Having previously used TeXstudio, I used the % BEGIN_FOLD command to fold sections of code manually in the code representation, e.g. for loading packages etc. (see below). Now switching to Overleaf, I couldn't figure out how to do this - is there a way to achieve this? (I know it is possible for \begin{section} etc. but I would like to achieve the same result for manually defined chunks (the % BEGIN_FOLD and % END_FOLD section in below code). Many thanks in advance.


% BEGIN_FOLD -----------PACKAGES------------
% END_FOLD -----------PACKAGES------------

    \section{First section}
    \section{Second section}
  • 2
    Have you contacted the Overleaf Helpdesk? I hear the Fu of their LaTeX specialists is strong.
    – Mico
    Commented Jun 11, 2020 at 10:05
  • Hi Ivo! Tom from Overleaf Support here. We don't have the ability to specify manual code-folding places. I have raised this to our Product team for consideration. Thanks for writing in! If you want it for the preamble, you can move everything in the preamble into a separate file (e.g. preamble.tex) and then just do \input{preamble}. Just please always keep \documentclass and \begin{document} in the main file (do not move these two into the preamble) or the Overleaf compiler would get confused.
    – yo'
    Commented Jun 11, 2020 at 15:53

2 Answers 2


You can fold on overleaf using % { and % }. I like it because you can organize a big text and it won't affect your file at all.

% {
\usepackage[a4paper, left=30mm, right=20mm, top=30mm, bottom=20mm]{geometry}
% }

% {
This text will be folded without cursing your file
% }

% {
% }


You can see how it works on the pictures below :D

  • 1
    Click in the margin at the right of the line numbers to fold lines Commented Dec 19, 2022 at 17:12
  • It also works with most structures \begin{envt} ... \end{envt} : you have a dot to click on to fold. What a nice improvement ! Commented Dec 19, 2022 at 17:59

Not a solution but, as a workaround, I am for now using the way described here, using a separate file starting with \ProvidesPackage{costumname} which is saved as costumname.sty and used in the main document with \usepackage{costumname}.

You must log in to answer this question.

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