6

Using TeXstudio's GUI, I would like to collapse the calls of \usepackage{} similar to what can be done for a \paragraph{}, a \section{} etc. The fact that some code can be collapsed in the GUI is identified with a little arrow pointing downward (if expanded) or to the right (if collapsed) next to the first line of code that can be collapsed (see below).

code that can be collapsed

I've tried using

\documentclass[a4paper,12pt]{article}
{ % this allows collapsing in the GUI (1/2)
    \usepackage{color}
} % this allows collapsing in the GUI (2/2)
\begin{document}
    text
\end{document}

which allows me to collapse the \usepackage{} calls but doesn't compile.

In short: I want code that compiles and allows me to collapse the code like show in the picture below (as identified by the gray arrow in line 4). So far, I can either get the code to compile (not using the { } around the \usepackage) or I am able to collapse the calls in the GUI.

working example (does not compile)

Does anyone have a solution or idea?

2
  • Don't do that. Put the \usepackages in a separate file (say, mypackages.sty) and then load them with \usepackage{mypackages}. Commented Oct 14, 2019 at 12:44
  • This is a great solution to the same issue, thank you!!! Is there any particular reason you'd suggest putting the \usepackage calls into a different file?
    – Ivo
    Commented Oct 14, 2019 at 13:15

1 Answer 1

9

Put

%BEGIN_FOLD

%END_FOLD

around them. This will allow your code to compile because for tex these are comments, however texstudio understands these comments and allows code folding

enter image description hereenter image description here

1
  • exactly what I was looking for! Thank you!!!
    – Ivo
    Commented Oct 14, 2019 at 13:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .