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

Use "align" environment to wrap math equations instead of "gather" #2254

Merged
merged 1 commit into from
Jan 31, 2016

Conversation

xuhdev
Copy link
Contributor

@xuhdev xuhdev commented Jan 20, 2016

Using align brings the benefit when multiple math equations are in one math directive, alignment is provided. We also use "aligned" to wrap the equations since in this way all the equations will be given only one label/tag, while previously only the first equation is labeled.

if not ret:
return ''
return '\\begin{gather}\n' + '\\\\'.join(ret) + '\n\\end{gather}'
if label is not None or numbering:
env_begin = r'\begin{align}\label{%s}' % label
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\label{None} will be generated here if label is None and numbering(math_number_all) is True.

@tk0miya
Copy link
Member

tk0miya commented Jan 21, 2016

Now, master branch has broken.
Multiple labels are assigned to multiple equations if definitions are separated by blank line.

Input:

.. math::
   :label: test

     E &= mc^2

   x^2 &= y^2 + z^2

In stable:
stable

In master:
before

This PR:
after

This PR fixes the problem same time. it looks good.

But I don't know about the difference between gather and align environments.
Can anyone review this?

Using align brings the benefit when multiple math equations are in one
math directive, alignment is provided. We also use "aligned" to wrap the
equations since in this way all the equations will be given only one
label/tag, while previously only the first equation is labeled.
@xuhdev
Copy link
Contributor Author

xuhdev commented Jan 21, 2016

@tk0miya I've updated the PR so None label would not be generated.

gather is for the case where no alignment is desired among the equations, align is for the case where alignment is desired (section 3.5 and 3.6 in the doc). I recommend using align; the only case I can think of where gather behaves different with align is that, when the two equations occupies multiple lines and each of them has their own internal alignment, which however do not share the same alignment with each other. In this case, in the context of Sphinx, we can just ask the user to write the equations into two different math directives.

@xuhdev
Copy link
Contributor Author

xuhdev commented Jan 21, 2016

For example, the following LaTeX source:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

Align:

\begin{align}
  \begin{aligned}
\begin{split}a &= b + c\\ &= d + e\end{split}
\\\begin{split}x + y &= z \\ &= u \end{split}
\end{aligned}
\end{align}

Gather:

\begin{gather}
  \begin{aligned}
\begin{split}a &= b + c\\ &= d + e\end{split}
\\\begin{split}x + y &= z \\ &= u \end{split}
\end{aligned}
\end{gather}

\end{document}

You can view the difference here. It also makes sense semantically when multi equations grouped together in a math directive in Sphinx are aligned.

@tk0miya
Copy link
Member

tk0miya commented Jan 21, 2016

Thank you for the thorough explanation. I understand clearly.
LGTM!

@tk0miya
Copy link
Member

tk0miya commented Jan 21, 2016

BTW, I found this article::
http://tex.stackexchange.com/questions/321/align-vs-equation

This says using align is bad idea and it should use equation by default.
How about the combination of equation and aligned?
I want to hear your opinion before merge this.

@birkenfeld
Copy link
Member

Also (without having taken a closer look) keep backwards compatibility in mind please.

@xuhdev
Copy link
Contributor Author

xuhdev commented Jan 21, 2016

@tk0miya Yes, equation seems in general space better for single equations. We can use equation for single equations, since it's made for single equations (see the doc section 3.2). Do you want me to make the change?

Actually I think that gather (which we used to use) should space the same as align for single equations, because they are both made for multiple equations. But you guys can decide whether single equations should space "differently" (using equation for a better spacing) than before.

@tk0miya
Copy link
Member

tk0miya commented Jan 24, 2016

Thank you for comment.
Ok, I don't want to make changes between single equation and multiple ones.

Finally, I vote +1 to this again.

@xuhdev
Copy link
Contributor Author

xuhdev commented Jan 29, 2016

shall we merge this? :)

@tk0miya
Copy link
Member

tk0miya commented Jan 29, 2016

no objections? I will merge this in Sunday.

@xuhdev
Copy link
Contributor Author

xuhdev commented Jan 29, 2016

Also I believe the tag latex does not belong here...

@tk0miya
Copy link
Member

tk0miya commented Jan 30, 2016

Oops. You're right.

tk0miya added a commit that referenced this pull request Jan 31, 2016
Use "align" environment to wrap math equations instead of "gather"
@tk0miya tk0miya merged commit ccd945b into sphinx-doc:master Jan 31, 2016
@tk0miya
Copy link
Member

tk0miya commented Jan 31, 2016

Thank you always!

xuhdev added a commit to xuhdev/sphinx that referenced this pull request Feb 19, 2016
This is a follow-up commit of sphinx-doc#2254, which supported alignment of
multiple equations for imgmath and LaTeX output.
xuhdev added a commit to xuhdev/sphinx that referenced this pull request Feb 19, 2016
This is a follow-up commit of sphinx-doc#2254, which supported alignment of
multiple equations for imgmath and LaTeX output.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants