9

I want to fold the whole part before \begin{document} where it is just formatting the LaTeX document. Is there a way to do this in LaTeX, in general, or at least in TeXstudio? Could I use some \begin{} structure to do it?

  • 1
    Although code folding is possible in TeXStudio http://tex.stackexchange.com/a/5281/15717, I don't think it's wise to do it. May be add the preamble (packages and custom macros) as package before \begin{document} follow http://tex.stackexchange.com/questions/40760/best-practice-on-organising-your-preamble – texenthusiast Jan 28 '15 at 03:38
  • Cut all your preamble and save as preamble.tex, then type \input{preamble} before of \begin{document}. – Fran Jan 28 '15 at 07:06
  • In general, you code-fold by editing your LaTeX code with a text editor that supports code folding. My choice of editor is Vim. It also supports syntax highlighting for many languages including LaTeX. – James Jan 28 '15 at 12:41
  • Why not split your code in many files and then include them within a single main file? You can define the main file as Master document and when you compile any open file, the main file will be compiled. – Sigur Jan 28 '15 at 12:45

1 Answers1

11

Note, code folding is a feature of an editor not a language. So there cannot be in 'code folding in LaTeX in general'.

Coming back to your intention, TeXstudio does not directly support 'folding everything before \begin{document}'. In TXS folding is limited to environments and structure commands (\section, etc.). However, you can define arbitrary folding ranges using the comments

%BEGIN_FOLD

%END_FOLD

That said, you may still consider separating the preamble to another file and \input-ing it as others have proposed in the comments. Personally, I favor this over folding, particularly in large projects that constist of multiple files anyway. While TXS can persistently save foling information in a session, the folding state is gone if you switch to another editor or pass the code to someone else. And then you would have to fold all the stuff again.

Tim Hoffmann
  • 11,159