11

By "folding", I mean condense some part of the codes, and by one click , you can unfold them.

percusse
  • 157,807
  • This sort of thing is just outside the remit of what can be done with PDFs or similar formats. I doubt LaTeX or friends can help you. – Seamus Nov 07 '10 at 00:56
  • 5
    I don't think the question is about folding in the resulting pdf. I believe it is about folding in the editor. LyX does have some folding, you can for example fold notes, ERT, tables and other inserts. However, general folding is not, AFAIK, implemented at the moment. It is on the wishlist (http://wiki.lyx.org/LyX/FeaturePoll2), though. – Jan Hlavacek Nov 07 '10 at 02:11
  • This is usually called a 'flexible outliner', and is something that a lot of TeX-friendly editors have on their wish-lists. I guess it's hard to do :-) – Joseph Wright Nov 07 '10 at 07:52
  • 1
    @JanHlavacek — you should write this as an actual answer :) – Will Robertson Nov 07 '10 at 11:09
  • ORG mode in emacs effectively does this. So I'm sure you could modify the code there to work in LaTeX mode... But that's not very helpful if the question was about LyX – Seamus Nov 07 '10 at 12:09
  • Please register on this site otherwise you won't be able to comment on or accept answers or edit your question. – Werner Nov 17 '11 at 18:35

3 Answers3

11

While LyX has not yet "traditional" functionality for general editor folding, it can relatively easy be simulated by using LyX branches. As branches are insets, they can be folded within LyX. (By activating/deactivating them, you could even fold them in the output, but that is another story.)

enter image description here

To fold some content, just select it and then choose Insert->Branch from the menu. If you do this the first time, you have to create the respective branch (e.g., "Folded"); afterwards, you can just put more content into the "Folded" branch. For quick access, it is possible and recommended to bind this function to a keyboard shortcut.

Note that a new branch is deactivated by default, which means that its content will not appear in the output. You can change this by right-clicking on the inset.

Daniel
  • 37,517
  • Very handy! Could you specify which function to bind to a keyboard shortcut? Is it possible to create a function that inserts a specific branch? I'd love to be able to mark text, press shortcut and then have it in the designated branch (as it is possible with other insets, like footnote, comment, etc.) – Rasmus Jun 22 '16 at 14:00
  • 2
    @Rasmus: At times it is a bit tricky to figure out what LyX commands one actually has to bind to a shortcut to achieve the desired behavior. However, you can investigate it! See http://tex.stackexchange.com/questions/22938/shortcut-for-vertical-space-in-lyx/22956#22956 for a general approach. – Daniel Jun 22 '16 at 22:30
  • The suggestion worked admirably. The function is 'branch-insert Name-of-Branch' . – Rasmus Jun 23 '16 at 08:46
  • 1
    This thread is very old. I wonder if there has been any updates on this? Native support for folding would be very nice. – a06e Sep 03 '18 at 13:47
  • @becko: Good point, but unfortunately the release notes of LyX 2.3.x do not show anything new related to folding: https://wiki.lyx.org/LyX/NewInLyX23 – Daniel Sep 03 '18 at 18:28
7

OK, since this have remained unanswered for a while, I will retype my comment here. LyX does have some folding, you can for example fold notes, ERT, tables and other inserts. However, general folding is not implemented at the moment. It is on the wishlist.

Jan Hlavacek
  • 19,242
4

As an alternative to (ab)using branches, one can easily define a custom inset by adding the following to Document > Settings > Local Layout:

InsetLayout Flex:Foldable          # Define a new "flex" inset called "Foldable"
  LyxType         custom           # Add to Insert > Custom Insets
  LatexType       none             # Export contents to latex as-is, ignoring the wrapper.
  Decoration      minimalistic     # Do not show a label, only the outer box, when not folded.
  ContentAsLabel  true             # When folded show truncated contents as label.
End

Usage

The inset can be inserted from the menu entry Insert > Custom Insets > Foldable of by typing M-x flex-insert Foldable.

For multi-file documents, the Local Layout has to be manually replicated across all files.

kdb
  • 1,889