On 2015-05-08 Fri 14:40, Nicolas Goaziou wrote: > Titus von der Malsburg writes: > >> Both are fixed in the patch below. > > Thank you. > >> I also included opening parentheses. It’s an unlikely case but for >> consistency they should be included. > > If there's no need to exclude opening parenthesis, I suggest to use > > "\\([[:punct:][:space:]]\\|$\\)" This looks indeed much nicer but it’s not what we want. The Emacs documentation says: ‘[:punct:]’ This matches any punctuation character. (At present, for multibyte characters, it matches anything that has non-word syntax.) If this matches any non-word multibyte character, it also matches things like the multiplication sign along with a lot of other non-punctuation characters. So if we’d use [:punct:] we would incorrectly detect a latex fragment in the following example: 50$=10$×5 The patch with commit message is below. I did the FSF copyright paperwork a while ago (for a contribution to Emacs) so the TINYCHANGE tag may not be required. > instead of > > "\\(\\s.\\|\\s-\\|\\s(\\|\\s)\\|\\s\"\\|$\\)" > > It is shorter and clearer. > >> I also updated org.texi. Dashes are punctuation and don’t need special >> mention. I also clarified that quotes and parentheses are considered to >> be punctuation (although Emacs has separate syntax classes for them). > > OK. > > Could you provide a commit message for this patch and send it again, > with change above? Fix detection of latex fragments * org-element.el (org-element-latex-fragment-parser): * org.el (org-latex-regexps): Fix the detection of latex fragments. 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/doc/org.texi b/doc/org.texi index 7b78417..d926de4 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -10347,9 +10347,10 @@ Text within the usual @LaTeX{} math delimiters. To avoid conflicts with currency specifications, single @samp{$} characters are only recognized as math delimiters if the enclosed text contains at most two line breaks, is directly attached to the @samp{$} characters with no whitespace in between, -and if the closing @samp{$} is followed by whitespace, punctuation or a dash. -For the other delimiters, there is no such restriction, so when in doubt, use -@samp{\(...\)} as inline math delimiters. +and if the closing @samp{$} is followed by whitespace or punctuation +(parentheses and quotes are considered to be punctuation in this +context). For the other delimiters, there is no such restriction, so when in +doubt, use @samp{\(...\)} as inline math delimiters. @end itemize @noindent For example: diff --git a/lisp/org-element.el b/lisp/org-element.el index 7aab9f6..8f57c90 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)) diff --git a/lisp/org.el b/lisp/org.el index 6139876..46a73b6 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -540,8 +540,8 @@ An entry can be toggled between COMMENT and normal with '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t) ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil) ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p - ("$1" "\\([^$]\\|^\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil) - ("$" "\\([^$]\\|^\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil) + ("$1" "\\([^$]\\|^\\)\\(\\$[^ \r\n,;.$]\\$\\)\\(\\s.\\|\\s-\\|\\s(\\|\\s)\\|\\s\"\\|\000\\|$\\)" 2 nil) + ("$" "\\([^$]\\|^\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\(\\s.\\|\\s-\\|\\s(\\|\\s)\\|\\s\"\\|\000\\|$\\)" 2 nil) ("\\(" "\\\\([^\000]*?\\\\)" 0 nil) ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil) ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))