在数学模式中自动增加标点逗号

在数学模式中自动增加标点逗号

如何有一个开关来打开/关闭数学模式中的标点逗号的提升,以便(当开关为真时)它们按照\newcommand{\CommaPunct}{\mathpunct{\raisebox{0.5ex}{,}}}建议进行排版这个答案

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath}

\newcommand{\CommaPunct}{\mathpunct{\raisebox{0.5ex}{,}}}

\begin{document}
    \noindent
    
    \verb|\mathpunct|: $\frac{1}{2} \CommaPunct \frac{3}{4} \CommaPunct \dfrac{1}{2} \CommaPunct \dfrac{3}{4}$\\
    
    Here, after setting the automatic raise to true, the commas should be printed as above\\
    
    $\frac{1}{2} , \frac{3}{4} , \dfrac{1}{2} , \dfrac{3}{4}$   
\end{document}

答案1

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,parskip}

\newcommand{\CommaPunct}{\mathpunct{\raisebox{0.5ex}{,}}}

\mathchardef\commaorig\mathcode`,

\mathcode`,="8000

{\catcode`,\active
\protected\gdef,{\ifraisedcomma\CommaPunct\else\commaorig\fi}
}
\newif\ifraisedcomma

\begin{document}
    \noindent % a strange way of adding vertical space
    
    \verb|\mathpunct|: $\frac{1}{2} \CommaPunct \frac{3}{4} \CommaPunct \dfrac{1}{2} \CommaPunct \dfrac{3}{4}$% no!!!!\\
    
    Here, after setting the automatic raise to true, the commas should be printed as above% never end paragraph with \\
    
    $\frac{1}{2} , \frac{3}{4} , \dfrac{1}{2} , \dfrac{3}{4}$   

\raisedcommatrue

    $\frac{1}{2} , \frac{3}{4} , \dfrac{1}{2} , \dfrac{3}{4}$   
\end{document}

相关内容