The following code, inspired by this answer, procudes an undesired result when the french option of babel is selected. However, it works fine with the english option!
Can anyone explain this to me, and find a way so that it works well with the french option?
\documentclass[12pt]{article}
\usepackage[french]{babel}
%\usepackage[english]{babel}
\usepackage{amsmath}
\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\def\matr#1{\def\matrL{}\matrA#1\end}
\def\matrA#1{\ifx\end#1\begin{pmatrix}\matrL\end{pmatrix}\else
\ifx,#1\addto\matrL{&}\else
\ifx;#1\addto\matrL{\cr}\else
\addto\matrL{#1}\fi\fi
\expandafter\matrA\fi
}
\begin{document}
$\matr{ a, b ; c, d }$
\end{document}
With the french option, I get this:
, while this should give me this:
, as it does with english option.



[shorthands=off]to the babel invocation --- wild guess about some active character – Rmano Mar 10 '21 at 15:36\begin{document}. I'm not sure there is a predefined way to deactivate the semi-colon. – campa Mar 10 '21 at 15:37: ; ! ?are made active. Surely they should revert to the original meaning in math mode? (edit: I see the manual says that you have to use{,}in math mode. Quite invasive...) – Rmano Mar 10 '21 at 15:40\mathpunct, which is fine if you don't use it as decimal separator. Enclosing it in braces is addressed also in the TeXbook. – campa Mar 10 '21 at 16:03\addtois already defined bybabeland it's not good policy to redefine it. Avoid\def, generally speaking. – egreg Mar 10 '21 at 17:02