Merge branch 'maint'
This commit is contained in:
commit
df0c345eac
|
@ -2982,16 +2982,8 @@ Assume point is at the beginning of the LaTeX fragment."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let* ((begin (point))
|
(let* ((begin (point))
|
||||||
(after-fragment
|
(after-fragment
|
||||||
(if (eq (char-after) ?$)
|
(cond
|
||||||
(if (eq (char-after (1+ (point))) ?$)
|
((not (eq ?$ (char-after)))
|
||||||
(search-forward "$$" nil t 2)
|
|
||||||
(and (not (eq (char-before) ?$))
|
|
||||||
(search-forward "$" nil t 2)
|
|
||||||
(not (memq (char-before (match-beginning 0))
|
|
||||||
'(?\s ?\t ?\n ?, ?.)))
|
|
||||||
(looking-at-p
|
|
||||||
"\\(\\s.\\|\\s-\\|\\s(\\|\\s)\\|\\s\"\\|'\\|$\\)")
|
|
||||||
(point)))
|
|
||||||
(pcase (char-after (1+ (point)))
|
(pcase (char-after (1+ (point)))
|
||||||
(?\( (search-forward "\\)" nil t))
|
(?\( (search-forward "\\)" nil t))
|
||||||
(?\[ (search-forward "\\]" nil t))
|
(?\[ (search-forward "\\]" nil t))
|
||||||
|
@ -2999,10 +2991,23 @@ Assume point is at the beginning of the LaTeX fragment."
|
||||||
;; Macro.
|
;; Macro.
|
||||||
(and (looking-at "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\
|
(and (looking-at "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\
|
||||||
\\|\\({[^{}\n]*}\\)\\)*")
|
\\|\\({[^{}\n]*}\\)\\)*")
|
||||||
(match-end 0))))))
|
(match-end 0)))))
|
||||||
(post-blank (if (not after-fragment) (throw 'no-object nil)
|
((eq ?$ (char-after (1+ (point))))
|
||||||
(goto-char after-fragment)
|
(search-forward "$$" nil t 2))
|
||||||
(skip-chars-forward " \t")))
|
(t
|
||||||
|
(and (not (eq ?$ (char-before)))
|
||||||
|
(not (memq (char-after (1+ (point)))
|
||||||
|
'(?\s ?\t ?\n ?, ?. ?\;)))
|
||||||
|
(search-forward "$" nil t 2)
|
||||||
|
(not (memq (char-before (match-beginning 0))
|
||||||
|
'(?\s ?\t ?\n ?, ?.)))
|
||||||
|
(looking-at-p
|
||||||
|
"\\(\\s.\\|\\s-\\|\\s(\\|\\s)\\|\\s\"\\|'\\|$\\)")
|
||||||
|
(point)))))
|
||||||
|
(post-blank
|
||||||
|
(if (not after-fragment) (throw 'no-object nil)
|
||||||
|
(goto-char after-fragment)
|
||||||
|
(skip-chars-forward " \t")))
|
||||||
(end (point)))
|
(end (point)))
|
||||||
(list 'latex-fragment
|
(list 'latex-fragment
|
||||||
(list :value (buffer-substring-no-properties begin after-fragment)
|
(list :value (buffer-substring-no-properties begin after-fragment)
|
||||||
|
|
|
@ -1548,10 +1548,16 @@ e^{i\\pi}+1=0
|
||||||
|
|
||||||
(ert-deftest test-org-element/latex-fragment-parser ()
|
(ert-deftest test-org-element/latex-fragment-parser ()
|
||||||
"Test `latex-fragment' parser."
|
"Test `latex-fragment' parser."
|
||||||
|
;; Basic $...$ test.
|
||||||
(should
|
(should
|
||||||
(eq 'latex-fragment
|
(eq 'latex-fragment
|
||||||
(org-test-with-temp-text "$a$"
|
(org-test-with-temp-text "$a$"
|
||||||
(org-element-type (org-element-context)))))
|
(org-element-type (org-element-context)))))
|
||||||
|
;; Test valid characters after $...$ construct.
|
||||||
|
(should-not
|
||||||
|
(eq 'latex-fragment
|
||||||
|
(org-test-with-temp-text "$a$a"
|
||||||
|
(org-element-type (org-element-context)))))
|
||||||
(should
|
(should
|
||||||
(eq 'latex-fragment
|
(eq 'latex-fragment
|
||||||
(org-test-with-temp-text "$a$!"
|
(org-test-with-temp-text "$a$!"
|
||||||
|
@ -1576,18 +1582,46 @@ e^{i\\pi}+1=0
|
||||||
(eq 'latex-fragment
|
(eq 'latex-fragment
|
||||||
(org-test-with-temp-text "$a$'"
|
(org-test-with-temp-text "$a$'"
|
||||||
(org-element-type (org-element-context)))))
|
(org-element-type (org-element-context)))))
|
||||||
|
;; Test forbidden characters inside $...$.
|
||||||
(should-not
|
(should-not
|
||||||
(eq 'latex-fragment
|
(eq 'latex-fragment
|
||||||
(org-test-with-temp-text "$a$a"
|
(org-test-with-temp-text "$.a$"
|
||||||
(org-element-type (org-element-context)))))
|
(org-element-type (org-element-context)))))
|
||||||
|
(should-not
|
||||||
|
(eq 'latex-fragment
|
||||||
|
(org-test-with-temp-text "$,a$"
|
||||||
|
(org-element-type (org-element-context)))))
|
||||||
|
(should-not
|
||||||
|
(eq 'latex-fragment
|
||||||
|
(org-test-with-temp-text "$;a$"
|
||||||
|
(org-element-type (org-element-context)))))
|
||||||
|
(should-not
|
||||||
|
(eq 'latex-fragment
|
||||||
|
(org-test-with-temp-text "$ a$"
|
||||||
|
(org-element-type (org-element-context)))))
|
||||||
|
(should-not
|
||||||
|
(eq 'latex-fragment
|
||||||
|
(org-test-with-temp-text "$a.$"
|
||||||
|
(org-element-type (org-element-context)))))
|
||||||
|
(should-not
|
||||||
|
(eq 'latex-fragment
|
||||||
|
(org-test-with-temp-text "$a,$"
|
||||||
|
(org-element-type (org-element-context)))))
|
||||||
|
(should-not
|
||||||
|
(eq 'latex-fragment
|
||||||
|
(org-test-with-temp-text "$a $"
|
||||||
|
(org-element-type (org-element-context)))))
|
||||||
|
;; Test $$...$$.
|
||||||
(should
|
(should
|
||||||
(eq 'latex-fragment
|
(eq 'latex-fragment
|
||||||
(org-test-with-temp-text "$$a$$"
|
(org-test-with-temp-text "$$a$$"
|
||||||
(org-element-type (org-element-context)))))
|
(org-element-type (org-element-context)))))
|
||||||
|
;; Test \(...\).
|
||||||
(should
|
(should
|
||||||
(eq 'latex-fragment
|
(eq 'latex-fragment
|
||||||
(org-test-with-temp-text "\\(a\\)"
|
(org-test-with-temp-text "\\(a\\)"
|
||||||
(org-element-type (org-element-context)))))
|
(org-element-type (org-element-context)))))
|
||||||
|
;; Test \[...\].
|
||||||
(should
|
(should
|
||||||
(eq 'latex-fragment
|
(eq 'latex-fragment
|
||||||
(org-test-with-temp-text "\\[a\\]"
|
(org-test-with-temp-text "\\[a\\]"
|
||||||
|
|
Loading…
Reference in New Issue