From mboxrd@z Thu Jan 1 00:00:00 1970 From: Titus von der Malsburg Subject: Re: Inline LaTeX formulae Date: Thu, 07 May 2015 11:00:08 -0700 Message-ID: <87vbg4gtef.fsf@posteo.de> References: <876186zsrc.fsf@posteo.de> <874mnqzp4t.fsf@posteo.de> <87wq0mc8bc.fsf@gmx.us> <87vbg5xx4z.fsf@posteo.de> <87bnhwq1ez.fsf@delle7240.chemeng.ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqQ5t-0008Di-Gw for emacs-orgmode@gnu.org; Thu, 07 May 2015 14:00:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqQ5l-0006iv-D9 for emacs-orgmode@gnu.org; Thu, 07 May 2015 14:00:21 -0400 Received: from mx02.posteo.de ([89.146.194.165]:55916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqQ5l-0006in-5J for emacs-orgmode@gnu.org; Thu, 07 May 2015 14:00:13 -0400 In-reply-to: <87bnhwq1ez.fsf@delle7240.chemeng.ucl.ac.uk> 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: Eric S Fraga Cc: emacs-orgmode@gnu.org, Rasmus --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2015-05-07 Thu 00:42, Eric S Fraga wrote: > On Wednesday, 6 May 2015 at 13:35, Titus von der Malsburg wrote: > > [...] > >> So if the problem is only due to mistaken optimization, it would perhaps >> be best to just revert to the previous code. > > Or if the "optimisation" was key to getting acceptable performance, > maybe discourage the use of $...$ and emphasise the use of \(...\). The > latter is less fragile and is easy to generate by typing $ using the > following function and binding: > > #+begin_src emacs-lisp=20 > ;; from Nicolas Richard > ;; Date: Fri, 8 Mar 2013 16:23:02 +0100 > ;; Message-ID: <87vc913oh5.fsf@yahoo.fr> > (defun yf/org-electric-dollar nil > "When called once, insert \\(\\) and leave point in between. > When called twice, replace the previously inserted \\(\\) by one $." > (interactive) > (if (and (looking-at "\\\\)") (looking-back "\\\\(")) > (progn (delete-char 2) > (delete-char -2) > (insert "$")) > (insert "\\(\\)") > (backward-char 2))) > (define-key org-mode-map (kbd "$") 'yf/org-electric-dollar) > #+end_src > > The problem with $ in org mode is that it is a valid standalone > character (i.e. currency symbol). Having it perform two functions > (symbol and LaTeX directive) makes it difficult to optimise > performance. The double use of the $ character makes things somewhat tricky, true. However, the org manual makes it perfectly clear how the $ sign should be interpreted and earlier versions of org implemented that specification. Hence, there is no need to reeducate users about how they should write inline formulas. This is simply a bug and it should be fixed. Rasmus=E2=80=99 proposal is simple and correctly implements what is specifi= ed in the manual. Below is a patch that implements this solution. Does anyone see a concrete problem? If not, it should be merged. Titus org-element: Ensure correct detection of latex fragments * org-element.el (org-element-latex-fragment-parser): Ensure correct detection of latex fragments in `org-element-latex-fragment-parser'. Uses syntax tables to detect whitespaces and punctuation marks following the final $ sign. In order to qualify as a math delimiter, the final $ sign of a LaTeX fragment has to be followed by a whitespace or punctuation mark but the regexp used in the previous code matched only a small number of punctuation marks and therefore missed some latex fragments. diff --git a/lisp/org-element.el b/lisp/org-element.el index 7aab9f6..d0c0485 100644 =2D-- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -2963,7 +2963,7 @@ Assume point is at the beginning of the LaTeX fragmen= t." (search-forward "$" nil t 2) (not (memq (char-before (match-beginning 0)) '(?\s ?\t ?\n ?, ?.))) =2D (looking-at "\\([- \t.,?;:'\"]\\|$\\)") + (looking-at "\\(\\s.\\|\\s-\\|\\s)\\|\\s\"\\|\\s_\= \)") (point))) (case (char-after (1+ (point))) (?\( (search-forward "\\)" nil t)) --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVS6gpAAoJEK40WfPGE2idGLwH/1B+orcv2fFNXLuSJuu4lV29 IvaK6eru28p23ACnWmH/rk8oARdeulPQr8NY5QcVQFsEfnFouTZUD9svlgJUGr6D 2sniqEfCCvGQ8Wez9vp5ga35X7e9ObELJJmeIqDRykPgICKOoRfZCBXoyNSB1iMQ gb9Zi3hjbZufFL2UptQ4jC8RrQQ+0k5bGFaUlNbBDwNMRP17uyzTBghTWdBzTYCs qDpTI2UtliedJno2kYQzWsS8gmwRvc49UcZhbau12s7Xup+KIg/aGRtsThZyi/wv f3LEUhtzRvY78SnbzY3/SEoDmWuPZJ7aZ48XHfkzwIfPzJrC7xYfbpeyiULv3Eo= =+2wg -----END PGP SIGNATURE----- --=-=-=--