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

Incorrect alignment with \prescript #28

Open
quark67 opened this issue Sep 3, 2021 · 2 comments
Open

Incorrect alignment with \prescript #28

quark67 opened this issue Sep 3, 2021 · 2 comments

Comments

@quark67
Copy link

quark67 commented Sep 3, 2021

The bug where described here by other user at 2013: https://tex.stackexchange.com/questions/109694/the-prescript-command-from-the-mathtools-package-gives-incorrect-alignment

The code (taken from the previous site):

\documentclass{article}
\usepackage{amsmath,mathtools}
\begin{document}
$\prescript{14}{2}{\mathbf{C}}^{5+}_{2}$
\end{document}

produce this (red line added to make the difference clearer):

But I found also a bug for the sup argument.

Here is a code:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
$\prescript{14}{2}{\mathbf{C}}^{4+}_{2}$
\end{document}

The result (compare the left and right "4": at left, the "4" is slightly too high):
image

More interesting: if we drop the "+", the sub part (the "2") are correctly aligned, but the left "4" is too hight (or the right "4" too low, but the position of the right part is not controlled by mathtools).

The code:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
$\prescript{14}{2}{\mathbf{C}}^{4}_{2}$
\end{document}

The result:
image

@eg9
Copy link

eg9 commented Sep 3, 2021

This would need some refinement, but it should give the idea

\documentclass{article}
\usepackage{amsmath}

\NewDocumentCommand{\prescript}{mmme{^_}}{%
  \vphantom{#3}% the base
  ^{\prescriptalign{{#1}{#4}{#2}{#5}}}% the superscript
  _{\prescriptalign{{#2}{#5}{#1}{#4}}}%  the subscript
  \kern-\scriptspace
  #3% the base
  ^{\IfValueT{#4}{#4}\vphantom{#1}}% the superscript
  _{\IfValueT{#5}{#5}\vphantom{#2}}% the subscript
}

\NewDocumentCommand{\prescriptalign}{m}{%
  \mathpalette\prescriptalignaux{#1}%
}
\NewDocumentCommand{\prescriptalignaux}{mm}{%
  \prescriptalignauxi{#1}#2%
}
\ExplSyntaxOn
\NewDocumentCommand{\prescriptalignauxi}{mmmmm}
 {
  \hbox_set:Nn \l_tmpa_box { \mathsurround0pt $#1#2\IfValueT{#3}{\vphantom{#3}}$ }
  \hbox_set:Nn \l_tmpb_box { \mathsurround0pt $#1#4\IfValueT{#5}{\vphantom{#5}}$ }
  \makebox
    [\dim_max:nn { \box_wd:N \l_tmpa_box } { \box_wd:N \l_tmpb_box } ]
    [r]
    { \box_use:N \l_tmpa_box }
 }
\ExplSyntaxOff

\def\baserule{\makebox[0pt]{\vrule height 0pt depth 0.1pt width 10cm}}

\begin{document}

\begin{gather*}
\prescript{14\baserule}{2\baserule}{\mathbf{C}}^{5+}_{2}
\\
\prescript{14\baserule}{2\baserule}{\mathbf{C}}^{5}_{2}
\\
\prescript{14\baserule}{2\baserule}{\mathbf{C}}_{2}
\\
\prescript{14\baserule}{2\baserule}{\mathbf{C}}^{5+}
\end{gather*}

\end{document}

image

@daleif
Copy link
Collaborator

daleif commented Sep 6, 2021

But is it now considered save to start using latex3 syntax in mathtools? It would be nice, but we have no idea how many people are updating these by hand. I all for drawing a line at some point and declaring that from now on we expect users to use an kernel newer than X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants