quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.98k stars 328 forks source link

Footnotes are duplicated when reused #5440

Open mcanouil opened 1 year ago

mcanouil commented 1 year ago

Bug description

When a footnote is reused, it is duplicated.

This is the case at least for html, pdf, and revealjs.

---
format:
  html: default
  pdf: default
  revealjs: default
---

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi.[^1]

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi.[^1]

[^1]: This is the first footnote.
html pdf
image image

For instance the expected results would be the one that can be seen on GitHub.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi.[^1]

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi.[^1]

[^1]: This is the first footnote.


Quarto: latest development version OS: MacOS Apple Silicon IDE: VSCode

image

Checklist

cderv commented 1 year ago

I think this is a Pandoc limitation for now: https://github.com/jgm/pandoc/issues/1603

And also related to LaTeX produced for PDF Output

FOR HTML

Pandoc create both footnotes

> quarto pandoc test2.qmd --to html
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non
risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec,
ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula
massa, varius a, semper congue, euismod non, mi.<a href="#fn1"
class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non
risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec,
ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula
massa, varius a, semper congue, euismod non, mi.<a href="#fn2"
class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a></p>
<aside id="footnotes" class="footnotes footnotes-end-of-document"
role="doc-endnotes">
<hr />
<ol>
<li id="fn1"><p>This is the first footnote.<a href="#fnref1"
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn2"><p>This is the first footnote.<a href="#fnref2"
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</aside>

FOR PDF

> quarto pandoc test2.qmd --to latex
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.
Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies
sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius
a, semper congue, euismod non, mi.\footnote{This is the first footnote.}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.
Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies
sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius
a, semper congue, euismod non, mi.\footnote{This is the first footnote.}

We get two \footnote call which will lead to 2 footnotes in PDF. It does not seem as straightforward to do it in LaTeX. Some context: https://texfaq.org/FAQ-repfootnote

Other formats:

Probably happens in other formats too, like for Markdown as described in https://github.com/jgm/pandoc/issues/1603

mcanouil commented 1 year ago

I did not thought of trying that directly in Pandoc. Let's go for upstream.

Maybe a workaround, would be to write a small filter to "reformat" footnotes and "remove" duplicates.

cderv commented 1 year ago

Maybe a workaround, would be to write a small filter to "reformat" footnotes and "remove" duplicates.

I don't know if we want to start patching some Pandoc limitation like this, but if easy enough we could try. It is surprising that Pandoc doesn't.

@tarleb is there any big limitation that would prevent not having duplicated references ? Is this something we should try doing here ?

tarleb commented 1 year ago

The big issue is that this will require changes in pandoc's internal document representation; any info about multiple markers for the same footnote is already lost when pandoc parses the input.

A filter might work, but I'm not sure if it would cause problems in PDF output in cases where the footnotes were supposed to be separate. This should really be fixed in pandoc.

younes-io commented 1 month ago

I have this rendered

Image

and this (in the footnotes):

Image

even though my code is:

Now, let's try to apply this action to our initial state:

1. `active[token]`: This is true in our current state. Node 1 is active. This is called an *enabling condition*[^3].

::: {.callout-note appearance="simple"}
## Leslie Lamport

> *So, the definition of an action usually begins with its enabling condition* [^3]
:::