asciidoctor icon indicating copy to clipboard operation
asciidoctor copied to clipboard

Add support for equation numbering and cross-referencing

Open siddjain opened this issue 5 years ago • 10 comments

It seems asciidoc has no support for equation numbering and cross-referencing? please see these threads: https://github.com/asciidoctor/asciidoctor-mathematical/issues/37#issuecomment-568772905 could support for this be added please?

siddjain avatar Dec 24 '19 19:12 siddjain

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 avatar Dec 25 '19 00:12 mojavelinux

See https://docs.mathjax.org/en/v2.7-latest/tex.html#automatic-equation-numbering for more info.

mojavelinux avatar Dec 25 '19 00:12 mojavelinux

Thanks. Much obliged. This almost works for me except for 2 things:

  1. The equation number appears on the left of the equation whereas standard practice is to have the label on the right
  2. I would like equation numbers to be prefixed by the chapter number. Right now my equations are numbered 1, 2, 3 and so on. I would like them to be numbered 3.1, 3.2, 3.3 and so on in chapter 3

Is there any way to fix above 2 issues?


From: Dan Allen [email protected] Sent: Tuesday, December 24, 2019 4:15 PM To: asciidoctor/asciidoctor [email protected] Cc: siddjain [email protected]; Author [email protected] Subject: Re: [asciidoctor/asciidoctor] Add support for equation numbering and cross-referencing (#3518)

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 <>.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fasciidoctor%2Fasciidoctor%2Fissues%2F3518%3Femail_source%3Dnotifications%26email_token%3DAAFZEMLQ3YJW6UVDWKNXVC3Q2KQZDA5CNFSM4J7ANN2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHTWNFA%23issuecomment-568813204&data=02%7C01%7C%7C0c235ad2fa5a400e263608d788cf83b6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637128297154263001&sdata=OnU4mdRIiSTAhF4lD07fHvEpp3yUwGzclvvM%2BhcJCls%3D&reserved=0, or unsubscribehttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAFZEMKZ6X5E6TO44X4MHX3Q2KQZDANCNFSM4J7ANN2A&data=02%7C01%7C%7C0c235ad2fa5a400e263608d788cf83b6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637128297154263001&sdata=IjtfbLzTxRcqsrPGOS0yKNU2BH7Si%2F1wkXRVTMKRfw8%3D&reserved=0.

siddjain avatar Dec 25 '19 00:12 siddjain

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.

mojavelinux avatar Dec 25 '19 00:12 mojavelinux

@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 avatar Feb 27 '20 01:02 siddjain

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

siddjain avatar Oct 23 '20 18:10 siddjain

I am testing equation references for Antora as described by @mojavelinux in https://github.com/asciidoctor/asciidoctor/issues/3518#issuecomment-568813204

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

RoxvilleRooster avatar Jun 21 '21 20:06 RoxvilleRooster

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.

mojavelinux avatar Jun 21 '21 21:06 mojavelinux

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.

vishalkrsinha avatar Aug 30 '21 13:08 vishalkrsinha

@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...

plevold avatar Nov 08 '21 08:11 plevold

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

wimcnice avatar Apr 16 '23 14:04 wimcnice

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

jesustorresdev avatar Jun 27 '23 11:06 jesustorresdev

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

mojavelinux avatar Jun 27 '23 20:06 mojavelinux