latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.94k stars 267 forks source link

amsmath \resetMathstrut@ is incompatible with a math active left parenthesis #210

Closed jfbu closed 1 week ago

jfbu commented 5 years ago

Brief outline of the bug

Making the ( mathematically active breaks amsmath \resetMathstrut@.

Minimal example showing the bug

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}

\usepackage{amsmath}

\mathchardef\leftparen\mathcode`(
\mathcode`( "8000
{\catcode`(\active\gdef({\leftparen_{<whatever>}}}
\begin{document}
$($
\end{document}

Commenting out the \usepackage{amsmath} line, the document compiles.

Log file (required) and possibly PDF file

pdflatex --halt-on-error mathstrutactive

mathstrutactive.log

! Bad mathchar (32768).
<to be read again> 
                   \relax 
l.10 $(
       $ 

Additional context

My package mathastext overrides \resetMathstrut@ with its own version to work around that problem. The replacement (which dates back to 2013) is found in its macro \mst@nonlettersobeymathxx. Here copied pasted from mathastext.pdf with code line numbers (top of page 60)

288    \def\resetMathstrut@{%
289     \setbox\z@\hbox{\the\textfont\symmtoperatorfont\char40
290                  \the\textfont\symoperators\char40}%
291     \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@}%

and is probably a bit too naive. Some comments are found on page 56 of mathastext.pdf 1.3v:

The replacement macro avoids a potentially math active (. It assumes that there is still some
appropriate glyph in slot 40 of operators and it sets the height and depth of \Mathstrutbox@
to be large enough to accomodate both this glyph and the one from the mathastext font (both
in the current math version). If option noparenthesis was used, we leave everything untouched.
In 1.3a, 2013/09/04, the modification is done only at the time of \MTnonlettersobeymathxx.

I remember back in 2012/2013 I considered it only a quick patch, with not a lot of thinking going into my replacement. By default mathastext does not do the replacement, it is done if user executes \MTnonlettersobeymathxx (one of the effect being that parenthesis now react to the math alphabet commands).

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity.

josephwright commented 1 week ago

In general, setting chars math active is not supported by LaTeX: there is a pre-defined set of chars that are covered, and that is all we support. If you want to use others, you have to take steps to sort issues.