emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: Footnote definition within a verse block has spurious line breaks when exported to LaTeX
Date: Tue, 01 Dec 2020 13:08:38 +0100	[thread overview]
Message-ID: <87sg8prant.fsf@posteo.net> (raw)

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

Hi,

When a verse block includes a footnote reference, the 
corresponding footnote definition is
understood in the LaTeX export as if it were part of the verses. 
In other words, every
line in a =\footnote{}= macro ends with the string =\\=, and the 
spaces between paragraphs are understood as spaces
between stanzas (\vspace*{1em}). If the text of the footnote 
definition contains one or more filled
paragraphs, then the export result is catastrophic.

For example, if we have something like this:

#+begin_src org
  ,#+begin_verse
  lorem
  ipsum[fn:1]
  dolor
  ,#+end_verse

  [fn:1] Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
  Donec hendrerit tempor
  tellus. Donec pretium posuere tellus. Proin quam nisl, tincidunt 
  et, mattis eget,
  convallis nec, purus.

  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec 
  hendrerit tempor tellus.
  Donec pretium posuere tellus. Proin quam nisl, tincidunt et, 
  mattis eget, convallis nec,
  purus.
#+end_src

in LaTeX we get this:

#+begin_src latex
\begin{verse}
lorem\\
ipsum\footnote{Lorem ipsum dolor sit amet, consectetuer adipiscing 
elit. Donec hendrerit tempor\\
tellus. Donec pretium posuere tellus. Proin quam nisl, tincidunt 
et, mattis eget,\\
convallis nec, purus.\\
\vspace*{1em}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec 
hendrerit tempor tellus.\\
Donec pretium posuere tellus. Proin quam nisl, tincidunt et, 
mattis eget, convallis nec,\\
purus.}\\
dolor\\
\end{verse}
#+end_src

Since footnotes are allowed within a LaTeX =verse= environment, I 
think
this behavior should be fixed.

I'm wondering if it would make sense to modify the
=org-latex-verse-block= function, in order to "save" the text 
formatting
of the footnote definition, something like this (apologies in 
advance
for my rudimentary Elisp: what I'm proposing is more of a
concept, or a pedestrian solution, than a actual patch ;-):

#+begin_src emacs-lisp
  (defun preserve-footnote-definition-in-verse-block (cont)
    (with-temp-buffer
      (insert cont)
      (save-excursion
	(goto-char (point-max))
	(while (re-search-backward "}" nil t)
	  (let ((from (point))
		(to (save-excursion
		      (re-search-backward "\\\\footnote{" nil t)
		      (point))))
	    (save-restriction
	      (narrow-to-region from to)
	      (goto-char (point-min))
	      (while (re-search-forward "\n\n+" nil t)
		(replace-match "\\\\par\s" t nil))
	      (goto-char (point-min))
	      (while (re-search-forward "\n" nil t)
		(replace-match "\s" t nil))))))
      (buffer-string)))

  (defun org-latex-verse-block (verse-block contents info)
    "Transcode a VERSE-BLOCK element from Org to LaTeX.
      CONTENTS is verse block contents.  INFO is a plist holding
      contextual information."
    (org-latex--wrap-label
     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.
     (format "\\begin{verse}\n%s\\end{verse}"
	     (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"
		(preserve-footnote-definition-in-verse-block 
		contents) nil t) nil t) nil t))
     info))
#+end_src

Best,

Juan Manuel

             reply	other threads:[~2020-12-01 12:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01 12:08 Juan Manuel Macías [this message]
2020-12-05  9:09 ` Nicolas Goaziou
2020-12-05 13:47   ` Juan Manuel Macías

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=87sg8prant.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    /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).