Rasmus ras...@gmx.us writes:
Nicolas Goaziou n.goaz...@gmail.com writes:
To begin with, it should be useful to know what is missing exactly.
Colors. E.g. it used to be that if an equation was too long to be
supported by $-signs it would go from brown (on my system) to the
normal black, giving visual feedback as to whether \(·\) should be
used.
Also, it made it quicker to distinguish inline math from text (also
display math but this can be replaced by babel blocks).
Would you mind testing the following patch? I don't like it much because
it's an all or nothing fontification. I think latex snippets, entities
and sub/superscript should be separated.
Anyway, does it replace the missing functionality?
Regards,
--
Nicolas Goaziou
From f0f165ef1b3a3e3d161da509cf0548171a6f68fb Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou n.goaz...@gmail.com
Date: Sun, 10 Feb 2013 00:07:48 +0100
Subject: [PATCH] Fontify latex, entities and sub/superscript again
* lisp/org-faces.el (org-latex-and-special): Renamed from
`org-latex-and-export-specials', which wasn't appropriate anymore.
* lisp/org.el (org-highlight-latex-and-special,
org-latex-and-special-regexp): New variables.
(org-compute-latex-and-special-regexp, org-do-latex-and-special): New
function, revived from a previous commit.
(org-set-regexps-and-options, org-set-font-lock-defaults): Use new
functions.
---
lisp/org-faces.el | 2 +-
lisp/org.el | 47 +++
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index de5a08c..a841ba3 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -765,7 +765,7 @@ level org-n-level-faces
:version 24.1
:type 'boolean)
-(defface org-latex-and-export-specials
+(defface org-latex-and-special
(let ((font (cond ((assq :inherit custom-face-attributes)
'(:inherit underline))
(t '(:underline t)
diff --git a/lisp/org.el b/lisp/org.el
index 2bfca4e..908fcb4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3889,6 +3889,11 @@ org-level-* faces.
:group 'org-appearance
:type 'boolean)
+(defcustom org-highlight-latex-and-special nil
+ Non-nil means fontify LaTeX stuff, entities and sub/superscript.
+ :group 'org-appearance
+ :type 'boolean)
+
(defcustom org-hide-emphasis-markers nil
Non-nil mean font-lock should hide the emphasis marker characters.
:group 'org-appearance
@@ -4987,6 +4992,7 @@ but the stars and the body are.)
(mapcar (lambda (w) (substring w 0 -1))
(list org-scheduled-string org-deadline-string
org-clock-string org-closed-string)))
+ (org-compute-latex-and-special-regexp)
(org-set-font-lock-defaults
(defun org-file-contents (file optional noerror)
@@ -5837,9 +5843,49 @@ by a #.
(goto-char e)
t)))
+(defvar org-latex-and-special-regexp nil
+ Regular expression for highlighting LaTeX, entities and sub/superscript.)
(defvar org-match-substring-regexp)
(defvar org-match-substring-with-braces-regexp)
+(defun org-compute-latex-and-special-regexp ()
+ Compute regular expression for LaTeX stuff, entities and sub/superscript.
+ (org-set-local
+ 'org-latex-and-special-regexp
+ (if (not org-highlight-latex-and-special) nil
+ (let* ((re-sub
+ (cond ((eq org-use-sub-superscripts '{})
+ (list org-match-substring-with-braces-regexp))
+ (org-use-sub-superscripts
+ (list org-match-substring-regexp
+ (matchers (plist-get org-format-latex-options :matchers))
+(re-latex (delq nil
+ (mapcar (lambda (x)
+ (and (member (car x) matchers) (nth 1 x)))
+org-latex-regexps)))
+(re-macros (list \\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\($\\|{}\\|[^[:alpha:]]\\
+ (mapconcat 'identity (append re-latex re-macros re-sub) \\|)
+
+(defun org-do-latex-and-special (limit)
+ Search down to LIMIT and fontify LaTeX snippets and entities.
+Fontification happens only if `org-latex-and-special-regexp' is
+non-nil.
+ (when org-latex-and-special-regexp
+(let (rtn d)
+ (while (and (not rtn)
+ (re-search-forward org-latex-and-special-regexp limit t))
+ (unless (memq (car-safe (get-text-property (1+ (match-beginning 0))
+ 'face))
+ '(org-code org-verbatim underline))
+ (setq
+ rtn t
+ d (if (memq (char-after (1+ (match-beginning 0))) '(?_ ?^)) 1 0))
+ (font-lock-prepend-text-property
+ (+ d (match-beginning 0)) (match-end 0) 'face 'org-latex-and-special)
+ (add-text-properties (+ d (match-beginning 0)) (match-end 0)
+ '(font-lock-multiline t
+ rtn)))
+
(defun org-restart-font-lock ()
Restart `font-lock-mode', to force refontification.
(when (and (boundp 'font-lock-mode) font-lock-mode)
@@ -6000,6 +6046,7 @@ needs to be inserted at a specific