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

{ % this allows collapsing in the GUI (1/2)
} % this allows collapsing in the GUI (2/2)

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?

  • Don't do that. Put the \usepackages in a separate file (say, mypackages.sty) and then load them with \usepackage{mypackages}. 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
    Oct 14, 2019 at 13:15

1 Answer 1





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

  • exactly what I was looking for! Thank you!!!
    – Ivo
    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 .