Posted on 11 January 2013
TeX-fold-mode
is a minor mode which is part of
AUCTEX, and automatically hides
a lot of the latex formatting commands. For example, \alpha
is
rendered using an alpha character, and references are shortened to
[r]
. Here’s an example:
This gives a much cleaner feel when writing. Adding
to your .emacs
will load the mode automatically and fold the whole
buffer when you load a latex file. However, when typing, any new stuff
won’t appear “folded”. To “re-fold” a paragraph, the command
TeX-fold-paragraph must be used (shortcut C-c C-o C-p
), which is a
bit tedious.
Instead, it would be great if things would fold automatically. Calling
TeX-fold-paragraph
after every character insert event would slow
emacs down to a crawl, so the approach that I use is to automatically
call it when either $
or }
are entered (typically ending an
expression which should be folded). The code required for this adds a
local hook which detects this change (the local part is important as
we don’t want this hook applying to other buffers) is
This does not slow emacs down noticeably on my machine while keeping
folding up to date. Typing a row of $
or }
characters becomes very
laggy but I don’t have to do that very often!