From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carlos Pita Subject: Re: Bug: Add option to fontify latex blocks [9.1.9 (release_9.1.9-65-g5e4542 @ /home/carlos/local/stow/emacs-26/share/emacs/26.1.50/lisp/org/)] Date: Wed, 28 Nov 2018 13:55:10 -0300 Message-ID: References: <87h8g2kv81.fsf@gmail.com> <87lg5ershk.fsf@nicolasgoaziou.fr> <87d0qpsc4g.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gS37V-0002h9-OG for emacs-orgmode@gnu.org; Wed, 28 Nov 2018 11:55:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gS37U-00053t-Qv for emacs-orgmode@gnu.org; Wed, 28 Nov 2018 11:55:25 -0500 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]:44227) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gS37U-000535-KZ for emacs-orgmode@gnu.org; Wed, 28 Nov 2018 11:55:24 -0500 Received: by mail-yb1-xb43.google.com with SMTP id p144-v6so10876514yba.11 for ; Wed, 28 Nov 2018 08:55:24 -0800 (PST) In-Reply-To: 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" To: emacs-orgmode@gnu.org > all fontification is lost for the entire environment and never reapplied The problem is with the limit argument passed by the font locking framework to org-do-latex-and-related . Once you natively fontified the environment this limit arg became non nil and it's in general not enough to match the entire latex environment. I assume this is because of the way native fontification annotates the code which makes the framework think it would be enough to look up to some limit. But this is not true anymore when you have this hybrid syntax that forces to refontify the entire fragment in a temporary buffer. So in order to get native fontification working for inline latex you need to: 1. Ignore the limit argument. 2. Replace the calls to font-lock-prepend-text-property and add-text-properties by a single call to org-src-font-lock-fontify-block 3. Also this makes most sense if org-highlight-latex-and-related is set to '(latex). Maybe an option could be added that did something like 1, 2 and 3 above, in case the user prefers native fontification for inline latex. In any case, here is an advice that will do the trick: (advice-add 'org-do-latex-and-related :around (lambda (f limit) (cl-letf (((symbol-function 'font-lock-prepend-text-property) (lambda (start end &rest args) (org-src-font-lock-fontify-block "latex" start end)))) (funcall f nil)))) Regards --- Carlos