I am using outline minor mode for LaTeX mode and would like emacs to automatically hide all section environments when opening a .tex file. How could I do that?

  • Does that mean you are using the built-in tex-mode.el library, or does that mean you are using the separate library that does not ship with Emacs called AUCTeX? – lawlist Nov 25 '17 at 22:17
  • I am using AUCTeX. – lo tolmencre Nov 25 '17 at 22:31

The specific function you are looking for is outline-hide-sublevels. Its docstring (C-h f outline-hide-sublevels) reads:

(outline-hide-sublevels LEVELS)

Hide everything but the top LEVELS levels of headers, in whole buffer. This also unhides the top heading-less body, if any.

Interactively, the prefix argument supplies the value of LEVELS. When invoked without a prefix argument, LEVELS defaults to the level of the current heading, or to 1 if the current line is not a heading.

Programmatically, (outline-hide-sublevels 1) will fold up everything to the top level (which is what you want). You can make a little function to do that:

(defun my-latex-hook ()
  (outline-hide-sublevels 1))

And add it to your LaTeX mode hook:

(add-hook 'LaTeX-mode-hook #'my-latex-hook)

See the manual node on outline visibility commands for more information.

  • thanks, but when I save the document everything unfolds again. That also happens when I manually fold blocks though. – lo tolmencre Nov 26 '17 at 3:06
  • @lotolmencre : please try it after starting up without your init file (emacs -Q). That doesn’t sound like standard behavior, so it’s likely something in your init file. – Dan Nov 26 '17 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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