Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cross reference equations #37

Closed
RarrugasTetra opened this issue May 6, 2018 · 11 comments
Closed

Cross reference equations #37

RarrugasTetra opened this issue May 6, 2018 · 11 comments

Comments

@RarrugasTetra
Copy link

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
Copy link
Contributor

ProgramFan commented May 6, 2018

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
Copy link
Contributor

tstumm commented May 6, 2018

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
Copy link
Author

@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
Copy link
Author

@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
Copy link
Author

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
Copy link
Contributor

tstumm commented May 6, 2018

@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
Copy link
Contributor

tstumm commented May 6, 2018

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

@RarrugasTetra
Copy link
Author

@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
Copy link

@RarrugasTetra did you solve this? how?

@RarrugasTetra
Copy link
Author

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

@ProgramFan
Copy link
Contributor

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.

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

No branches or pull requests

4 participants