all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [patch] ox-latex.el: fix blank lines behavior in verse block
@ 2023-08-06 12:03 Juan Manuel Macías
  2023-08-07 11:40 ` Ihor Radchenko
  0 siblings, 1 reply; 22+ messages in thread
From: Juan Manuel Macías @ 2023-08-06 12:03 UTC (permalink / raw)
  To: orgmode

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

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ox-latex.el-fix-blank-lines-behavior-in-verse-b.patch --]
[-- Type: text/x-patch, Size: 1944 bytes --]

From 0c8a352567333d0d743b5235b68e9cd5d513f615 Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@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


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2023-08-18  8:45 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-06 12:03 [patch] ox-latex.el: fix blank lines behavior in verse block Juan Manuel Macías
2023-08-07 11:40 ` Ihor Radchenko
2023-08-07 17:23   ` Juan Manuel Macías
2023-08-09  7:57     ` Ihor Radchenko
2023-08-09  8:41       ` Juan Manuel Macías
2023-08-10  9:27         ` Ihor Radchenko
2023-08-10 10:39           ` Juan Manuel Macías
2023-08-11 10:00             ` Ihor Radchenko
2023-08-11 18:52               ` Juan Manuel Macías
2023-08-12  7:56                 ` Ihor Radchenko
2023-08-12 11:28                   ` Juan Manuel Macías
2023-08-13  8:06                     ` Ihor Radchenko
2023-08-14 20:10                   ` Juan Manuel Macías
2023-08-15 10:08                     ` Ihor Radchenko
2023-08-15 11:50                       ` Juan Manuel Macías
2023-08-15 11:53                         ` Ihor Radchenko
2023-08-15 14:25                           ` Juan Manuel Macías
2023-08-16  8:10                             ` Ihor Radchenko
2023-08-16 14:10                               ` Juan Manuel Macías
2023-08-17 10:35                                 ` Ihor Radchenko
2023-08-17 20:17                                   ` Juan Manuel Macías
2023-08-18  8:44                                     ` Ihor Radchenko

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.