7

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.

  • I've little idea how to do this, but I believe AUCTeX would could/would be useful here---is its use allowed, or should it stick to normal tex-mode? – Sean Allred Jul 30 '13 at 17:08
  • A solution with AUCTeX is fine with me. – phs Jul 31 '13 at 7:48
5

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

| improve this answer | |

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.