Multiple maths equations are right-aligned by default
#3,785 opened on May 22, 2017
Description
Problem
When I write multiple equations in a math directive, they are right-aligned by default.
Procedure to reproduce the problem
Proof of concept, full source rst, output PDF. Source rst:
Default behaviour:
.. math::
e^{i \pi} + 1 = 0
x = \frac{-b\pm \sqrt{b^2-4ac}}{2a}
Output:

I would like the maths to be centered, and I think right-aligning is a bad default to choose in this case.
History
-
In the past, equations used to be always right-aligned, with
splitinsidegather. -
With #2254, we changed it to be
splitinsidealign*. This is useful for if you want to align equations using&. -
With #2370 and 39396a4 and 3206ccb, we changed it to
splitinequation*(for single equations) oralignedinsidealign*(for multiple equations).The original issue #2370 mentioned right-alignment vs. centering. In the end, the applied fix was to add a negative space to nudge
aligned output slightly to the left. But I suspect that the original submitter meant the same problem as my current issue is for.
Cause
Sphinx chooses one of two setups for the maths.
- If there is a single equation, then we wrap the maths in
\begin{equation*}(orequation). - If there are multiple equations (as determined by the presence of an empty line), then we wrap the maths first in
\begin{aligned}and then in\begin{align*}(oralign).
The latter makes sense when the user has alignment characters & in the maths, but otherwise I don't see a reason to, because without alignment characters, the aligned environment will make everything right-aligned.
Proposal
I propose to add a third case:
- If there are multiple equations but no
&characters, then we wrap the equations in\begin{gather*}.
Environment info
- Sphinx version: 1.6.1