emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Footnote definition within a verse block has spurious line breaks when exported to LaTeX
@ 2020-12-01 12:08 Juan Manuel Macías
  2020-12-05  9:09 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Juan Manuel Macías @ 2020-12-01 12:08 UTC (permalink / raw)
  To: orgmode

[-- 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

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

end of thread, other threads:[~2020-12-05 13:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-01 12:08 Footnote definition within a verse block has spurious line breaks when exported to LaTeX Juan Manuel Macías
2020-12-05  9:09 ` Nicolas Goaziou
2020-12-05 13:47   ` Juan Manuel Macías

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).