I have been using org-mode for publishing scientific notes. Most of what I publish is compiled latex code and I am looking for a way to highlight latex syntax in the org-mode buffer. I came across many solutions for displaying published latex code with syntax highlighting using listed, minted, pygments, etc. Is there a way to display highlighted latex syntax in the org-buffer?
The variable org-highlight-latex-and-related
allows you to
highlight inline math. However, LaTeX fragments will only be highlighted with a single face.
From the documentation of org-highligh-latex-and-related
:
Non-nil means highlight LaTeX related syntax in the buffer.
When non nil, the value should be a list containing any of the
following symbols:
`latex' Highlight LaTeX snippets and environments.
`script' Highlight subscript and superscript.
`entities' Highlight entities.
E.g.:
(setq org-highlight-latex-and-related '(latex script entities))
The face org-latex-and-related
is used to fontify LaTeX fragments.
You can enclose your latex fragments in#+BEGIN_LaTeX latex
and #+END_LaTex latex
to have them highlighted. It is different from source blocs (#+BEGIN_SRC LaTeX
....) that are exported verbatim (with potential highlighting via pygments as you mentioned).
It works well for environments (equations,aligns...):
As far as I know it does not work for inline math (well it does if you enclose the whole paragraph but you loose the point of using org-mode...)
Source: this answer in emacs.stackexchange and Reddit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With