From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: [patch] ox-latex.el: fix blank lines behavior in verse block
Date: Thu, 17 Aug 2023 20:17:32 +0000 [thread overview]
Message-ID: <877cpta0f7.fsf@posteo.net> (raw)
In-Reply-To: <87leeaq7mt.fsf@localhost> (Ihor Radchenko's message of "Thu, 17 Aug 2023 10:35:06 +0000")
[-- Attachment #1: Type: text/plain, Size: 1434 bytes --]
Ihor Radchenko writes:
> Thanks!
>
>> * (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. If the `:literal' attribute is
>> used, all blank lines are preserved and exported as
>
> Please use double space between sentences and start sentences with
> capital letter.
>
>> +- =:literal= :: With value t, all blank lines are preserved and
>> + exported as =\vspace*{\baselineskip}=, including the blank lines
>> + before or after contents. Note that without the =:literal=
>> + attribute, one or more blank lines between stanzas are exported as a
>> + single blank line, and any blank lines before or after the content
>> + are removed, which is more consistent with the syntax of the LaTeX
>> + `verse' environment, and the one provided by the `verse' package.
>> + If the =verse= package is loaded, the vertical spacing between all
>> + stanzas can be controlled by the global length =\stanzaskip= (see
>> + https://www.ctan.org/pkg/verse).
>
> s/`verse'/=verse=/
>
> And you need to update `test-ox-latex/verse' test - it is currently failing.
Sorry for the typos... Here goes the corrected patch again, with the
updated test.
--
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-Add-the-literal-attribute-to-verse-.patch --]
[-- Type: text/x-patch, Size: 6513 bytes --]
From bd956aa947e080ef10aa851f339414dc1cda1baf Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Mon, 14 Aug 2023 21:48:58 +0200
Subject: [PATCH] lisp/ox-latex.el: Add the `:literal' attribute to verse
block.
* (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. If the `:literal' attribute is
used, all blank lines are preserved and exported as
`\vspace*{\baselineskip}', including the blank lines before or after
contents. The rx code has been suggested by Ihor Radchenko, to
improve readability.
* doc/org-manual.org (Verse blocks in LaTeX export): The new feature
is documented.
* testing/lisp/test-ox-latex.el (test-ox-latex/verse): Updated.
---
doc/org-manual.org | 18 ++++++++++++++----
lisp/ox-latex.el | 36 ++++++++++++++++++++++++++---------
testing/lisp/test-ox-latex.el | 8 ++++----
3 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index e59efc417..ce0521dee 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14425,10 +14425,10 @@ The LaTeX export backend converts horizontal rules by the specified
#+cindex: verse blocks, in @LaTeX{} export
#+cindex: @samp{ATTR_LATEX}, keyword
-The LaTeX export backend accepts four attributes for verse blocks:
-=:lines=, =:center=, =:versewidth= and =:latexcode=. The three first
-require the external LaTeX package =verse.sty=, which is an extension
-of the standard LaTeX environment.
+The LaTeX export backend accepts five attributes for verse blocks:
+=:lines=, =:center=, =:versewidth=, =:latexcode= and =:literal=. The
+three first require the external LaTeX package =verse.sty=, which is
+an extension of the standard LaTeX environment.
- =:lines= :: To add marginal verse numbering. Its value is an
integer, the sequence in which the verses should be numbered.
@@ -14440,6 +14440,16 @@ of the standard LaTeX environment.
verse.
- =:latexcode= :: It accepts any arbitrary LaTeX code that can be
included within a LaTeX =verse= environment.
+- =:literal= :: With value t, all blank lines are preserved and
+ exported as =\vspace*{\baselineskip}=, including the blank lines
+ before or after contents. Note that without the =:literal=
+ attribute, one or more blank lines between stanzas are exported as a
+ single blank line, and any blank lines before or after the content
+ are removed, which is more consistent with the syntax of the LaTeX
+ `verse' environment, and the one provided by the =verse= package.
+ If the =verse= package is loaded, the vertical spacing between all
+ stanzas can be controlled by the global length =\stanzaskip= (see
+ https://www.ctan.org/pkg/verse).
A complete example with Shakespeare's first sonnet:
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 31cad1dc4..d11e3befa 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -4116,10 +4116,11 @@ contextual information."
(let* ((lin (org-export-read-attribute :attr_latex verse-block :lines))
(latcode (org-export-read-attribute :attr_latex verse-block :latexcode))
(cent (org-export-read-attribute :attr_latex verse-block :center))
+ (lit (org-export-read-attribute :attr_latex verse-block :literal))
(attr (concat
- (if cent "[\\versewidth]" "")
- (if lin (format "\n\\poemlines{%s}" lin) "")
- (if latcode (format "\n%s" latcode) "")))
+ (if cent "[\\versewidth]" "")
+ (if lin (format "\n\\poemlines{%s}" lin) "")
+ (if latcode (format "\n%s" latcode) "")))
(versewidth (org-export-read-attribute :attr_latex verse-block :versewidth))
(vwidth (if versewidth (format "\\settowidth{\\versewidth}{%s}\n" versewidth) ""))
(linreset (if lin "\n\\poemlines{0}" "")))
@@ -4128,20 +4129,37 @@ 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 normal space, calculated with `\fontdimen2\font'. One
+ ;; or more blank lines between lines are exported as a single
+ ;; blank line. If the `:lines' attribute is used, the last
+ ;; verse of each stanza ends with the string `\\!', according to
+ ;; the syntax of the `verse' package. The separation between
+ ;; stanzas can be controlled with the length `\stanzaskip', of
+ ;; the aforementioned package. If the `:literal' attribute is
+ ;; used, all blank lines are preserved and exported as
+ ;; `\vspace*{\baselineskip}', including the blank lines before
+ ;; or after CONTENTS.
(format "%s\\begin{verse}%s\n%s\\end{verse}%s"
vwidth
attr
(replace-regexp-in-string
- "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m)))
+ "^[ \t]+" (lambda (m) (format "\\hspace*{%d\\fontdimen2\\font}" (length m)))
(replace-regexp-in-string
- (concat "^[ \t]*" (regexp-quote org-latex-line-break-safe) "$")
- "\\vspace*{1em}"
+ (if (not lit)
+ (rx-to-string
+ `(seq (group ,org-latex-line-break-safe "\n")
+ (1+ (group line-start (0+ space) ,org-latex-line-break-safe "\n"))))
+ (concat "^[ \t]*" (regexp-quote org-latex-line-break-safe) "$"))
+ (if (not lit)
+ (if lin "\\\\!\n\n" "\n\n")
+ "\\vspace*{\\baselineskip}")
(replace-regexp-in-string
"\\([ \t]*\\\\\\\\\\)?[ \t]*\n"
(concat org-latex-line-break-safe "\n")
- contents nil t)
+ (if (not lit)
+ (concat (org-trim contents t) "\n")
+ contents)
+ nil t)
nil t)
nil t)
linreset)
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index adb3a60ea..79ef8793b 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -61,11 +61,11 @@ lorem ipsum dolor
(search-forward
"\\begin{verse}
lorem ipsum dolor\\\\[0pt]
+lorem ipsum dolor
+
lorem ipsum dolor\\\\[0pt]
-\\vspace*{1em}
-lorem ipsum dolor\\\\[0pt]
-lorem ipsum dolor\\\\[0pt]
-\\vspace*{1em}
+lorem ipsum dolor
+
lorem ipsum dolor\\\\[0pt]
lorem ipsum dolor\\\\[0pt]
\\end{verse}"))))
--
2.41.0
next prev parent reply other threads:[~2023-08-17 20:18 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2023-08-18 8:44 ` Ihor Radchenko
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=877cpta0f7.fsf@posteo.net \
--to=maciaschain@posteo.net \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@posteo.net \
/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).