In Emacs, how do you change Latex mode to treat &l

2019-07-24 23:58发布

问题:

In Emacs, is there some short code that you can write (in .emacs, latex.el, or some other file) so that Latex mode treats code of form <% ... %> as a comment?

回答1:

See this tutorial on writing syntax highlighting support for new modes (wayback machine link to material orriginally found at http://two-wugs.net/emacs/mode-tutorial.html and attibuted to Scott Andrew Borton), then dig into what the latex mode you are using (tex-mode? auctex? something else?) is doing and fix it.

Which only leaves the question: Why?!?



回答2:

You need to use the font-lock-add-keyword function; give it a major mode to add keywords too, and a association list of regex / face:

(font-lock-add-keywords 'latex-mode
   '(("\<\%.*\%\>" . font-lock-comment-face)))

More details here on emacswiki: http://www.emacswiki.org/emacs/AddKeywords

Note this answer was copied over from the previous version of this question



回答3:

Something like the following might work:

(modify-syntax-entry ?< "_ 1n" latex-mode-syntax-table)
(modify-syntax-entry ?% "< 23" latex-mode-syntax-table)
(modify-syntax-entry ?> "_ 4n" latex-mode-syntax-table)


标签: latex elisp