From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id aHQzBJzkP2OegQEAbAwnHQ (envelope-from ) for ; Fri, 07 Oct 2022 10:34:36 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id SKFjA5zkP2M2ewAAG6o9tA (envelope-from ) for ; Fri, 07 Oct 2022 10:34:36 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 96562104DD for ; Fri, 7 Oct 2022 10:34:35 +0200 (CEST) Received: from localhost ([::1]:48358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogioT-0003gl-RC for larch@yhetil.org; Fri, 07 Oct 2022 04:34:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogikk-0002ik-DD for emacs-orgmode@gnu.org; Fri, 07 Oct 2022 04:30:43 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:34776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ogiki-0000Ub-7W for emacs-orgmode@gnu.org; Fri, 07 Oct 2022 04:30:42 -0400 Received: by mail-pg1-x532.google.com with SMTP id 195so4076340pga.1 for ; Fri, 07 Oct 2022 01:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=D+hmYZ6pw9E99jgkfdl/tajl/SqcQXeQGfN2U2Twtsw=; b=iEGP/SbLvgYRpJEzsATpLRPpnHMX5tZc8iaHLw8CZnyCPSCaO28/NKE+A+y+ehyXph VS5YgQJSi+CHR5MN75UXcsx9G1Xnprd71AG2bQFdwmvEMducXRcd9T3Q5ZjQfiOOtSzk 35Ez3/XWeore0GDYn4Qjblkk383TC7yihb/b0nPFIm6szjYbn4d9zv76j9AW+rlLk850 VdM0HEw/tXl2nvu76LPq20LcsmoB/d0oRqcTIhhiyBc8EUEw75yY+rVD79X886KFaHL5 qJ2lb5S07OKIhVi7GXR9hvRPolZjhxDfuaYKYFrR8tSGIF1OD/QU182s7/eauw9iHTKd zETg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D+hmYZ6pw9E99jgkfdl/tajl/SqcQXeQGfN2U2Twtsw=; b=wRR8AAG90D6JzvaOoogjWHi/KcmbNYsQiSaQOEAwhuPIt7ZsUYExJxuFLnosTmid84 zCEQIgpMXcOQAg7heu2XyYSjSVpuC60L40IT0ImTS1XjTNOu+/Bx50JKt0r+sKnBAEw7 QFRhXK1cXxUCfDUXUB3MDbgreCv/jKS3PSC5WISNo3GiHNDXDMh76qlEnzs7QeB7gHlt AYvvlJH+lf7iPVNJX77Bz15EfR7ZiKjiQVJb1sLI7Hcwknh5nddVVdv2aR318Y88jJLJ rtUg4lGAq/ad4j9UH/cyvN+HVUO3HtYITdmS541elbASwxgKAkJGqKJyiMMj7aTh7iRH nj1Q== X-Gm-Message-State: ACrzQf2vGEYUYrkQAFDp2qGJWRcKcPq8lKdNjFb9QW2BS3YLDTyRrekR EAyqgocs4unshioYHhilU0c= X-Google-Smtp-Source: AMsMyM7WNBaWsVQ5WQP7ge/GmOCdpZF/C9sib6CKjkQKm5qHW91CooG0dRvwpZPXetSJH/kFTxtCXg== X-Received: by 2002:a65:580a:0:b0:439:befc:d2b0 with SMTP id g10-20020a65580a000000b00439befcd2b0mr3504217pgr.302.1665131438620; Fri, 07 Oct 2022 01:30:38 -0700 (PDT) Received: from localhost ([2409:8970:af2:32f:6c23:3ad5:f37d:541b]) by smtp.gmail.com with ESMTPSA id i7-20020a628707000000b00562303ff59dsm992951pfe.48.2022.10.07.01.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 01:30:37 -0700 (PDT) From: Ihor Radchenko To: Max Nikulin , Daniel Fleischer Cc: Stewart Thomas , emacs-orgmode@gnu.org Subject: [PATCH] Re: [BUG] Tables with square brackets do not compile in PDF (latex) export [9.5 (release_9.5-59-g52e6f1 @ /home/sjt015/repo/emacs/lisp/org/)] In-Reply-To: References: Date: Fri, 07 Oct 2022 16:31:22 +0800 Message-ID: <8735c0kpb9.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=yantar92@gmail.com; helo=mail-pg1-x532.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1665131675; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=D+hmYZ6pw9E99jgkfdl/tajl/SqcQXeQGfN2U2Twtsw=; b=jP7fyqoJaKdOv+3u8yKEe1ru0WemlNoAo+9BlTAAqoxgi5nw1wECIrVBTLCUQackOJ/dY7 JnrXEiPj4Z0YLjMVF0yonQ4aJa6c6BYZMA9lGcpy1xLFmUAK4aBLHgjf/pDOby6DoY0eKJ I0MmVLzOhH8HMti1peX7tIH+rFU/e2RD+vYM/5RSgUOkE8BGIa5+G7u6gyoVtU94MwEF4k GG/2LwImmOHcH7gjogDJE/IExgYVb/RZJGScS3CeqXIDb7+O0ZYMznhJCQdZYbR5trVUFk Z2fg/0pf9sXWZvvUkWMLC7S4dKHOjyyjz2Ney97nSK2cMlEju2xhqyTj7It6DA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665131675; a=rsa-sha256; cv=none; b=UDbfvpkBC/bU61QFhOWBfzIOOKmfczXHpYyWu4bCdmdfGYF+lY3O04nW3LbQkpaNvpmCfE u/1+doDkNIZ4ktWlDjqNyfs1idfC58+KftObfMSW5Qt4d2rZLD3Ci8bk0xqz90tUEndPAN FPiFEp39c4KnzylAxZkNgnRFb3absRd8Nu3a4Uw9YD37WwIVn7l8NWHRyZ7dQXJZw8jmVE 3Sf8UiLfw5wVoKrlTYFfCF4iS9+7C+tQaU11d19l/FHQR0022ZFm61EGTIm307SUFsdrCK Qe9JMJcapOE3V8XrFdLG6yHez2Dz9j/LqpjoaLs1WHMjFT2Uo/tuFZPxOESNZQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="iEGP/SbL"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -7.67 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="iEGP/SbL"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 96562104DD X-Spam-Score: -7.67 X-Migadu-Scanner: scn0.migadu.com X-TUID: tvi5TuS5EYSe --=-=-= Content-Type: text/plain Max Nikulin writes: > On 10/11/2021 23:16, Stewart Thomas wrote: >> >> A table in which a first column begins with square brackets is not >> compiling. The square bracket is interpreted by latex as an argument >> to the preceding line break. > > Confirmed > > To fix the bug newline (in tables and paragraphs) should be exported as > "\\\relax" or "\\{}". I do not suggest curly brackets in the beginning > of line to avoid issues with spurious spaces. Percent character > (comment) at the end of line should be considered for a fix since it is > usually used in the opposite way: to suppress newline character and > spaces at the beginning of next source line. I am attaching a tentative patch to fix this. However, I am not sure if I replaced \\ with \\\relax in the right places. Daniel, can you please check? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ox-latex-Protect-.-after-to-be-interpreted-as-LaTeX-.patch >From 43d643197883e10a6c6551489d37053c2c89b4dd Mon Sep 17 00:00:00 2001 Message-Id: <43d643197883e10a6c6551489d37053c2c89b4dd.1665131437.git.yantar92@gmail.com> From: Ihor Radchenko Date: Fri, 7 Oct 2022 16:24:32 +0800 Subject: [PATCH] ox-latex: Protect [...] after \\ to be interpreted as LaTeX argument * lisp/ox-latex.el (org-latex-linebreak-safe): New constant holding safe version of LaTeX line break. (org-latex-table-matrix-macros): (org-latex-clock): (org-latex-line-break): (org-latex-plain-text): (org-latex-planning): (org-latex--org-table): (org-latex--math-table): (org-latex-table-row): (org-latex-verse-block): Use the new constant. * testing/lisp/test-org-table.el (test-org-table/to-latex): Update tests. Reported-by: Stewart Thomas Link: https://orgmode.org/list/ce760fc3-5aae-144d-2d02-7dea215f73fc@gmail.com --- lisp/ox-latex.el | 47 ++++++++++++++++++++++++---------- testing/lisp/test-org-table.el | 6 ++--- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 34ff52b81..127637ccf 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -278,10 +278,23 @@ (defconst org-latex-language-alist - `:lang-name' the actual name of the language.") +(defconst org-latex-linebreak-safe "\\\\\\relax" + "Linebreak protecting the following [...]. -(defconst org-latex-table-matrix-macros '(("bordermatrix" . "\\cr") +Without \"\\relax\" 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 + [m] & kg +\\end{tabular}") + +(defconst org-latex-table-matrix-macros `(("bordermatrix" . "\\cr") ("qbordermatrix" . "\\cr") - ("kbordermatrix" . "\\\\")) + ("kbordermatrix" . ,org-latex-linebreak-safe)) "Alist between matrix macros and their row ending.") (defconst org-latex-math-environments-re @@ -2062,7 +2075,7 @@ (defun org-latex-clock (clock _contents info) (concat (org-timestamp-translate (org-element-property :value clock)) (let ((time (org-element-property :duration clock))) (and time (format " (%s)" time))))) - "\\\\")) + org-latex-linebreak-safe)) ;;;; Code @@ -2659,7 +2672,7 @@ ;;;; Line Break (defun org-latex-line-break (_line-break _contents _info) "Transcode a LINE-BREAK object from Org to LaTeX. CONTENTS is nil. INFO is a plist holding contextual information." - "\\\\\n") + (concat org-latex-linebreak-safe "\n")) ;;;; Link @@ -3005,7 +3018,9 @@ (defun org-latex-plain-text (text info) ;; Handle break preservation if required. (when (plist-get info :preserve-breaks) (setq output (replace-regexp-in-string - "\\(?:[ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n" output nil t))) + "\\(?:[ \t]*\\\\\\\\\\)?[ \t]*\n" + (concat org-latex-linebreak-safe "\n") + output nil t))) ;; Return value. output)) @@ -3041,7 +3056,7 @@ (defun org-latex-planning (planning _contents info) (format (plist-get info :latex-active-timestamp-format) (org-timestamp-translate scheduled))))))) " ") - "\\\\")) + org-latex-linebreak-safe)) ;;;; Property Drawer @@ -3821,11 +3836,11 @@ (defun org-latex--org-table (table contents info) (format "\\begin{%s}%s{%s}\n" table-env width alignment) (and above? (org-string-nw-p caption) - (concat caption "\\\\\n")) + (concat caption org-latex-linebreak-safe "\n")) contents (and (not above?) (org-string-nw-p caption) - (concat caption "\\\\\n")) + (concat caption org-latex-linebreak-safe "\n")) (format "\\end{%s}" table-env) (and fontsize "}")))) (t @@ -3910,7 +3925,7 @@ (defun org-latex--math-table (table info) (lambda (cell) (substring (org-element-interpret-data cell) 0 -1)) (org-element-map row 'table-cell #'identity info) "&") - (or (cdr (assoc env org-latex-table-matrix-macros)) "\\\\") + (or (cdr (assoc env org-latex-table-matrix-macros)) org-latex-linebreak-safe) "\n"))) (org-element-map table 'table-row #'identity info) ""))) (concat @@ -3982,7 +3997,7 @@ (defun org-latex-table-row (table-row contents info) ;; hline was specifically marked. (and booktabsp (not (org-export-get-previous-element table-row info)) "\\toprule\n") - contents "\\\\\n" + contents org-latex-linebreak-safe "\n" (cond ;; Special case for long tables. Define header and footers. ((and longtablep (org-export-table-row-ends-header-p table-row info)) @@ -3990,9 +4005,9 @@ (defun org-latex-table-row (table-row contents info) (org-export-get-parent-table table-row) info)))) (format "%s \\endfirsthead -\\multicolumn{%d}{l}{%s} \\\\ +\\multicolumn{%d}{l}{%s} \\\\\\relax %s -%s \\\\\n +%s \\\\\\relax\n %s \\endhead %s\\multicolumn{%d}{r}{%s} \\\\ @@ -4092,8 +4107,12 @@ (defun org-latex-verse-block (verse-block contents info) (replace-regexp-in-string "^[ \t]*\\\\\\\\$" "\\vspace*{1em}" (replace-regexp-in-string - "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n" - contents nil t) nil t) nil t) linreset) + "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" + (concat org-latex-linebreak-safe "\n") + contents nil t) + nil t) + nil t) + linreset) info) ;; Insert footnote definitions, if any, after the environment, so ;; the special formatting above is not applied to them. diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 76fe41630..3e7f18a10 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -1635,11 +1635,11 @@ (ert-deftest test-org-table/to-generic () (ert-deftest test-org-table/to-latex () "Test `orgtbl-to-latex' specifications." (should - (equal "\\begin{tabular}{l}\na\\\\\n\\end{tabular}" + (equal "\\begin{tabular}{l}\na\\\\\\relax\n\\end{tabular}" (orgtbl-to-latex (org-table-to-lisp "| a |") nil))) ;; Test :environment parameter. (should - (equal "\\begin{tabularx}{l}\na\\\\\n\\end{tabularx}" + (equal "\\begin{tabularx}{l}\na\\\\\\relax\n\\end{tabularx}" (orgtbl-to-latex (org-table-to-lisp "| a |") '(:environment "tabularx")))) ;; Test :booktabs parameter. @@ -1648,7 +1648,7 @@ (ert-deftest test-org-table/to-latex () "\\toprule" (orgtbl-to-latex (org-table-to-lisp "| a |") '(:booktabs t)))) ;; Handle LaTeX snippets. (should - (equal "\\begin{tabular}{l}\n\\(x\\)\\\\\n\\end{tabular}" + (equal "\\begin{tabular}{l}\n\\(x\\)\\\\\\relax\n\\end{tabular}" (orgtbl-to-latex (org-table-to-lisp "| $x$ |") nil))) ;; Test pseudo objects and :raw parameter. (should -- 2.35.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--