# [TxMt] Re: Code folding in LaTeX

René Schwaiger sanssecours at f-m.fm
Wed May 6 19:37:47 UTC 2015

Hi Ross,

> On 04 May 2015, at 15:57 , Ross Ahmed <rossahmed at googlemail.com> wrote:
>
> Code folding in LaTeX is not doing what I expect. Lets say I have this in my .tex file:
>
> \begin{document}
> \section{}
> Lorem ipsum dolor sit amet, consectetur adipisicing elit.
> \subsection{}
> Lorem ipsum dolor sit amet, consectetur adipisicing elit.
> \end{document}
>
> Option + Command + 0 does as expected:
>
> \begin{document}…\end{document}
>
> Option + Command + 1 does exactly the same:
>
> \begin{document}…\end{document}
>
> But what I expected was
>
> \begin{document}
> \section{}…
> \end{document}
>
> Option + Command + 2 does as expected:
>
> \begin{document}
> \section{}…
> \subsection{}…
> \end{document}
>
> So, I expected:
> \begin{document} to be all levels
> \section{} to be level 1
> \subsection{} to be level 2
>
> Is there a way of setting cold folding to do what I expected?

I don't know if it is currently possible to assign a level to a certain marker — e.g. \section{} — without a corresponding end marker. I would guess it is not. Markdown sections for example show the same behaviour — ⌥⌘1 collapses all of them, regardless of their level.

You can work around this issue by using sectioning environments — instead of sectioning commands. For your document that would mean that you would write something like:

\documentclass{article}

\begin{document}

\begin{section}{Section}
Lorem ipsum dolor sit amet, consectetur adipisicing elit.

\begin{subsection}{Subsection}
Lorem ipsum dolor sit amet, consectetur adipisicing elit.

\end{subsection}
\end{section}
\end{document}

Folding in this document should work as you expect.

> Ross Ahmed
> Ecologist
> —
> 07875533906