emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Footnote definition within a verse block has spurious line breaks when e


From: Juan Manuel Macías
Subject: Footnote definition within a verse block has spurious line breaks when exported to LaTeX
Date: Tue, 01 Dec 2020 13:08:38 +0100

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 via email to

[Prev in Thread] Current Thread [Next in Thread]