Org-mode mailing list
 help / color / mirror / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Cc: Bastien <bzg@gnu.org>, TEC <tecosaur@gmail.com>,
	Eric Fraga <e.fraga@ucl.ac.uk>
Subject: Re: [PATCH] A proposal to add LaTeX attributes to verse blocks
Date: Sat, 08 May 2021 07:31:54 +0000
Message-ID: <874kfdn0k5.fsf@posteo.net> (raw)
In-Reply-To: <878s4y7mbh.fsf@gnu.org> (Bastien's message of "Sat, 01 May 2021 12:58:10 +0200")

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

Hi all,

Here I am attaching a new version of the patch that includes a commit
message.

I put here an example for those who want to try it, a fragment of a
poem by W.H. Auden.

Best regards,

Juan Manuel

#+begin_src org
  ,#+LaTeX_Header: \usepackage{verse}
  ,#+ATTR_LATEX: :center t
  ,#+ATTR_LATEX: :versewidth Teach the free man how to praise.
  ,#+ATTR_LATEX: :lines 5 :latexcode \small
  ,#+begin_verse
  Earth, receive an honoured guest:
  William Yeats is laid to rest.
  Let the Irish vessel lie
  Emptied of its poetry.

  In the nightmare of the dark
  All the dogs of Europe bark,
  And the living nations wait,
  Each sequestered in its hate;

  Intellectual disgrace
  Stares from every human face,
  And the seas of pity lie
  Locked and frozen in each eye.

  Follow, poet, follow right
  To the bottom of the night,
  With your unconstraining voice
  Still persuade us to rejoice;

  With the farming of a verse
  Make a vineyard of the curse,
  Sing of human unsuccess
  In a rapture of distress;

  In the deserts of the heart
  Let the healing fountain start,
  In the prison of his days
  Teach the free man how to praise.
  ,#+end_verse
#+end_src

https://juanmanuelmacias.com/


[-- Attachment #2: 0001-Add-LaTeX-attributes-for-verse-blocks.patch --]
[-- Type: text/x-patch, Size: 4774 bytes --]

From 337014731e89f7f28873b8f5d9a917901e810c95 Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Sat, 8 May 2021 09:03:10 +0200
Subject: [PATCH] Add LaTeX attributes for verse blocks

---
 doc/org-manual.org | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 lisp/ox-latex.el   | 20 +++++++++++++++----
 2 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index ab12fa70a..c752ce46d 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -13861,6 +13861,54 @@ The LaTeX export back-end converts horizontal rules by the specified
 -----
 #+end_example
 
+*** Verse blocks in LaTeX export
+:PROPERTIES:
+:DESCRIPTION: Attributes specific to special blocks.
+:END:
+
+#+cindex: verse blocks, in @LaTeX{} export
+#+cindex: @samp{ATTR_LATEX}, keyword
+
+The LaTeX export back-end accepts four attributes for verse blocks:
+=:lines=, =:center=, =:versewidth= and =:latexcode=. The three first
+require the external LaTeX package =verse.sty=, wich is an extension
+of the standard LaTeX environment. The purpose of these attributes is
+explained below.
+
+- =:lines= :: To add marginal verse numbering. Its value is an
+  integer, the sequence in which the verses should be numbered.
+- =:center= :: With value =t= all the verses on the page are optically
+  centered (a typographic convention for poetry), taking as a
+  reference the longest verse, which must be indicated by the
+  attribute =:versewidth=.
+- =:versewidth= :: Its value is a literal text string with the longest
+  verse.
+- =:latexcode= :: It accepts any arbitrary LaTeX code that can be
+  included within a LaTeX =verse= environment.
+
+A complete example with Shakespeare's first sonnet:
+
+#+begin_src org
+,#+ATTR_LaTeX: :center t :latexcode \color{red} :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
+
 ** Markdown Export
 :PROPERTIES:
 :DESCRIPTION: Exporting to Markdown.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c3fc83b1b..0376dffd1 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3513,6 +3513,17 @@ 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))
+       (latcode (org-export-read-attribute :attr_latex verse-block :latexcode))
+       (cent (org-export-read-attribute :attr_latex verse-block :center))
+       (attr (concat
+	      (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}" "")))
   (concat
    (org-latex--wrap-label
     verse-block
@@ -3520,19 +3531,20 @@ 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}%s"
+	      vwidth
+	      attr
 	    (replace-regexp-in-string
 	     "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m)))
 	     (replace-regexp-in-string
 	      "^[ \t]*\\\\\\\\$" "\\vspace*{1em}"
 	      (replace-regexp-in-string
 	       "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n"
-	       contents nil t) nil t) nil t))
+	       contents nil t) nil t) nil t) linreset)
     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))))
 
 \f
 ;;; End-user functions
-- 
2.26.0


  parent reply	other threads:[~2021-05-08  7:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17 17:23 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
2021-05-01 10:58         ` Bastien
2021-05-01 11:46           ` Juan Manuel Macías
2021-05-02 10:24           ` Eric S Fraga
     [not found]           ` <87tunlxws3.fsf@ucl.ac.uk>
2021-05-02 11:09             ` Juan Manuel Macías
2021-05-02 11:31             ` Timothy
2021-05-03 23:22               ` Tim Cross
2021-05-08  7:31           ` Juan Manuel Macías [this message]
2021-05-15 13:46             ` Bastien
2021-05-01 10:58         ` Timothy
  -- strict thread matches above, loose matches on Subject: below --
2020-12-17 17:11 [patch] " Juan Manuel Macías
2021-01-03 10:22 ` TEC

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://orgmode.org

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874kfdn0k5.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=bzg@gnu.org \
    --cc=e.fraga@ucl.ac.uk \
    --cc=emacs-orgmode@gnu.org \
    --cc=tecosaur@gmail.com \
    /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

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