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

Add support for equation numbering and cross-referencing #3518

Open
siddjain opened this issue Dec 24, 2019 · 13 comments
Open

Add support for equation numbering and cross-referencing #3518

siddjain opened this issue Dec 24, 2019 · 13 comments
Assignees
Milestone

Comments

@siddjain
Copy link

It seems asciidoc has no support for equation numbering and cross-referencing? please see these threads:
asciidoctor/asciidoctor-mathematical#37 (comment)
could support for this be added please?

@mojavelinux
Copy link
Member

Equation numbering is handled by MathJax itself. It can be enabled by setting the eqnums document attribute. Other equations can then refer to these numbers.

You can also give the block and ID so you can reference it from AsciiDoc content.

:stem: latexmath
:eqnums:

[latexmath#eq-1,reftext=Equation 1]
++++
\begin{equation}
y = x^2
\end{equation}
++++

see <<eq-1>>.

@mojavelinux mojavelinux added this to the support milestone Dec 25, 2019
@mojavelinux mojavelinux self-assigned this Dec 25, 2019
@mojavelinux
Copy link
Member

@siddjain
Copy link
Author

siddjain commented Dec 25, 2019 via email

@mojavelinux
Copy link
Member

The equation number should be appearing on the right. Here's the output I see:

screenshot

MathJax isn't aware of the chapters in the AsciiDoc document, so it's going to number the equations straight. To change that, you'd need to load an extension to MathJax that changes how the number is done. So no, not without a customization.

@siddjain
Copy link
Author

@mojavelinux, is the output you have pasted the result of running asciidoctor-pdf. Below is my asciidoc

:stem: latexmath
:eqnums:
:chapter: 1

[latexmath#formula, id="formula", reftext={chapter}.{counter:equation}]
++++
\begin{equation}
y = x^2
\end{equation}
++++

See <<formula>>

and when I process it through asciidoctor-pdf I get

image

The equation number appears on the left. I am using the docker image asciidoctor/docker-asciidoctor

asciidoctor/docker-asciidoctor                                                                         latest                        50b355abeb79        3 months ago        419MB

Any chance you could add ability for user to customize the equation number so that it can be numbered 7.1 for example. 7 is the chapter number.

@siddjain
Copy link
Author

adding a note to help readers later on. the left-side equation numbering got fixed when i upgraded to asciidoctor-pdf v1.5.3. earlier i was using beta7 version of 1.5.0

@RoxvilleRooster
Copy link

RoxvilleRooster commented Jun 21, 2021

I am testing equation references for Antora as described by @mojavelinux in #3518 (comment)

The linking aspects work fine in Antora but the key piece, the equation reference number, is not rendered in the Antora output.
The equation reference number is rendered well in the Asciidoctor HTML (printed on the right)

[latexmath#eq1_sft_ca_cap,reftext=Equation 1]
++++
\begin{equation}
{MtM}_{L} = Sign \times {FX}_{currency\rightarrow DomesticCurrency} \times \left\{ \begin{matrix}
{quantity \times security\Pr ice,} & {L \in L_{SECURITY}^{NS}} \\
{cashMtM,} & {L \in L_{CASH}^{NS}} \\
\end{matrix} \right.
\end{equation}
++++

and the link to this is

where _MtM~L~_ is defined in <<#eq1_sft_ca_cap>> ...

Here is a link to the issue I created for Antora
https://gitlab.com/antora/antora/-/issues/783

@mojavelinux
Copy link
Member

Please direct Antora questions to the Antora community chat at https://antora.zulipchat.com. The Asciidoctor issue tracker is not the appropriate place to be discussing Antora behavior.

@vishalkrsinha
Copy link

Equation numbering is handled by MathJax itself. It can be enabled by setting the eqnums document attribute. Other equations can then refer to these numbers.

You can also give the block and ID so you can reference it from AsciiDoc content.

:stem: latexmath
:eqnums:

[latexmath#eq-1,reftext=Equation 1]
++++
\begin{equation}
y = x^2
\end{equation}
++++

see <<eq-1>>.

Thanks for the solution. The example works fine for cross-referencing the equation in 'asciidoctor-pdf'.

One query though, we see the 'reftext=Equation 1' here is the static test we are using to link. Instead of using static reftext, can we use dynamic equation number to link something like 'reftext={dynamic equation number}'?

PS: I have set ':eqnums: AMS' for automatic equation number generation.

@plevold
Copy link

plevold commented Nov 8, 2021

@vishalkrsinha I'm currently using the following template with a counter to automatically generate equation numbers:

[stem#eq-<some label>,reftext=Equation ({counter:eqs})]
++++
<Equation here>
++++

Complete example:

= My Report
:sectnums:
:stem: latexmath
:eqnums: all

== Theory

[stem#eq-ode,reftext=Equation ({counter:eqs})]
++++
\mathbf{M}(t)\mathbf{\ddot{q}}(t) + \mathbf{C}(t)\mathbf{\dot{q}}(t) + \mathbf{K}(t)\mathbf{q}(t)
= \mathbf{F}(\mathbf{q}, \mathbf{\dot{q}}, t)
++++

See <<eq-ode>> for definition.

[stem#eq-emc,reftext=Equation ({counter:eqs})]
++++
E = mc^2
++++

<<eq-emc>> is another equation.

This should give you something like this:
image

You can modify the reftext to get the format you wish like Eq. ({counter:eqs}) for example.

There's at least two downsides to this:

  • Section numbering (for example Equation (1.2)) is not possible afaik.
  • If you later decide to change the reftext format you have to change every single equation in your document. Maybe someone with better asciidoctor knowlege than me can figure out a way to define the format once in the document header...

@wimcnice
Copy link

Equation numbering works nice, thank you. But how can I align the equation to the left in place of center? Thanks.

@jesustorresdev
Copy link

jesustorresdev commented Jun 27, 2023

I don't know why, but I can't see the equation number, neither to the right nor to the left.

@mojavelinux
Copy link
Member

Please direct usage questions to the project chat at https://chat.asciidoctor.org. See you there!

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

8 participants
@mojavelinux @jesustorresdev @siddjain @plevold @RoxvilleRooster @wimcnice @vishalkrsinha and others