commonmark icon indicating copy to clipboard operation
commonmark copied to clipboard

Implement LaTeX footnotes using `\footnotemark` and `\footnotetext`

Open yihui opened this issue 1 year ago • 2 comments

This is the best I could achieve with my poor knowledge of C. Ideally, we should render footnotes into \footnote{} in the case of CMARK_NODE_FOOTNOTE_REFERENCE, but I can't figure out how I can get the footnote content from the node there (maybe that's just not possible). I'd very much appreciate help here.

Fixes https://github.com/github/cmark-gfm/issues/314

yihui avatar Oct 11 '24 05:10 yihui

This is the best I could achieve with my poor knowledge of C. Ideally, we should render footnotes into \footnote{} in the case of CMARK_NODE_FOOTNOTE_REFERENCE, but I can't figure out how I can get the footnote content from the node there (maybe that's just not possible). I'd very much appreciate help here.

Could you give some example markdown input with the intended output (to match pandoc or similar), perhaps I can help.

jeroen avatar Oct 14 '24 23:10 jeroen

Sure:

Hello[^1]

[^1]: A footnote.

should generate

Hello\footnote{A footnote.}

Currently I'm generating

Hello\footnotemark[1]

\footnotetext[1]{A footnote.}

which is fine but not ideal.

yihui avatar Oct 14 '24 23:10 yihui

I have lost track of the discussion, sorry :(

It seems indeed upstream cmark-gfm is not actively maintained so we need to do it ourselves.

I can see why it is not ideal but indeed it would be much more complicated to move text content from the footnote reference back to the corresponding footnote mark location. So if you are still interested we can merge this solution.

jeroen avatar Jul 07 '25 11:07 jeroen

commonmark 2.0.0 is now on cran.

jeroen avatar Jul 07 '25 13:07 jeroen

Perfect! Thanks!

In {litedown}, I converted \footnotemark[x] and \footnotetext[x]{*} to \footnote{*}.

yihui avatar Oct 30 '25 20:10 yihui