Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement footnotes for LaTeX output #314

Open
yihui opened this issue Mar 17, 2023 · 3 comments · May be fixed by r-lib/commonmark#32
Open

Implement footnotes for LaTeX output #314

yihui opened this issue Mar 17, 2023 · 3 comments · May be fixed by r-lib/commonmark#32

Comments

@yihui
Copy link

yihui commented Mar 17, 2023

Currently LaTeX output for footnotes is not implemented:

cmark-gfm/src/latex.c

Lines 447 to 449 in c32ef78

case CMARK_NODE_FOOTNOTE_DEFINITION:
case CMARK_NODE_FOOTNOTE_REFERENCE:
// TODO

I don't have much expertise on C but I wonder if the team is interested in getting it implemented. Basically what we need to do is to add the footnote content to \footnote{} in the case of CMARK_NODE_FOOTNOTE_REFERENCE, and output nil in the case of CMARK_NODE_FOOTNOTE_DEFINITION .

  case CMARK_NODE_FOOTNOTE_DEFINITION:
    break;
  case CMARK_NODE_FOOTNOTE_REFERENCE:
    if (entering) {
      LIT("\\footnote{");
      // How can I get the footnote content here?
    } else {
      LIT("}");
    }
    break;

Thanks!

@yihui
Copy link
Author

yihui commented Sep 13, 2024

HTML (if the footnotes extension is enabled):

<p>This is a test<sup class="footnote-ref"><a href="#fn-1" id="fnref-1" data-footnote-ref>1</a></sup></p>
<section class="footnotes" data-footnotes>
<ol>
<li id="fn-1">
<p>Nothing special. <a href="#fnref-1" class="footnote-backref" data-footnote-backref data-footnote-backref-idx="1" aria-label="Back to reference 1"></a></p>
</li>
</ol>
</section>

LaTeX (not implemented):

This is a test\footnote{Nothing special.}

@yoonghm
Copy link

yoonghm commented Sep 13, 2024

#362 have a solution and I have tested it that it works except that it could not handle
footnote with non-numerical value.

abc.md:

---
title: "footnote"
---

- A footnote[^1]
- A duplicated[^1]
- Another one[^2]
- A non-numeric[^tim]

[^1]: Footnote 1
[^2]: Footnote 2 with a line
      break
[^tim]: Time is essential

Using the command: cmark-gfm.exe --extension footnotes --to latex abc.md, we could get

\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}

\subsection{title: \textquotedbl{}footnote\textquotedbl{}}

\begin{itemize}
\item A footnote\footnote{1}

\item A duplicated\footnote{1}

\item Another one\footnote{2}

\item A non-numeric\footnote{3}

\end{itemize}

\footnote{1Footnote 1

}\footnote{2Footnote 2 with a line
break

}\footnote{timTime is essential

}

So, from your example, LaTeX expects the footnote definition is in the body text, not at the end of the document. LaTeX will automatically generate reference numbers.

@yihui
Copy link
Author

yihui commented Sep 13, 2024

That will be a great step forward! I really wish Github could merge #362, although it appears to me that they don't pay much attention to bug reports or PRs from the community.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants