Org-mode mailing list
 help / color / mirror / Atom feed
* [patch] A proposal to add LaTeX attributes to verse blocks
@ 2020-12-17 17:11 Juan Manuel Macías
  2021-01-03 10:22 ` TEC
  0 siblings, 1 reply; 7+ messages in thread
From: Juan Manuel Macías @ 2020-12-17 17:11 UTC (permalink / raw)
  To: orgmode


[-- Attachment #1.1: Type: text/plain, Size: 4802 bytes --]

Hi,

I would like to propose this patch to add some LaTeX attributes to verse blocks,
especially to be able to apply certain features from the verse.sty package, which is an
extension (widely used in Humanities) of the standard LaTeX 'verse'
environment (see https://www.ctan.org/pkg/verse).

These attributes would be:

- `:lines' to add verse numbers, according to any numbering sequence

- `:center' to apply the optical centering of the poem, which is a typographic convention
  whereby a poem or a group of verses is centered (as a 'block') on the page, taking the width of the
  longest verse as a reference. In fact, optical centering is the correct arrangement of
  verses in a document.
  
- `:versewidth' which expects a literal string that is the longest verse of the poem,
  required when applying the `:center' attribute.

As I said, these three attributes require the LateX package verse.sty. A fourth `:options'
attribute would be used to add arbitrary code within the verse environment.

Consider this complete example with Shakespeare's first sonnet:

#+begin_src org
  ,#+ATTR_LaTeX: :center t :options \small :lines 5
  ,#+ATTR_LaTeX: :versewidth Feed’st thy light’st flame with self-substantial fuel,
  ,#+begin_verse
  From fairest creatures we desire increase,
  That thereby beauty’s rose might never die,
  But as the riper should by time decrease,
  His tender heir mught bear his memeory:
  But thou, contracted to thine own bright eyes,
  Feed’st thy light’st flame with self-substantial fuel,
  Making a famine where abundance lies,
  Thyself thy foe, to thy sweet self too cruel.
  Thou that art now the world’s fresh ornament
  And only herald to the gaudy spring,
  Within thine own bud buriest thy content
  And, tender churl, makest waste in niggarding.
  Pity the world, or else this glutton be,
  To eat the world’s due, by the grave and thee.
  ,#+end_verse
#+end_src

when exporting to LaTeX we get:

#+begin_src latex
\settowidth{\versewidth}{Feed’st thy light’st flame with self-substantial fuel,}
\begin{verse}[\versewidth]
\poemlines{5}
\small
From fairest creatures we desire increase,\\
That thereby beauty’s rose might never die,\\
But as the riper should by time decrease,\\
His tender heir mught bear his memeory:\\
But thou, contracted to thine own bright eyes,\\
Feed’st thy light’st flame with self-substantial fuel,\\
Making a famine where abundance lies,\\
Thyself thy foe, to thy sweet self too cruel.\\
Thou that art now the world’s fresh ornament\\
And only herald to the gaudy spring,\\
Within thine own bud buriest thy content\\
And, tender churl, makest waste in niggarding.\\
Pity the world, or else this glutton be,\\
To eat the world’s due, by the grave and thee.\\
\end{verse}
#+end_src

In an attached image I send a screenshot with the typographic result

And finally, this is the patch I would propose

#+begin_src diff
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 2a14b25d5..bc6b64e78 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3506,6 +3506,16 @@ channel."
   "Transcode a VERSE-BLOCK element from Org to LaTeX.
 CONTENTS is verse block contents.  INFO is a plist holding
 contextual information."
+(let*
+      ((lin (org-export-read-attribute :attr_latex verse-block :lines))
+       (opt (org-export-read-attribute :attr_latex verse-block :options))
+       (cent (org-export-read-attribute :attr_latex verse-block :center))
+       (attr (concat
+	      (if cent "[\\versewidth]" "")
+	      (if lin (format "\n\\poemlines{%s}" lin) "")
+	      (if opt (format "\n%s" opt) "")))
+       (versewidth (org-export-read-attribute :attr_latex verse-block :versewidth))
+       (vwidth-attr (if versewidth (format "\\settowidth{\\versewidth}{%s}\n" versewidth) "")))
   (concat
    (org-latex--wrap-label
     verse-block
@@ -3513,7 +3523,9 @@ contextual information."
     ;; 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.
-    (format "\\begin{verse}\n%s\\end{verse}"
+    (format "%s\\begin{verse}%s\n%s\\end{verse}"
+	      vwidth-attr
+	      attr
            (replace-regexp-in-string
             "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m)))
             (replace-regexp-in-string
@@ -3524,7 +3536,7 @@ contextual information."
     info)
    ;; Insert footnote definitions, if any, after the environment, so
    ;; the special formatting above is not applied to them.
-   (org-latex--delayed-footnotes-definitions verse-block info)))
+   (org-latex--delayed-footnotes-definitions verse-block info))))
#+end_src

Regards,

Juan Manuel

[-- Attachment #1.2: Type: text/html, Size: 1 bytes --]

[-- Attachment #2: verse-test.png --]
[-- Type: image/png, Size: 286585 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [PATCH] A proposal to add LaTeX attributes to verse blocks
@ 2020-12-17 17:23 Juan Manuel Macías
  2021-01-03 10:25 ` TEC
  0 siblings, 1 reply; 7+ messages in thread
From: Juan Manuel Macías @ 2020-12-17 17:23 UTC (permalink / raw)
  To: orgmode

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

(Sorry, due to a mistake, the text of my message did not appear in my previous email)

Hi,

I would like to propose this patch to add some LaTeX attributes to the verse block,
especially to be able to apply certain features from the verse.sty package, which is an
extension (widely used in Humanities) of the standard LaTeX 'verse' environment.

These attributes would be:

- `:lines' to add verse numbers, according to any numbering sequence
- `:center' to apply the optical centering of the poem, which is a typographic convention
  whereby a poem or a group of verses is centered on the page, taking the width of the
  longest verse as a reference. In fact, optical centering is the correct arrangement of
  verses in a document.
- `:versewidth' which expects a text string that is the longest verse of the poem,
  required when applying the `:center' attribute.

As I said, these three attributes require the LateX package verse.sty. A fourth `:options'
attribute would be used to add arbitrary code within the verse environment.

Consider this complete example with Shakespeare's first sonnet:

#+begin_src org
  ,#+ATTR_LaTeX: :center t :options \small :lines 5
  ,#+ATTR_LaTeX: :versewidth Feed’st thy light’st flame with self-substantial fuel,
  ,#+begin_verse
  From fairest creatures we desire increase,
  That thereby beauty’s rose might never die,
  But as the riper should by time decrease,
  His tender heir mught bear his memeory:
  But thou, contracted to thine own bright eyes,
  Feed’st thy light’st flame with self-substantial fuel,
  Making a famine where abundance lies,
  Thyself thy foe, to thy sweet self too cruel.
  Thou that art now the world’s fresh ornament
  And only herald to the gaudy spring,
  Within thine own bud buriest thy content
  And, tender churl, makest waste in niggarding.
  Pity the world, or else this glutton be,
  To eat the world’s due, by the grave and thee.
  ,#+end_verse
#+end_src

when exporting to LaTeX we get:

#+begin_src latex
\settowidth{\versewidth}{Feed’st thy light’st flame with self-substantial fuel,}
\begin{verse}[\versewidth]
\poemlines{5}
\small
From fairest creatures we desire increase,\\
That thereby beauty’s rose might never die,\\
But as the riper should by time decrease,\\
His tender heir mught bear his memeory:\\
But thou, contracted to thine own bright eyes,\\
Feed’st thy light’st flame with self-substantial fuel,\\
Making a famine where abundance lies,\\
Thyself thy foe, to thy sweet self too cruel.\\
Thou that art now the world’s fresh ornament\\
And only herald to the gaudy spring,\\
Within thine own bud buriest thy content\\
And, tender churl, makest waste in niggarding.\\
Pity the world, or else this glutton be,\\
To eat the world’s due, by the grave and thee.\\
\end{verse}
#+end_src

In an attached image I send a screenshot with the typographic result

And finally, this is the patch I would propose

#+begin_src diff
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 2a14b25d5..bc6b64e78 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3506,6 +3506,16 @@ channel."
   "Transcode a VERSE-BLOCK element from Org to LaTeX.
 CONTENTS is verse block contents.  INFO is a plist holding
 contextual information."
+(let*
+      ((lin (org-export-read-attribute :attr_latex verse-block :lines))
+       (opt (org-export-read-attribute :attr_latex verse-block :options))
+       (cent (org-export-read-attribute :attr_latex verse-block :center))
+       (attr (concat
+	      (if cent "[\\versewidth]" "")
+	      (if lin (format "\n\\poemlines{%s}" lin) "")
+	      (if opt (format "\n%s" opt) "")))
+       (versewidth (org-export-read-attribute :attr_latex verse-block :versewidth))
+       (vwidth-attr (if versewidth (format "\\settowidth{\\versewidth}{%s}\n" versewidth) "")))
   (concat
    (org-latex--wrap-label
     verse-block
@@ -3513,7 +3523,9 @@ contextual information."
     ;; 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.
-    (format "\\begin{verse}\n%s\\end{verse}"
+    (format "%s\\begin{verse}%s\n%s\\end{verse}"
+	      vwidth-attr
+	      attr
	    (replace-regexp-in-string
	     "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m)))
	     (replace-regexp-in-string
@@ -3524,7 +3536,7 @@ contextual information."
     info)
    ;; Insert footnote definitions, if any, after the environment, so
    ;; the special formatting above is not applied to them.
-   (org-latex--delayed-footnotes-definitions verse-block info)))
+   (org-latex--delayed-footnotes-definitions verse-block info))))
#+end_src

Regards,

Juan Manuel

[-- Attachment #2: Type: text/html, Size: 0 bytes --]

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

end of thread, other threads:[~2021-01-07 18:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 17:11 [patch] A proposal to add LaTeX attributes to verse blocks Juan Manuel Macías
2021-01-03 10:22 ` TEC
2020-12-17 17:23 [PATCH] " Juan Manuel Macías
2021-01-03 10:25 ` TEC
2021-01-03 13:07   ` Juan Manuel Macías
2021-01-03 13:08     ` TEC
2021-01-07 18:52       ` Juan Manuel Macías

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git