tomduck / pandoc-eqnos

A pandoc filter for numbering equations and equation references.
GNU General Public License v3.0
220 stars 27 forks source link

Wrong conversion of cross-references from md to jupyter notebook #58

Open cani-venatici opened 3 years ago

cani-venatici commented 3 years ago

Hi, i'm attaching a md formatted text and the corresponding jupyter notebook describing the issue I'm having that you could use as a MWE. Should the anchor link in the examples fail to wok on github please refer to the raw files in the zip.

I'm suggesting a solution to the issue. If there's another way or if I'm doing something wrong please let me know.

Great work with your filters, thank you in advance.


Pandoc-eqnos > jupyter notebook cross-reference issue

Description of the problem

pandoc-eqnos does not translate link anchors correctly when converting from markdown to jupyter notebook even though pandoc supports conversion from .md to .ipynb.

It seems that when converting markdown to jupyter notebook format, pandoc-eqnos translates the @eq:foo link id only as hardcoded latex code \qquad (#) to display the equation number. Instead, it should also attach a <a> anchor tag before the equation otherwise the cross-reference links called via @eq:foo will be broken.

This can be noticed when converting a markdown file filtered with pandoc-eqnos to jupyter notebook format or to markdown.

pandoc test.md --standalone --filter pandoc-eqnos -o test.ipynb

or

pandoc test.md --standalone --filter pandoc-eqnos -o test-2.md

Example of the problem

The equation below was typeset as,

$$
    x^{n} + y^{n} = z^{n}
$$ {#eq:a1}

and is converted to

$$
    x^{n} + y^{n} = z^{n}
\qquad (1)
$$

via pandoc test.md --standalone --filter pandoc-eqnos -o test.ipynb

$$ x^{n} + y^{n} = z^{n} \qquad (1) $$

Then the equation is referenced later in the text through @eq:a1. The cross-reference is converted correctly to [1](#eq:a1) in the jupyter notebook. However, the reference has nowhere to point to since the id #eq:a1 wasn't converted to an address link like <a> but hardcoded to plain text (\quadd (1)).

In fact, the following link anchor to the equation is broken 1


Correct behaviour and suggested solution

The following markdown+eqnos code

$$
    x^{n} + y^{n} = z^{n}
$$ {#eq:a2}

when filtered by pandoc-eqnos and converted to .ipynb or md should have attached a <a> id tag before the equation environment in order to be referenced correctly later in the text.

<a id="eq:a2"></a>
$$
    x^{n} + y^{n} = z^{n}
    \qquad (2)
$$

$$ x^{n} + y^{n} = z^{n} \qquad (2) $$

This is a working reference to equation (2) with a pointer to the <a> tag typeset via pandoc-eqnos usual syntax @eq:a2 ([2](#eq:a2)).

eqnos-jupyter-refs-issue.zip