8

Do you know a simple way to tell GNU Emacs to recognize LaTeX \iffalse ... \fi blocks and to display them in a special way, e.g., using a lighter font, or using font-lock-comment-face. Is there a LaTeX style package that already knows how to do this?

I understand that correctly recognizing valid \iffalse's and their matching \fi's in arbitrary LaTeX source file is a non-trivial problem, but I am happy with an approximate solution that works in most easy cases, e.g., that assumes no nesting of \if\fi's and requires these commands to appear alone on their source line.

dustin
  • 18,617
  • 23
  • 99
  • 204
phs
  • 203

1 Answers1

7

This solution does not require AUCTeX to the best of my knowledge.

Add the following to your .emacs:

(add-hook 'TeX-mode-hook
  (lambda ()
    (font-lock-add-keywords nil '(
      ("\\\\iffalse\\(\\(.\\|\n\\)*?\\)\\\\fi" 1 font-lock-comment-face)))))

result

Sean Allred
  • 27,421