Multiple labels for multiple aligned equations in one math environment

11 views
Skip to first unread message

sbiser

unread,
Apr 24, 2020, 10:50:14 AM4/24/20
to sphinx-users
Hey together,

I'm working on some code documentation which I need both as HTML as well as PDF. Is there any way to achieve the following graphical output not
only as PDF but as HTML as well?

For latex output I've used the following code:

.. math::
      :label: testpdf
      :nowrap:

      \begin{align}
         2x^2 + 3(x-1)(x-2)   & = 2x^2 + 3(x^2-3x+2) \\ \nonumber
                              & = 2x^2 + 3x^2 - 9x + 6 \\ 
                              & = 5x^2 - 9x + 6 
      \end{align}

But I couldn't manage to get the same rendering in HTML (either only one label number, or no at all...)

Thanks for any suggestions.

Stefan
Multilabel.PNG

Matt from Documatt

unread,
Apr 28, 2020, 5:11:00 AM4/28/20
to sphinx...@googlegroups.com
Hello Stefan,
I'm not good at typesetting math, but is your problem just that the numbers "(2.8)" and "(2.9)" on the right are not rendered in HTML? Or you can't render math in HTML at all?

For example, if I reuse your snippet in my project, it looks like this:

image.png

The only what I did differently in my conf.py was adding "'sphinx.ext.mathjax'" to "extensions" list.

Matt



--
You received this message because you are subscribed to the Google Groups "sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/e1f8f0ac-0d30-4e45-a342-d332499a4370%40googlegroups.com.

Matthias Geier

unread,
Apr 30, 2020, 1:00:24 PM4/30/20
to sphinx...@googlegroups.com
Hi Stefan.

AFAIK, this is not possible with Sphinx's :label: option, because this
always applies to the whole equation, even if it has multiple lines.

You might be able to split your multiple lines into separate "math"
directives, but I guess then it'll be hard to get the vertical
alignment right.

But if you are willing to use MathJax's labelling mechanism, it should
work like this:

.. math::
:nowrap:

\begin{align}
2x^2 + 3(x-1)(x-2) & = 2x^2 + 3(x^2-3x+2) \\ \nonumber
& = 2x^2 + 3x^2 - 9x + 6 \\
& = 5x^2 - 9x + 6
\label{testpdf}
\end{align}


In addition, you'll need to activate the MathJax labelling:

mathjax_config = {
'TeX': {'equationNumbers': {'autoNumber': 'AMS', 'useLabelIds': True}},
}

Also, the referencing with :eq: will not work anymore, instead you'll
have to use :math:`\ref{testpdf}`.

The big disadvantage of the whole thing is that MathJax references
only work within the same page.
And they don't take the section number into account. At least by
default, there might be a setting to fix this ...?

cheers,
Matthias

On Fri, Apr 24, 2020 at 4:50 PM sbiser <stefan....@gmail.com> wrote:
>
Reply all
Reply to author
Forward
0 new messages