sphinx-doc/sphinx

Multiple maths equations are right-aligned by default

Open

#3,785 opened on May 22, 2017

View on GitHub
 (15 comments) (0 reactions) (0 assignees)Python (5,625 stars) (1,985 forks)batch import
extensions:mathematicshelp wantedtype:proposal

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:

screenshot from 2017-05-22 16-44-37

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 split inside gather.

  • With #2254, we changed it to be split inside align*. This is useful for if you want to align equations using &.

  • With #2370 and 39396a4 and 3206ccb, we changed it to split in equation* (for single equations) or aligned inside align* (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*} (or equation).
  • 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*} (or align).

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

Contributor guide