ox-latex: Use \empty instead of \relax after \\

* lisp/ox-latex.el (org-latex-line-break-safe, org-latex-table-row):
* testing/lisp/test-org-table.el (test-org-table/to-latex): Use \empty
instead of \relax to prevent interpreting following "*" and "[" as
optional parts of \\*[LENGTH] command.

Fix regression introduced by 3f60acff77. \\\relax\hline caused
misaligned \noalign error. Org markup:

    | a |
    |---|

\hline is allowed only immediately after \cr while \relax has some side
effects. Hope, \empty just expands to nothing.

Those who used \\ optional argument to adjust amount of space between
lines may add the following tricks:

    First,\\
    @@latex:{\vskip1em}@@second.

    | First                               |
    | @@latex:\noalign{\vskip1em}@@second |

Reported in
gerard.vermeulen, Wed, 12 Oct 2022 03:15:49 +0000.
https://list.orgmode.org/784cf8be450b7d676ddd60214cc847db@posteo.net
This commit is contained in:
Max Nikulin 2022-10-13 22:08:29 +07:00 committed by Ihor Radchenko
parent 2d6032db96
commit 892df429f4
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 9 additions and 9 deletions

View File

@ -278,17 +278,17 @@ list can be:
- `:lang-name' the actual name of the language.")
(defconst org-latex-line-break-safe "\\\\\\relax"
(defconst org-latex-line-break-safe "\\\\\\empty"
"Linebreak protecting the following [...].
Without \"\\relax\" it would be interpreted as an optional argument to
Without \"\\empty\" it would be interpreted as an optional argument to
the \\\\.
This constant, for example, makes the below code not err:
\\begin{tabular}{c|c}
[t] & s\\\\\\relax
[I] & A\\\\\\relax
[t] & s\\\\\\empty
[I] & A\\\\\\empty
[m] & kg
\\end{tabular}")
@ -4005,9 +4005,9 @@ a communication channel."
(org-export-get-parent-table table-row) info))))
(format "%s
\\endfirsthead
\\multicolumn{%d}{l}{%s} \\\\\\relax
\\multicolumn{%d}{l}{%s} \\\\\\empty
%s
%s \\\\\\relax\n
%s \\\\\\empty\n
%s
\\endhead
%s\\multicolumn{%d}{r}{%s} \\\\

View File

@ -1635,11 +1635,11 @@ See also `test-org-table/copy-field'."
(ert-deftest test-org-table/to-latex ()
"Test `orgtbl-to-latex' specifications."
(should
(equal "\\begin{tabular}{l}\na\\\\\\relax\n\\end{tabular}"
(equal "\\begin{tabular}{l}\na\\\\\\empty\n\\end{tabular}"
(orgtbl-to-latex (org-table-to-lisp "| a |") nil)))
;; Test :environment parameter.
(should
(equal "\\begin{tabularx}{l}\na\\\\\\relax\n\\end{tabularx}"
(equal "\\begin{tabularx}{l}\na\\\\\\empty\n\\end{tabularx}"
(orgtbl-to-latex (org-table-to-lisp "| a |")
'(:environment "tabularx"))))
;; Test :booktabs parameter.
@ -1648,7 +1648,7 @@ See also `test-org-table/copy-field'."
"\\toprule" (orgtbl-to-latex (org-table-to-lisp "| a |") '(:booktabs t))))
;; Handle LaTeX snippets.
(should
(equal "\\begin{tabular}{l}\n\\(x\\)\\\\\\relax\n\\end{tabular}"
(equal "\\begin{tabular}{l}\n\\(x\\)\\\\\\empty\n\\end{tabular}"
(orgtbl-to-latex (org-table-to-lisp "| $x$ |") nil)))
;; Test pseudo objects and :raw parameter.
(should