This was brought to my attention by our colleague, Lover of Structure, but since it affects my scalerel package (which began using the mathstyle package to detect the current math style, as of version 1.4) it is now my problem too.
I even think I know why it happens, and I have a workaround, but I was hoping for a more satisfying solution. Here is the MWE:
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathstyle}
\newcommand*{\testcmd}{\(M_{\texttt{k}}\)}
\begin{document}
\(M_{\texttt{k}}\) \par
\testcmd
\end{document}
and here is the result.
In it you see two different sized subscripts (call them small and large, respectively), which would not seem obvious from code. Investigating, I found that:
1) with neither package loaded, both subscripts are large
2) with only amsmath loaded, both subscripts are small
3) with only mathstyle loaded, both subscripts are large
4) with both packages loaded (as in my MWE), the first is small, the second is large
5) with both packages loaded, if the definition of \testcmd
is moved after \begin{document}
, both subscripts are small (this is what I call the WORKAROUND).
6) If I load mathstyle before amsmath, the code breaks, saying \dfrac
is already defined.
"Aha," I say to myself. It would appear that one of these packages is using a "feature" I've seen mentioned wherein certain commands are loaded just prior to \begin{document}
. But this would seem to put a significant constraint on users of these two packages (or users of amsmath and scalerel); namely, one would be forbidden from defining math command shortcuts in their document preamble.
So, my questions are these: am I understanding the nature of the problem properly? Is there a fix that would still allow users to define math shortcuts in their preamble, while using the package combination?
mathstyle
(texdoc mathstyle
) it says "If you want to use this package withamsmath
, it is importantmathstyle
is loaded afteramsmath
." some reasons for this are given later in the documentation. (the author ofmathstyle
isn't currently active with latex as far as i know.)\usepackage{mathtools}
loads the full mh bundle and amsmath after which example looks fine for me.amsmath
withmathtools
in my MWE left the behavior unchanged.\mathchoice
in your package rather than use mathstyle. TeX would have been better without mathchoice but it is what it is but redefining every command that makes a sub or superscript or fraction just to save yourself three boxing operations is a high price to pay and will make your package incompatible with other things and have weird load order constraints.