From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Rasmus <rasmus@gmx.us>
Cc: emacs-orgmode@gnu.org
Subject: Re: Highlighting LaTeX fragments
Date: Sun, 10 Feb 2013 00:15:39 +0100 [thread overview]
Message-ID: <87a9rdgjtw.fsf@gmail.com> (raw)
In-Reply-To: <87liaxtjf3.fsf@pank.eu> (rasmus@gmx.us's message of "Sat, 09 Feb 2013 19:46:08 +0100")
[-- Attachment #1: Type: text/plain, Size: 798 bytes --]
Rasmus <rasmus@gmx.us> writes:
> Nicolas Goaziou <n.goaziou@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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fontify-latex-entities-and-sub-superscript-again.patch --]
[-- Type: text/x-patch, Size: 4505 bytes --]
From f0f165ef1b3a3e3d161da509cf0548171a6f68fb Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@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 position in the font-lock sequence.")
"\\(.*:" org-archive-tag ":.*\\)")
'(1 'org-archived prepend))
;; Specials
+ '(org-do-latex-and-special)
'(org-fontify-entities)
'(org-raise-scripts)
;; Code
--
1.8.1.3
next prev parent reply other threads:[~2013-02-09 23:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-09 16:47 Highlighting LaTeX fragments Rasmus
2013-02-09 18:05 ` Nicolas Goaziou
2013-02-09 18:46 ` Rasmus
2013-02-09 23:15 ` Nicolas Goaziou [this message]
2013-02-16 15:37 ` Rasmus
2013-02-16 21:22 ` Nicolas Goaziou
2013-02-16 22:02 ` Rasmus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a9rdgjtw.fsf@gmail.com \
--to=n.goaziou@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=rasmus@gmx.us \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).