[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org bd305ecdf6 2/3: ox-latex: Make sure that [text] is
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/org bd305ecdf6 2/3: ox-latex: Make sure that [text] is not misinterpreted as LaTeX argument |
|
Date: |
Wed, 31 Jan 2024 06:58:55 -0500 (EST) |
branch: externals/org
commit bd305ecdf68818eb678ad10f319722bc38037c3e
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>
ox-latex: Make sure that [text] is not misinterpreted as LaTeX argument
* lisp/ox-latex.el (org-latex-plain-text): Protect plain text starting
from [. It might be misinterpreted as optional command argument if
previous exported fragment ends with a command accepting such.
*
testing/lisp/test-ox-latex.el (text-ox-latex/protect-square-brackets):
Add new test.
Link: https://orgmode.org/list/87o7dju9vn.fsf@posteo.net
---
lisp/ox-latex.el | 9 +++++++++
testing/lisp/test-ox-latex.el | 23 +++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index df20345f83..a64dd5a87f 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3095,6 +3095,15 @@ contextual information."
"\\(?:[ \t]*\\\\\\\\\\)?[ \t]*\n"
(concat org-latex-line-break-safe "\n")
output nil t)))
+ ;; Protect [foo] at the beginning of lines / beginning of the
+ ;; plain-text object. This prevents LaTeX from unexpectedly
+ ;; interpreting @@latex:\pagebreak@@ [foo] as a command with
+ ;; optional argument.
+ (setq output (replace-regexp-in-string
+ (rx bol (0+ space) (group "["))
+ "{[}"
+ output
+ nil nil 1))
;; Return value.
output))
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 41df1b8234..237ad97ec9 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -29,6 +29,29 @@
+(ert-deftest text-ox-latex/protect-square-brackets ()
+ "Test [foo] being interpreted as plain text even after LaTeX commands."
+ (org-test-with-exported-text
+ 'latex
+ "* This is test
+lorem @@latex:\\pagebreak@@ [ipsum]
+
+#+begin_figure
+[lorem] figure
+#+end_figure
+
+| [foo] | 2 |
+| [bar] | 3 |
+
+- [bax]
+- [aur]
+"
+ (goto-char (point-min))
+ (should (search-forward "lorem \\pagebreak {[}ipsum]"))
+ (should (search-forward "{[}lorem] figure"))
+ (should (search-forward "{[}foo]"))
+ (should (search-forward "\\item {[}bax]"))))
+
(ert-deftest test-ox-latex/verse ()
"Test verse blocks."
(org-test-with-exported-text