Fix fontification of LaTeX elements (take two)

* lisp/org.el (org-do-latex-and-related): Fix last commit.
This commit is contained in:
Nicolas Goaziou 2018-12-16 11:08:00 +01:00
parent dc74770706
commit af3e2b1856
1 changed files with 28 additions and 32 deletions

View File

@ -6260,38 +6260,34 @@ done, nil otherwise."
(when (org-string-nw-p org-latex-and-related-regexp) (when (org-string-nw-p org-latex-and-related-regexp)
(catch 'found (catch 'found
(while (re-search-forward org-latex-and-related-regexp limit t) (while (re-search-forward org-latex-and-related-regexp limit t)
(unless (cl-some (unless (cl-some (lambda (f) (memq f '(org-code org-verbatim underline
(lambda (f) (memq f '(org-code org-verbatim underline org-special-keyword)))
org-special-keyword))) (save-excursion
(save-excursion (goto-char (1+ (match-beginning 0)))
(goto-char (1+ (match-beginning 0))) (face-at-point nil t)))
(face-at-point nil t))) (let ((start (if (memq (char-after (1+ (match-beginning 0)))
(let* ((start (if (memq (char-after (1+ (match-beginning 0))) '(?_ ?^))
'(?_ ?^)) (1+ (match-beginning 0))
(1+ (match-beginning 0)) (match-beginning 0)))
(match-beginning 0))) (end
(end (let* ((b (match-beginning 0))
(let* ((b (match-beginning 0)) (e (match-end 0))
(e (match-end 0)) (m (buffer-substring-no-properties b e)))
(m (buffer-substring-no-properties b e))) (cond
(cond ((string-match "\\`[ \t]*\\\\begin{\\([a-zA-Z0-9\\*]+\\)}" m)
((string-match "\\`[ \t]*\\\\begin{\\([a-zA-Z0-9\\*]+\\)}" (let ((re (format "\\\\end{%s}[ \t]*$"
m) (regexp-quote (match-string 1 m)))))
(let ((closing (or (re-search-forward re nil t) e)))
(format "\\\\end{%s}[ \t]*$" ((string-match "\\\\end{\\([a-zA-Z0-9\\*]+\\)}[ \t]*\\'" m)
(regexp-quote (match-string 1 m))))) (let ((re (format "^[ \t]*\\\\begin{%s}"
(or (re-search-forward closing nil t) e))) (regexp-quote (match-string 1 m)))))
((string-match "\\\\end{\\([a-zA-Z0-9\\*]+\\)}[ \t]*\\'" m) (setq start
(let ((opening (or (save-excursion (re-search-backward re nil t))
(format "^[ \t]*\\\\begin{%s}" b))
(regexp-quote (match-string 1 m))))) (line-end-position)))
(setq start (or (save-excursion ((string-match "\\`\\\\[a-zA-Z]+\\*?{\\'" m)
(re-search-backward opening nil t)) (search-forward "}" nil t))
b)) (t e)))))
(line-end-position)))
((string-match "\\\\[a-zA-Z]+\\*?{" m)
(search-forward "}" nil t))
(t e)))))
(font-lock-prepend-text-property (font-lock-prepend-text-property
start end 'face 'org-latex-and-related) start end 'face 'org-latex-and-related)
(add-text-properties start end '(font-lock-multiline t))) (add-text-properties start end '(font-lock-multiline t)))