latex3 / mathtools

Mathematical tools to use with amsmath
LaTeX Project Public License v1.3c
57 stars 7 forks source link

[Feature proposal] Left aligned stackrel #37

Open FelixBenning opened 2 years ago

FelixBenning commented 2 years ago

The following

\documentclass{article}
\usepackage{mathtools}
\begin{document}
    \begin{align}
        &\text{First Statement}\\
        &\implies \text{Second Statement}\\
        &\stackrel{\text{Explanation}}{\implies}\text{Third Statement}\\
        &\stackrel{\mathclap{\text{Explanation}}}{\implies} \text{Fourth Statement}
\end{align}
\end{document}

compiles to

misaligned implications

The solution I ended up building for this looks like this:

\newcommand*{\lstackrel}[2]{ %uses leftsides smashoperator thus ignoring overlap towards the left
        \mathrel{% makes the resulting stack a relation class (like =,<,>,...)
        \smashoperator[l]{\mathop{#2}^{#1}}
        }
}% use when aligning to the left

where \lstackrel{\text{explanation}}{=} aligns the equal sign towards the left.

zauguin commented 2 years ago

You can use the aligned-overset package for this which also ensures that it never overlaps with any potential content on the left:

\documentclass{article}
\usepackage{aligned-overset}
\begin{document}
\begin{align}
  &\text{First Statement}\\
  &\implies \text{Second Statement}\\
  \overset{\text{Explanation}}&{\implies} \text{Third Statement}\\
  \overset{\text{Explanation}}&{\implies} \text{Fourth Statement}
\end{align}
\end{document}
blefloch commented 2 years ago

Amazing! Could this relatively unknown package become part of mathtools, or perhaps be mentioned in the documentation?

zauguin commented 2 years ago

@blefloch Sorry, I missed your comment. I wouldn't mind merging it into mathtools if @daleif is happy with that.

daleif commented 2 years ago

I think the only problem about a merge is that even thoug it might seem so, mathtools is not written in expl3 (Morten made a self contained variant of it before expl3 was consolitated or something like that).

I'm currently unsure as to which direction to go with mathtools, either convert it into expl3 (which can cause issues for those who update manually), or leave it as it is now (I'm not particularly well versed in expl3 programming, or Mortens setup for that matter)