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.
This commit is contained in:
parent
f1359546ad
commit
2eb4fd8900
|
@ -14458,10 +14458,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.
|
||||
|
@ -14473,6 +14473,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:
|
||||
|
||||
|
|
|
@ -4116,6 +4116,7 @@ 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) "")
|
||||
|
@ -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)
|
||||
|
|
|
@ -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}"))))
|
||||
|
|
Loading…
Reference in New Issue