2

How to have a switch to turn on/off the raising of punctuating commas inside the math mode so that (when the switch is true) they are typeset by \newcommand{\CommaPunct}{\mathpunct{\raisebox{0.5ex}{,}}} as suggested by this answer?

enter image description here

\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 Answer 1

5

enter image description here

\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}
3
  • I noticed that your beautiful punctuating comma doesn't have the same font as the other commas in my original document. You can find here ibb.co/LnDL86f that your provided comma (in red) looks different from the default comma (in blue).
    – Diaa
    Dec 20, 2023 at 11:38
  • Here are my main document font specs in case you are interested: \usepackage[tuenc,no-math]{fontspec} \usepackage[bold-style=TeX,math-style=french]{unicode-math} \setmainfont[ Ligatures={NoRequired, NoCommon, NoContextual} ]{Latin Modern Roman} \setmathfont{Latin Modern Math}[version=LM] \setmathfont{TeX Gyre Pagella Math}[version=TG] \setmathfont[math-style=ISO]{Cambria Math}`
    – Diaa
    Dec 20, 2023 at 11:40
  • @Diaa I used the fonts you used in the question. if you want the math comma use \raisebox{0.5ex}{$\commaorig$} Dec 20, 2023 at 11:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .