asciidoctor
asciidoctor copied to clipboard
Add support for equation numbering and cross-referencing
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?
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>>.
See https://docs.mathjax.org/en/v2.7-latest/tex.html#automatic-equation-numbering for more info.
Thanks. Much obliged. This almost works for me except for 2 things:
- The equation number appears on the left of the equation whereas standard practice is to have the label on the right
- 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.
The equation number should be appearing on the right. Here's the output I see:
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, 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
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.
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
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
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.
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 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:
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...
Equation numbering works nice, thank you. But how can I align the equation to the left in place of center? Thanks.
I don't know why, but I can't see the equation number, neither to the right nor to the left.
Please direct usage questions to the project chat at https://chat.asciidoctor.org. See you there!