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.
org-highlight-latex-and-related
? Also, could there be things in conflict? –
Nicholson .org
file with emacs -q
and then evaluating (setq org-highlight-latex-and-related '(latex script entities))
. –
Nicholson 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.
Put the following in your .emacs config file:
;; fontify code in code blocks
(setq org-src-fontify-natively t)
PS- I don't understand it's not enabled by default.
You may want to try something like this.
(font-lock-add-keywords 'org-mode
'(("\\(\\\\cite\\)" . font-lock-keyword-face)
("\\[[0-9]+]" . font-lock-type-face)
("\\s-*[a-zA-Z]+[0-9]+[a-z]" . font-lock-constant-face)))
(font-lock-add-keywords 'org-mode
'(("\\(\\\\citep\\)" . font-lock-keyword-face)))
(font-lock-add-keywords 'org-mode
'(("\\(\\\\citet\\)" . font-lock-keyword-face)))
(font-lock-add-keywords 'org-mode
'(("\\(\\\\citealp\\)" . font-lock-keyword-face)))
(font-lock-add-keywords 'org-mode
'(("\\(\\\\citeauthor\\)" . font-lock-keyword-face)))
(font-lock-add-keywords 'org-mode
'(("\\(\\\\citeyear\\)" . font-lock-keyword-face)))
http://www.emacswiki.org/emacs/AddKeywords http://www.emacswiki.org/emacs/RegularExpression
© 2022 - 2024 — McMap. All rights reserved.
org-mode
buffer, to highlight all the embedded latex code (for instance\alpha
,S^3
,\dots
). – FrayneC-c '
not enough while editing a LaTeX block? Do you want to see it highlighted at all times? – Candide