asciidoctor / asciidoctor-mathematical

An extension for Asciidoctor that converts the content of STEM blocks and inline macros using Mathematical.
MIT License
49 stars 44 forks source link

Cross reference equations #37

Closed RarrugasTetra closed 6 years ago

RarrugasTetra commented 6 years ago

I would like to define an equation and then to reference it later in my text. The following example works fine with bare asciidoctor:

= Test eqn cross-ref
:stem: latexmath
:eqnums:

== Let's try

[stem]
++++
\begin{equation}\label{myequation}
c^2 = a^2 + b^2 + 5
\end{equation}
++++

I refer back to \eqref{myequation}.

A number is assigned automatically to the equation and the same number appears in the text below. Now, I would like to use asciidoctor-mathematical, but the referencing does not work anymore. The equation is generated with the number, this is already something, but the referencing does not work! In HTML I get just (???) and in PDF I get the unprocessed \eqref{myequation}.

I am using asciidoctor 1.5.4 and asciidoctor-mathematical 0.2.2

Could you help me to solve the problem?

ProgramFan commented 6 years ago

I don't quite understand the use case. But asciidoctor does not support label and reference equations using latex syntax. The native way is to assign the [stem] block an ID and reference it using asciidoc's internal cross-reference syntax.

For example:

== Let's try

[stem, id="myequation"]
++++
\begin{equation}
c^2 = a^2 + b^2 + 5
\end{equation}
++++

I refer back to <<myequation, Equation 2.5>>
tstumm commented 6 years ago

Also I'm pretty sure that mathematical has no such thing as continuous equation numbering. Two equation environments should both have the number 1.

RarrugasTetra commented 6 years ago

@ProgramFan, @tstumm Thank you for your reply! Of course asciidoctor supports reference equations using latex syntax! Check my example (it works correctly if asciidoctor is used without asciidoctor-mathematical). Also, you can consult asciidoctor's manual what for is the eqnums attribute. And this even works partially with asciidoctor-mathematical, namely equations get automatically numbers. What is not working is just referencing!

@ProgramFan Thank you for your example, but it is not practical at all, unfortunately. This is because you have to write explicitly the number of equation in the source file (Equation 2.5 in your example). Now imagine you have hundreds of equations and just by removing/adding one equation somewhere in text you have to renumber all equations below in the text!

That is why people are using automatic numbering and referencing of equations.

RarrugasTetra commented 6 years ago

@tstumm No, you are wrong. My equations get sequential numbers 1,2,3, ..etc automatically. I just cannot reference them, so that these numbers appear in text.

RarrugasTetra commented 6 years ago

Here I've created a testcase:

= Test eqn cross-ref
:stem: latexmath
:eqnums:

== Let's try

[stem]
++++
\begin{equation}\label{myequation}
c^2 = a^2 + b^2 + 5
\end{equation}
++++

++++
\begin{equation}\label{myequation2}
c^2 = a^2 + b^2 + 5
\end{equation}
++++

I refer back to \eqref{myequation} and \eqref{myequation2}.

If I compile it as asciidoctor --backend=html5 -a embedded -o test.html test.adoc everything works fine, check here

If I compile it with asciidoctor-mathematical as asciidoctor --backend=html5 -a embedded -r asciidoctor-mathematical -o test_math.html test.adoc then I get wrong result

tstumm commented 6 years ago

@RarrugasTetra Mhm, okay seems like I underestimated mathematical. But as far as I know, eqref is implemented by MathJax which is just used to render TeX stuff in browser. Hence, this is no feature of Asciidoctor itself!

I'm not sure if the implementation would be trivial, as we get absolutely no feedback on any equations / from mathematical. So we actually do not know the equation number when we generate the SVG / PNG. Also, we would need to process all text to find all usages of some reference commands.

tstumm commented 6 years ago

Same goes for eqnums, this is all handled by MathJax is not natively supported by Asciidoctor itself.

RarrugasTetra commented 6 years ago

@tstumm Sure, you are right about MathJax. I do not mean that asciidoctor-mathematical has a bug or so... but it would be very pity if it could not not support the autonumbering/referencing. Would it be possible to process \eqref's in asciidoctor-mathematical just like other stem blocks, so that inline SVG/PNG numbers are created and put in right places in text? Just as an idea...

siddjain commented 4 years ago

@RarrugasTetra did you solve this? how?

RarrugasTetra commented 4 years ago

No, I do not know how to cross-reference equations...

ProgramFan commented 4 years ago

Let's accept that asciidoctor does support numbering stem blocks yet. asciidoctor-mathematical can not do this on its own without introducing new syntax, which is the last thing such an extension would ever want to do. Numbering the equations is the latex way, not the asciidoc way. If you really want that, you can use asciidoctor with asciidoctor-latex to produce directly latex documents.