Multiple labels for multiple aligned equations in one math environment

已查看 11 次
跳至第一个未读帖子

sbiser

未读,
2020年4月24日 10:50:142020/4/24
收件人 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

未读,
2020年4月28日 05:11:002020/4/28
收件人 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

未读,
2020年4月30日 13:00:242020/4/30
收件人 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:
>
回复全部
回复作者
转发
0 个新帖子