emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Inline LaTeX formulae


From: Titus von der Malsburg
Subject: Re: [O] Inline LaTeX formulae
Date: Thu, 07 May 2015 11:00:08 -0700

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 
>   ;; from Nicolas Richard <address@hidden>
>   ;; Date: Fri, 8 Mar 2013 16:23:02 +0100
>   ;; Message-ID: <address@hidden>
>   (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’ proposal is simple and correctly implements what is specified 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
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -2963,7 +2963,7 @@ Assume point is at the beginning of the LaTeX fragment."
                         (search-forward "$" nil t 2)
                         (not (memq (char-before (match-beginning 0))
                                    '(?\s ?\t ?\n ?, ?.)))
-                        (looking-at "\\([- \t.,?;:'\"]\\|$\\)")
+                        (looking-at "\\(\\s.\\|\\s-\\|\\s)\\|\\s\"\\|\\s_\\)")
                         (point)))
                (case (char-after (1+ (point)))
                  (?\( (search-forward "\\)" nil t))


Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]