From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id uKjQFKIhqWWaJAAAe85BDQ:P1 (envelope-from ) for ; Thu, 18 Jan 2024 14:03:30 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id uKjQFKIhqWWaJAAAe85BDQ (envelope-from ) for ; Thu, 18 Jan 2024 14:03:30 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=dbAcClnZ; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1705583010; 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=YSYScQtbePoaHtOk49RykUtkNg/Y7dMqfStR7ZdqdKs=; b=pUJY/oOET6d5BYv+cE98a1yaddc8v2HTdYvGjIAizzlD38sQeiatuRUEwcS0YVJkW62qEi /dsL3mb+F9rony+5SafZapFotmvhb5XM/UuaStxlTah3QIsLd8E+pLZEmGfuOcJOD2zcZn CYsShMVxfb5nS++b9IxmEYKJ6P0fJhkj2pSyqdKpAcWJLo4JSW5myjtOk3Cmm16e2sVrFc toCXp8eCT0KvFUOUsVjKNpHtTNmXWnz1jHTZfJCBdGFhzqe2fB9JWXVTtxIdoWkettHhu8 5jzf18iAK/c2D0KP3LzA/JXaZOVLai1hqREqKRCw78I/9HaEwZvVVIZWcZacfA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=dbAcClnZ; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1705583010; a=rsa-sha256; cv=none; b=s/LxsB5p3clxXx/bNtjrkaqI2iv/1HdYyfIRVJpktps5eaxwhXJoWURsj+PP5W/eIdr+W+ mKJmaNWFDlB0EzqfVnaz1BvDGikS2vvoSdRbBoHQNEDNuVtVrx8ZL3+RLsXSFQXbkxaqMy JKRH83gR9WOrYQU525sD+oro5At37r4LT4xFBD8I4TI/cufuu55SS0rmw/EGGgFp43CcN6 peKBqqE9tG17UVysx1t9skR6V6HLDoWxyk/x/ZZ/TF52UM8xzxsE7qTJYvFqTWv/AhFX/7 MXOEsIYRFiCLPozMc682qiCTdaNTp5clA6bQZUYCe9o+/42A6TU2R+MeYhWqeQ== 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 5C97A39DF7 for ; Thu, 18 Jan 2024 14:03:29 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQS2Z-0008RY-Ib; Thu, 18 Jan 2024 08:02:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQS2X-0008PC-DR for emacs-orgmode@gnu.org; Thu, 18 Jan 2024 08:02:37 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQS2U-0003xA-U6 for emacs-orgmode@gnu.org; Thu, 18 Jan 2024 08:02:37 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 4854E240104 for ; Thu, 18 Jan 2024 14:02:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1705582952; bh=rUCI/ftxKRSD7Vl1hTVwkKfbHTXIniJ0+aIPCMT3HBs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=dbAcClnZea9CoFRqKmyFhHOW/aY/5ZeQFN8GIJOFWoo22dgi3a/EXgqUeE1j0l8mB DMNAiyczG3RVGeq7nnacTN5sJXjfaI+s534KYVfaHoOQ+tTHAcsqJImKCo1wEp6XVQ rYhokk/WSnmqvOGzJowkIzalh0rCkkUdPM04rRU6K16TUzUfeEshYTZxKfUWfGrhB6 ZvDsR4LxHp8YANCOxPFLHaEvutMsdhYET0c4UfwIO7CGq2QAzzhrkIDWepRL2b7XZC dp8QCmVvmU+iuSeLOwnl5q5OEZch27dkM3n/3+JvXha9V/n/0FvSju9VxyTdNDZJvE Q3TS3LGlGv9dQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TG2w724Tnz6tyX; Thu, 18 Jan 2024 14:02:31 +0100 (CET) From: Ihor Radchenko To: Juan Manuel =?utf-8?Q?Mac=C3=ADas?= Cc: orgmode , Max Nikulin Subject: Re: [possible patch] Remove the '\\[0pt]' string from the last line of a verse block in LaTeX export In-Reply-To: <87o7dju9vn.fsf@posteo.net> References: <874jfvjo2k.fsf@posteo.net> <87cyu5uv7c.fsf@localhost> <878r4tfccn.fsf@posteo.net> <87zfx9t7di.fsf@localhost> <87wmsddlw5.fsf@posteo.net> <87r0ikrt5h.fsf@localhost> <87o7dnefwo.fsf@posteo.net> <87cyu1l69f.fsf@localhost> <87il3tax9a.fsf@posteo.net> <8734uwjerg.fsf@localhost> <87o7dju9vn.fsf@posteo.net> Date: Thu, 18 Jan 2024 13:05:46 +0000 Message-ID: <8734uuaj11.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.89 X-Migadu-Scanner: mx13.migadu.com X-Spam-Score: -9.89 X-Migadu-Queue-Id: 5C97A39DF7 X-TUID: ymDWip769FGS --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Juan Manuel Mac=C3=ADas writes: >> As for {[}{]}, it is a bit difficult to implement. Especially when we >> also consider user filters and derived backends. If we have several >> transcoders of consequent elements, there is always a risk that even >> when a given filter/transcoder is generating a valid LaTeX code, >> concatenating them may still cause issues like we have with \\. > > I see. I think pandoc's solution is what Leslie Lamport recommends > (naturally, Lamport doesn't say to enclose /all/ brackets in curly > braces). This turned out to be a lot easier than I thought. See the attached patch. >> \command >> [unrelated text] >> >> If there are, we may actually want to consider pandoc's approach >> seriously. > > In principle, any environment that takes an optional argument in a > "dangerous" position. Just do a simple test. Something like this: > > #+begin_figure > [lorem] ipsum > #+end_figure > > will throw an error like ''LaTeX Error: Unknown float option...'' > > Of course, putting an empty line after #+begin... usually solves it. But > the user may not know it. > > There are also a number of commands with an optional argument. For > example \pagebreak. Something like this will give an error: > > lorem @@latex:\pagebreak@@ [ipsum] > > \item is another typical example, but in this case org adds \relax. With the patch, I am getting the following: * This is test lorem @@latex:\pagebreak@@ [ipsum] #+begin_figure [lorem] figure #+end_figure | [foo] | 2 | | [bar] | 3 | - [bax] - [aur] exports to lorem \pagebreak {[}ipsum] \begin{figure} {[}lorem] figure \end{figure} \begin{center} \begin{tabular}{lr} {[}foo] & 2\\[0pt] {[}bar] & 3\\[0pt] \end{tabular} \end{center} \begin{itemize} \item {[}bax] \item {[}aur] \end{itemize} --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ox-latex-Make-sure-that-text-is-not-misinterpreted-a.patch >From db3fa01d6f15b3d3f499f77e342a608a822029c8 Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Thu, 18 Jan 2024 14:01:32 +0100 Subject: [PATCH] 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 432f09f4e..a3505c25f 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -3094,6 +3094,15 @@ (defun org-latex-plain-text (text info) "\\(?:[ \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 41df1b823..237ad97ec 100644 --- a/testing/lisp/test-ox-latex.el +++ b/testing/lisp/test-ox-latex.el @@ -29,6 +29,29 @@ (unless (featurep 'ox-latex) +(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 -- 2.43.0 --=-=-= 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 --=-=-=--