Function: org-do-latex-and-related
org-do-latex-and-related is a byte-compiled function defined in
org.el.gz.
Signature
(org-do-latex-and-related LIMIT)
Documentation
Highlight LaTeX snippets and environments, entities and sub/superscript.
Stop at first highlighted object, if any. Return t if some highlighting was done, nil otherwise.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-do-latex-and-related (limit)
"Highlight LaTeX snippets and environments, entities and sub/superscript.
Stop at first highlighted object, if any. Return t if some
highlighting was done, nil otherwise."
(when (org-string-nw-p org-latex-and-related-regexp)
(let ((latex-prefix-re (rx (or "$" "\\(" "\\[")))
(blank-line-re (rx (and "\n" (zero-or-more (or " " "\t")) "\n"))))
(catch 'found
(while (and (< (point) limit)
(re-search-forward org-latex-and-related-regexp nil t))
(cond
((>= (match-beginning 0) limit)
(throw 'found nil))
((cl-some (lambda (f)
(memq f '(org-code org-verbatim underline
org-special-keyword)))
(save-excursion
(goto-char (1+ (match-beginning 0)))
(face-at-point nil t))))
;; Try to limit false positives. In this case, ignore
;; $$...$$, \(...\), and \[...\] LaTeX constructs if they
;; contain an empty line.
((save-excursion
(goto-char (match-beginning 0))
(and (looking-at-p latex-prefix-re)
(save-match-data
(re-search-forward blank-line-re (1- (match-end 0)) t)))))
(t
(let* ((offset (if (memq (char-after (1+ (match-beginning 0)))
'(?_ ?^))
1
0))
(start (+ offset (match-beginning 0)))
(end (match-end 0)))
(if (memq 'native org-highlight-latex-and-related)
(org-src-font-lock-fontify-block "latex" start end)
(font-lock-prepend-text-property start end
'face 'org-latex-and-related))
(add-text-properties (+ offset (match-beginning 0)) (match-end 0)
'(font-lock-multiline t))
(throw 'found t)))))
nil))))