5

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.

\documentclass{article}

% BEGIN_FOLD -----------PACKAGES------------
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{lipsum}
% END_FOLD -----------PACKAGES------------

\begin{document}
    \section{First section}
        \paragraph{}
            \lipsum[1]
    
    \section{Second section}
        \paragraph{}
            \lipsum[2]
\end{document}
2
  • 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

13

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.

% FORMAT AND PACKAGES
% {
\documentclass[a4paper,10pt,onecolumn]{article}
\usepackage[a4paper, left=30mm, right=20mm, top=30mm, bottom=20mm]{geometry}
\usepackage[utf8]{inputenc}
% }

% DOCUMENT
% {
\begin{document}
\title{RADA RADA RADA}
This text will be folded without cursing your file
% }

% SECTIONS
% {
\section*{BLABLABLA}
blablabla
% }

\end{document}

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

2
  • 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
1

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 .