# Spacing setting of math mode

In typing of an article, I need to type many formulas like

$\left( a, b,c,d | e,f,g,h \right)$.


Since they are too tight, I should add space using \, command to obtain

$\left( a, \, b, \, c, \, d | e, \, f, \, g, \, h \right)$.


But my problem is there are too many of such formulas. Is there any command which changes the default spacing between characters in the math mode?

• $\begin{pmatrix}a&b&c&d&e&f&g&h\end{pmatrix}$ (don't forget to add \usepackage{amsmath} to the preamble) could be an option. – manooooh Jul 25 at 17:36

Assuming you don't need the thing in subscripts or superscripts, the easiest way is to exit from math mode, doubling the \thinmuskip, reentering math mode, typesetting the lists and go back.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\cls}[2]{%
\mathord{\mbox{%
\thinmuskip=2\thinmuskip
$(#1\mid#2)$%
}}%
}

\begin{document}

$( a, b,c,d \mid e,f,g,h)$

$(a,\, b,\, c,\, d \mid e,\, f,\, g,\, h)$

$\cls{a,b,c,d}{e,f,g,h}$

\end{document}


A different solution that allows for resizing the parentheses as usual for commands defined with \DeclarePairedDelimiter, see the examples. It also has a friendlier syntax.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\AtBeginDocument{\mathchardef\clscomma=\mathcode, }

\ExplSyntaxOn
\NewDocumentCommand{\cls}{som}
{
\group_begin:
\IfBooleanTF{#1}
{
\hs_cls_auto:n { #3 }
}
{
\hs_cls_manual:nn { #2 } { #3 }
}
\group_end:
}

\cs_new_protected:Nn \hs_cls_auto:n
{
\__hs_cls_activate_comma:
\__hs_cls_activate_bar:n { \;\middle\vert\; }
\left( #1 \right)
}

\cs_new_protected:Nn \hs_cls_manual:nn
{
\__hs_cls_activate_comma:
\__hs_cls_activate_bar:n { \__hs_cls_mid:n {#1} }
\__hs_cls_open:n {#1} #2 \__hs_cls_close:n {#1}
}

\cs_new_protected:Nn \__hs_cls_activate_comma:
{
\char_set_active_eq:nN { , } \__hs_cls_comma:
\mathcode,="8000 \scan_stop:
}

\cs_new_protected:Nn \__hs_cls_comma: { \clscomma\, }

\cs_new_protected:Nn \__hs_cls_activate_bar:n
{
\cs_set_protected:Nn \__hs_cls_bar: { #1 }
\char_set_active_eq:nN { | } \__hs_cls_bar:
\mathcode|="8000 \scan_stop:
}

\cs_new_protected:Nn \__hs_cls_open:n
{
\tl_if_novalue:nTF { #1 } { ( } { \mathopen{#1(} }
}
\cs_new_protected:Nn \__hs_cls_mid:n
{
\tl_if_novalue:nTF { #1 } { \mid } { \mathrel{#1\vert} }
}
\cs_new_protected:Nn \__hs_cls_close:n
{
\tl_if_novalue:nTF { #1 } { ) } { \mathclose{#1)} }
}
\ExplSyntaxOff

\begin{document}

$( a, b,c,d \mid e,f,g,h)$

$(a,\, b,\, c,\, d \mid e,\, f,\, g,\, h)$

$\cls{a,b,c,d|e,f,g,h}$

$\cls[\Big]{a,b,c,d|e,f,g,h}$

$\cls*{\dfrac{a}{2},b,c,d|e,f,g,h}$

\end{document}


• Thanks for your comments and answers but I need a more general command of \thinmuskip=2\thinmuskip – HS8637 Jul 25 at 18:00
• @HS8637 Why? A comma is followed by a thin space and \, inserts another thin space; the thin space has width \thinmuskip, so you get exactly the same output with my code and with ,\, all around. – egreg Jul 25 at 18:18
• Dear @egreg. You're right. But I need to change the setting of spacing, not an especial case. – HS8637 Jul 25 at 18:21
• @HS8637 Reread your question. Those are the formulas you mention. Changing in general the spacing after commas is not something I'd recommend. – egreg Jul 25 at 18:23
• @egreg Thanks for adding the LaTeX3 code, it is full of little interesting things! – frougon Jul 25 at 20:38

You can process each of the two lists (left and right) using etoolbox and a cunning delimiter trick:

\documentclass{article}

\usepackage{etoolbox}

% https://tex.stackexchange.com/a/89187/5764
\newcommand{\printlist}[2][,]{%
\def\itemdelim{\def\itemdelim{#1}}% Item delimiter delayed by one cycle
\renewcommand*{\do}[1]{\itemdelim##1}% How each item is processed
\docsvlist{#2}}% Process CSV list

\makeatletter
\def\@LandR#1|#2\relax{\def\leftlist{#1}\def\rightlist{#2}}%
\def\LandR#1{%
\@LandR#1\relax
\left( % Left bracket
\edef\x{\noexpand\printlist[,\,]{\leftlist}}\x
\,\middle|\, % Middle divider
\edef\x{\noexpand\printlist[,\,]{\rightlist}}\x
\right) % Right bracket
}
\makeatother

\begin{document}

$\left( a, b, c, d | e, f, g, h \right)$

$\LandR{a, b, c, d | e, f, g, h}$

\end{document}


Each list is printed using \printlist[,\,], which adds a small space \, after each delimiter ,. You can adjust the layout of the left/right bracket and middle divider.

If you wish to include larger constructions, you may need to use \noexpand, as in

\LandR{\noexpand\frac{a}{b}, c, d, e | f, g, h, \noexpand\frac{i}{j}}
`