## #363 Fold preamble (as in TexMaker)

None
open
nobody
1
2013-04-22
2012-11-20
Anonymous
No

I'd like restore the feature "fold preamble" like in Texmaker.
i don't know why quit this feature.
It's good to fold since \documentclass{} to \begin{document}

Thanks

## Discussion

• Tim Hoffmann
2012-11-24

Ok, we leave this open because the request is reasonable. However it is currently not possible to implement this because of the program logic: Folding is associated with "brackets" and you cannot specify "beginning of file" to "\begin{document}" as bracket in the language specification.

Last edit: Tim Hoffmann 2012-11-24

• Anonymous
2012-11-25

I wonder about the benefit of such a functionality. If you have a really long preamble, the first thing that comes to mind is to outsource the preamble to a seperate file and include this with the 'input' command.

• Anonymous
2012-11-25

Sometimes in a short document a "well-specified" preamble (maybe with some explanatory comments) can occupy several lines and that bothers, not worth it separated into a new file. (if this is not posible, how is done in Texmaker?)

• Tim Hoffmann
2012-11-25

Of course, everything is possible, given you had endless ressouces. It's just that TXS and Texmaker use different mechanisms to detect folding, and in our case folding the preamble is not easy to implement. The reasons are given below:

Afaik Texmaker hard-codes these things, e.g. something like

if (line.contains("\\begin{")) {
fold to matching \\end
}


In contrast, TXS (actually the underlying editor QCodeEdit) uses a formal language definition (see .qnfa files in the sources) and an engine that parses this definition and handles the details. Code folding is part of these language definitions. This approach is much more powerful and is the basis that allows us to have the detailed highlighting and folding (and support for other languages, Like BibTeX, QtScript, dtx files, Lua etc.) with reasonable effort.

Now, in the Texmaker way, it is easy to hack an additional line

lf (startOfDocument()) {
fold to line before \\begin{document}
}


This doesn't work in our approach. The language format of QCodeEdit neiter supports startOfDocument, nor "line before something". So you'd have to adapt the language definition format and the parser/engine. The latter is a non-trivial piece of code which makes sure, that also complicated situations are highlighted and folded correctly (that's not always the case in Texmaker). And I'm not going to touch this for the time being.

As a workaround, I cound offer you a special comment that can be folded:
% PREAMBLE

% END_PREAMBLE

Actually, implementing this would be trivially due to the language system.

Last edit: Tim Hoffmann 2012-11-25
• Priority: 1 --> 5*

• Anonymous
2012-12-02

I think the
% PREAMBLE

% END_PREAMBLE
idea you mention would be very helpful!
Thanks,
DW

• Tim Hoffmann
2012-12-02

Maybe we should generalize it to
% START_EXTRA_FOLD
% END_EXTRA_FOLD

Last edit: Tim Hoffmann 2012-12-04

• Tim Hoffmann
2012-12-04

Implemented (rev. 3532)

% BEGIN_FOLD

% END_FOLD


which lets the user specify an arbitrary region as foldable

• Tim Hoffmann
2012-12-04

• milestone: -->
• priority: 5* --> 1

• Tim Hoffmann
2012-12-04

with the above workaround, one can make the preamble region foldable. Nevertheless, directly supporting a folding of the preamble would be desirable.

Reinvestigate, when QCE3 is used.

• Anonymous
2012-12-06

Ok, I like this idea ... because it allows you to fold any region more generally.

• Anonymous
2012-12-11

A fold command would be very appreciated. TeXnicCenter has the following command to delimit a foldable region:

%\begin