5

This question already has an answer here:

I'd like to easily hide or show the text below individual headings in a large Latex document.

I thought this should be possible with outline-minor-mode, however I can not get it to work. I can activate the mode, but I don't see how to hide or show something.

The AUCTeX documentation says that AUCTeX can work together with outline-minor-mode.

I also looked at the documentation on Outline Mode, but

  • motion commands do not have any effect (and seem to conflict with AUCTeX keybindings)
  • same for folding commands

When using AUCTeX folding commands like C-c C-o C-b for folding the whole buffer, only some labels and small things are hidden, but not enough.

I'm familiar with using org-mode, so it would be nice if I could use key bindings similar to org-mode's for expanding/collapsing sections or navigating between headings.

marked as duplicate by Malabarba, Dan, paprika, Luke, Francesco Nov 4 '14 at 16:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    It's pretty close, although this question does implicitly ask about the AUCTeX folding facilities, which are different from the outline options. If this Q gets closed, I'll move the answer with the non-overlapping parts to the other thread. – Dan Nov 4 '14 at 12:41
  • @Dan: Please do! And don't worry about overlapping, it's a very good answer, just copy the whole thing. If you expand a bit on the part about outline-minor-mode-prefix I'll even accept it. – Malabarba Nov 4 '14 at 18:24
  • @Malabara: done! Turns out that setting outline-minor-mode-prefix is surprisingly convoluted. – Dan Nov 4 '14 at 21:04
6

Outline mode and the AUCTeX folding facilities are two different beasts that are meant to do broadly the same thing: hide and show selected parts of the buffer. Personally, I find the AUCTeX facilities to be rather jarring and rarely use them, but your mileage may vary. I use the outlining functionality all the time, however.

outline-minor-mode

A key element to recognize when using outline-minor-mode is that it's got a different prefix key that outline-mode (ie, the major mode) -- precisely to avoid the key conflicts with motion keys, etc. That prefix defaults to the awkward-to-type C-c @ (although you can change that by customizing outline-minor-mode-prefix). All the keybindings listed on this node of the manual should still work, but with the twist that you replace the major mode prefix of C-c with the minor mode prefix of C-c @. Hence, C-c @ C-c runs hide-entry, C-c @ C-e runs show-entry, and so on.

To use these facilities, you need to enable outline-minor-mode. The simplest way is with a mode hook:

(add-hook 'LaTeX-mode-hook 'outline-minor-mode)

adding new outline headings

As an added bonus, you can also customize which outline headers can get folded, and to what levels. I, for example, like to be able to make "fake" section headers to hide away text that doesn't have a true LaTeX header, but logically is kept at the same level of the document. With the following code, you can use:

%section{a fake section}

Blah blah blah blah blah, LaTeX doesn't recognize me as a section...

\section{a real section}

Blah blah blah blah blah, LaTeX treats me as a real section

And you will be able to manipulate the fake section just like any other one, but LaTeX will ignore it when you compile the document:

;; extra outline headers 
(setq TeX-outline-extra
      '(("%chapter" 1)
        ("%section" 2)
        ("%subsection" 3)
        ("%subsubsection" 4)
        ("%paragraph" 5)))

;; add font locking to the headers
(font-lock-add-keywords
 'latex-mode
 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
    0 'font-lock-keyword-face t)
   ("^%chapter{\\(.*\\)}"       1 'font-latex-sectioning-1-face t)
   ("^%section{\\(.*\\)}"       1 'font-latex-sectioning-2-face t)
   ("^%subsection{\\(.*\\)}"    1 'font-latex-sectioning-3-face t)
   ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
   ("^%paragraph{\\(.*\\)}"     1 'font-latex-sectioning-5-face t)))

outline-magic

outline-magic extends the outline modes to use org-mode-like hiding/showing with the magic tab key. In other words, you can probably add this in to your workflow and make your LaTeX documents behave more like org documents. (I don't use it myself, so can't comment on functionality.)

AUCTeX folding facilities

These were the facilities you were mentioning when you cited the bindings like C-c C-o C-b. Note that you need to enable them with TeX-fold-mode.

These facilities work differently from outline mode, and hide environments (eg, \begin{itemize} ... \end{itemize} and what AUCTeX refers to as "macros", such as \footnote{...} rather than sections per se.

You can use both outline-minor-mode and AUCTeX's folding facilities together in the same document: they do different things on different parts of it.

  • thanks a lot for this detailed explanation! for some reason, the keybindings with my prefix do have no effect and I can not use C-@ for some other strange reason... but with the outline menu, I can now at least see that the commands do work. No I have to make the key bindings work. ... – MostlyHarmless Nov 4 '14 at 15:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.