3

I have searched hard for the answer to this question but have not been able to find it. I'm typing an article and I have to write a lot of formulas, and for me it's more beautiful write f(x, y) than f(x,y). I'm tired of always writing a thin space \, after a comma in mathmode, and it's also confusing. Is there a way to automate this?

1
  • Welcome. // You can define useful macros via \newcommand and, for example, incorporate Davids suggestion there. View it as your individual shorthand notation. // See e.g. here: en.wikibooks.org/wiki/LaTeX/Macros#New_commands
    – MS-SPO
    Commented Feb 28, 2023 at 19:48

3 Answers 3

2

If you're willing to have more space after every comma in math mode.

\documentclass{article}

\AtBeginDocument{%
  \mathchardef\stdcomma=\mathcode`,
  \mathcode`,="8000
}
\begingroup\lccode`~=`, \lowercase{\endgroup\def~}{\stdcomma\,}

\begin{document}

$f(x,y)$

$a,b,c$

\end{document}

enter image description here

If you only want the space when specifying variables, you can use the same method as the package icomma, but this requires discipline in input: if a comma is followed by a space (in math mode), a thin space is added.

\documentclass{article}

\makeatletter
\AtBeginDocument{%
  \mathchardef\stdcomma=\mathcode`,
  \mathcode`,="8000
}
\begingroup\lccode`~=`, \lowercase{\endgroup\def~}{%
  \futurelet\@let@token\spaced@comma
}
\newcommand{\spaced@comma}{%
  \stdcomma
  \ifx\@let@token\@sptoken\,\fi
}
\makeatother

\begin{document}

$f(x, y)$ % added space

$f(x,y)$ % compare with the standard

$a,b,c$ % no space is added

\end{document}

enter image description here

I'd avoid setting \thinmuskip to a larger value. Here's why.

\documentclass{article}

\thinmuskip=6mu

\begin{document}

$f(x,y)=\sin x-\sin y$ % with the new setting

\thinmuskip=3mu

$f(x,y)=\sin x-\sin y$ % with the standard setting

\end{document}

enter image description here

As you see, \thinmuskip is not only used after commas, but in several other places, which would be affected by the same enlarged space.

1
  • Indeed, I didn't pay attention immediately, thanks. I have tried your method and it works great. Thank you. Commented Mar 1, 2023 at 6:49
5

, is \mathpunct so has a thin space by default unless you have changed the settings. Compare with {,}

enter image description here

\documentclass{article}

\begin{document}

$f(x, y)$

$f(x{,} y)$

\end{document}
4
  • 1
    Thanks a lot, but people want from me a little bit big space \documentclass[10pt,a4paper]{book} \begin{document} $f(x,\, y)$%like this $f(x, y)$ $f(x,y)$ $f(x{,}y)$ \end{document} Commented Feb 28, 2023 at 19:57
  • @FatimaBogatyreva you can increase all thin spaces, \thinmuskip=5mu (but would not) Commented Feb 28, 2023 at 20:22
  • It works, thanks a lot. I rummaged through the entire Internet and did not find it and suffered from multiple typing \, in all my formulas. Commented Feb 28, 2023 at 20:32
  • @FatimaBogatyreva are you_sure_you want that? You should change \medmuskip and \thickmuskip to be larger than \thinmuskip if you do. I would advise against it. Commented Feb 28, 2023 at 21:05
2

You may also define your own command with the space you want:

\documentclass{article}

\newcommand{\fxy}{$f(x,\,y)$}

\begin{document}
    \fxy, compared to
    

    $f(x,y)$
    
\end{document}

enter image description here

2
  • 1
    But i need it in many place, i can't put it all with newcommand. I'm searching for method for redefining comma like comma+\, Commented Feb 28, 2023 at 20:03
  • What do you mean? When you want to type f(x, y) you type \fxy and you get it with the space you defined in \newcommand. No need for \newcommand than just once.
    – miltos
    Commented Feb 28, 2023 at 20:18

You must log in to answer this question.

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