From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Highlighting LaTeX fragments Date: Sun, 10 Feb 2013 00:15:39 +0100 Message-ID: <87a9rdgjtw.fsf@gmail.com> References: <87vca1towm.fsf@pank.eu> <8738x5s6r1.fsf@gmail.com> <87liaxtjf3.fsf@pank.eu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:47029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U4JeJ-0005uv-CX for emacs-orgmode@gnu.org; Sat, 09 Feb 2013 18:16:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U4JeH-0002ew-Gs for emacs-orgmode@gnu.org; Sat, 09 Feb 2013 18:15:58 -0500 Received: from mail-wg0-f48.google.com ([74.125.82.48]:52163) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U4JeH-0002eq-5n for emacs-orgmode@gnu.org; Sat, 09 Feb 2013 18:15:57 -0500 Received: by mail-wg0-f48.google.com with SMTP id 16so3844427wgi.27 for ; Sat, 09 Feb 2013 15:15:56 -0800 (PST) In-Reply-To: <87liaxtjf3.fsf@pank.eu> (rasmus@gmx.us's message of "Sat, 09 Feb 2013 19:46:08 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rasmus Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Rasmus writes: > Nicolas Goaziou 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 \(=C2=B7\) should be > used.=20 > > 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, --=20 Nicolas Goaziou --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fontify-latex-entities-and-sub-superscript-again.patch >From f0f165ef1b3a3e3d161da509cf0548171a6f68fb Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou 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 --=-=-=--