emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] ox-latex: Use \empty instead of \relax after \\
Date: Thu, 13 Oct 2022 22:18:47 +0700	[thread overview]
Message-ID: <ti9a8n$plc$1@ciao.gmane.io> (raw)
In-Reply-To: <87wn93re80.fsf@t14.reltub.ca>

[-- Attachment #1: Type: text/plain, Size: 786 bytes --]

On 13/10/2022 21:27, Leo Butler wrote:
> 
> Maybe Org should not use \\ to end lines in a latex-exported table?
> The fact that it has many variations argues against its use in Org, IMO.
> 
> My suggestion is to use the TeX command \cr.

Various LaTeX packages may redefine \\, so low level \cr might be not 
enough. Actually I do not like that \\ does not have a robust 
counterpart with no optional arguments.

> Or, define a command in the exported latex, something like
> 
> \newcommand{\orgcr}{\cr}

It is better to make `org-latex-line-break-safe' a user option instead 
of a constant.

For a record. Unlike \\, \newline does not have optional argument, but
{\centering a\\b\par} and {\centering a\newline b\par} are not equivalent.

I hope, \empty will behave better than \relax.

[-- Attachment #2: 0001-ox-latex-Use-empty-instead-of-relax-after.patch --]
[-- Type: text/x-patch, Size: 3627 bytes --]

From d79da60e6dcfb2f3d7c0a1f5abf9ee2bc684a15c Mon Sep 17 00:00:00 2001
In-Reply-To: <87wn93re80.fsf@t14.reltub.ca>
References: <87wn93re80.fsf@t14.reltub.ca>
From: Max Nikulin <manikulin@gmail.com>
Date: Thu, 13 Oct 2022 22:08:29 +0700
Subject: [PATCH] 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
---
 lisp/ox-latex.el               | 12 ++++++------
 testing/lisp/test-org-table.el |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index eed5dc898..aff90f611 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -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} \\\\
diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el
index 3e7f18a10..722c37ea4 100644
--- a/testing/lisp/test-org-table.el
+++ b/testing/lisp/test-org-table.el
@@ -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
-- 
2.25.1


  reply	other threads:[~2022-10-13 15:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12  3:15 Export of this table fails LuaLaTeX compilation gerard.vermeulen
2022-10-12  4:15 ` Ihor Radchenko
2022-10-12  4:45   ` Max Nikulin
2022-10-12  5:15     ` gerard.vermeulen
2022-10-12  5:55       ` Max Nikulin
2022-10-12  7:26         ` Ihor Radchenko
2022-10-12  8:20           ` Max Nikulin
2022-10-13  2:44             ` Ihor Radchenko
2022-10-13  4:59               ` Max Nikulin
2022-10-13 14:27                 ` Leo Butler
2022-10-13 15:18                   ` Max Nikulin [this message]
2022-10-14  2:32                     ` [PATCH] ox-latex: Use \empty instead of \relax after \\ Ihor Radchenko
2022-10-12  9:17         ` Export of this table fails LuaLaTeX compilation gerard.vermeulen
2022-10-12 16:21           ` Max Nikulin
2022-10-13  5:03             ` gerard.vermeulen
2022-10-12  4:53   ` gerard.vermeulen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='ti9a8n$plc$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).