Rationale for this patch: the treatment of blank lines in `org-latex-verse-block' is inconsistent with the syntax of the `verse' environment, both the one that includes LaTeX and the one provided by the `verse' package as a replacement for the former.
Currently, each blank line is exported to LaTeX as an explicit vertical space: \vspace*{1em}. This can return unexpected results. For example, this: ┌──── │ #+begin_verse │ │ lorem │ ipsum │ dolor | │ #+end_verse └──── is exported to LaTeX as: ┌──── │ \begin{verse} │ \vspace*{1em} │ lorem\\[0pt] │ ipsum\\[0pt] │ dolor\\[0pt] │ \vspace*{1em} │ \end{verse} └──── In the LaTeX `verse' environment, spaces before and after the content are not taken into account. As for the separation between stanzas, this is marked with at least one blank line between the stanzas, as in normal paragraphs (not with an explicit vertical space). Also it is not necessar y that the last verse of each stanza ends with the linebreak mark `\\'. So, after this patch: • Any blank line before and/or after the content is removed; • One or more blank lines between stanzas are exported as a single blank line, leaving the previous final verse without the linebreak mark `\\'; • When verse numbering is enabled via the `:lines' attribute (for the `verse' package), the last verses of each stanza are marked with `\\!', according to the verse package syntax (this was not necessary with the previous behavior). This way, the `verse' block is exported to LaTeX with the correct syntax. This also brings the advantage of being able to globally control the spacing between stanzas via the verse package’s \stanzaskip command. Example: ┌──── │ #+begin_verse │ Lorem ipsum dolor │ lorem ipsum dolor │ lorem ipsum dolor │ │ Lorem ipsum dolor │ lorem ipsum dolor │ lorem ipsum dolor │ │ Lorem ipsum dolor │ lorem ipsum dolor │ lorem ipsum dolor │ #+end_verse └──── LaTeX: ┌──── │ \begin{verse} │ Lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\[0pt] │ lorem ipsum dolor │ │ Lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\[0pt] │ lorem ipsum dolor │ │ Lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\[0pt] │ \end{verse} └──── And with verse numbers: ┌──── │ #+ATTR_LaTeX: :lines 5 │ #+begin_verse │ Lorem ipsum dolor │ lorem ipsum dolor │ lorem ipsum dolor │ │ Lorem ipsum dolor │ lorem ipsum dolor │ lorem ipsum dolor │ │ Lorem ipsum dolor │ lorem ipsum dolor │ lorem ipsum dolor │ #+end_verse └──── LaTeX: ┌──── │ \begin{verse} │ \poemlines{5} │ Lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\! │ │ Lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\! │ │ Lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\[0pt] │ lorem ipsum dolor\\[0pt] │ \end{verse} │ \poemlines{0} └──── N.B.: the `\\[0pt]' mark of the last verse does not affect the final result. Best regards, Juan Manuel -- Juan Manuel Macías https://juanmanuelmacias.com https://lunotipia.juanmanuelmacias.com https://gnutas.juanmanuelmacias.com
>From 0c8a352567333d0d743b5235b68e9cd5d513f615 Mon Sep 17 00:00:00 2001 From: Juan Manuel Macias <maciasch...@posteo.net> Date: Sun, 6 Aug 2023 12:42:36 +0200 Subject: [PATCH] lisp/ox-latex.el: fix blank lines behavior in verse block export. * (org-latex-verse-block): now the treatment of blank lines is consistent with the syntax of the LaTeX `verse' environment, and the one provided by the `verse' package. --- lisp/ox-latex.el | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 31cad1dc4..26827537a 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -4128,20 +4128,28 @@ contextual information." verse-block ;; In a verse environment, add a line break to each newline ;; character and change each white space at beginning of a line - ;; into a space of 1 em. Also change each blank line with - ;; a vertical space of 1 em. + ;; into a space of 1 em. One or more blank lines between lines + ;; are exported as a single blank line. (format "%s\\begin{verse}%s\n%s\\end{verse}%s" vwidth attr (replace-regexp-in-string "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m))) (replace-regexp-in-string - (concat "^[ \t]*" (regexp-quote org-latex-line-break-safe) "$") - "\\vspace*{1em}" + (concat "\\(" + (regexp-quote org-latex-line-break-safe) + "\n\\)" + "\\(^[ \t]*" + (regexp-quote org-latex-line-break-safe) + "\n" + "\\)+") + (if lin "\\\\!\n\n" "\n\n") (replace-regexp-in-string "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" (concat org-latex-line-break-safe "\n") - contents nil t) + ;; Remove any blank lines before and after CONTENTS. + (concat (org-trim contents t) "\n") + nil t) nil t) nil t) linreset) -- 2.41.0