1

I am using \begin{comment} hello world \end{comment} in order to comment out text in AucTex mode.

In general I am using different color for comments but when I use \begin{comment} [text] \end{comment}, the text in between them shows up as white (normal text color). I want it to be seen as in original comment color.

enter image description here

(setq LaTeX-item-indent 0)
(add-hook 'LaTeX-mode-hook 'turn-on-auto-fill)
(require 'tex)

(add-hook 'LaTeX-mode-hook (lambda ()
  (TeX-global-PDF-mode t)
  ))

General question: Is it possible to have different color in between a specific pattern?

Narrowed question: How can I have different color in auxtex for text for all kind of comments such as in between \begin{comment} and \end{comment}

2

This should be automatic if you have \usepackage{comment} or \usepackage{verbatim} in your preamble. At the time the question was asked, it was actually automatic only with \usepackage{comment}, but AUCTeX 12.3 onwards will do it for \usepackage{verbatim} as well.

If you've just added the \usepackage command, run TeX-normal-mode (C-c C-n) to tell AUCTeX to parse the preamble again.

More generally, if you define your own environments using a LaTeX package that AUCTeX doesn't know about, you can ask AUCTeX to parse the .sty file. See automatic customization. As a last resort, if your LaTeX code is too complex for AUCTeX to parse, write your own style support. You can look at style/comment.el in the AUCTeX distribution to see how the {comment} environment from the comment.sty package is declared: it adds an entries to font-latex-syntactic-keywords-extra, which is used to override syntax information to declare \begin{comment} as having comment-start syntax and \end{comment} as having comment-end syntax.

| improve this answer | |
  • I was using it through verbatim : tex.stackexchange.com/a/17822/127048 . C-c C-n says Applying style hooks...done and does nothing – alper May 8 at 13:13
  • Coloring does not also work for \iffalse ... \fi – alper May 8 at 13:18
  • Ah if there is no space or tav before\begin{comment} it works but if there is space or tab it does not – alper May 8 at 13:40
  • 3
    @alper Indeed AUCTeX's support code for the verbatim package doesn't color comment environments, only the support code for the comment package. This would be worth a feature request to AUCTeX. \iffalse…\fi is not a comment, it's a conditional construct, so there's no reason why it would be colored as a comment. Recognizing \begin{comment} and \end{comment} only at the start of a line is also a design choice in AUCTeX because \end{comment} from comment.sty has to be at the start of a line, unlike \end{comment} from verbatim.sty which is implemented slightly differently. – Gilles 'SO- stop being evil' May 8 at 15:27
  • @Gilles'SO-stopbeingevil' - Fixed with this change. – Arash Esbati May 22 at 19:27

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.