1

The language I use for certain files look much better if there is a small space \, after each inline equation, like this:

\(...\)   % BAD  spacing
\(...\,\) % GOOD spacing

But it's not quite productive to add the \, to every inline math equation. So is there a way to make this a default setting, in the preamble maybe?

Paul Kim
  • 1,078

2 Answers2

5

I'm not sure what benefit you get from adding space after each formula.

Anyway, the space should be indeed added after the formula, not before it ends.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\let\)\relax % undefine \)
\DeclareRobustCommand\){%
  \relax
  \ifmmode
    \ifinner
      $\thinspace % add a kern after the formula
    \else
      \@badmath
    \fi
  \else
    \@badmath
  \fi
}
\makeatother

\begin{document}

$a+b$ xyz % for comparison

\(a+b\) xyz

\bigskip

\setlength{\fboxsep}{0pt}% tight to the box

% for comparison
\fbox{\parbox{4.8cm}{This line ends with math $a+b\,$ and text follows}}

\medskip

\fbox{\parbox{4.8cm}{This line ends with math \(a+b\) and text follows}}

\end{document}

The first two lines show that the space is actually added when the \(...\) syntax is added. The two boxes show that if one adds it before closing the formula, the space is not removed at line breaks.

enter image description here

egreg
  • 1,121,712
1

I cannot see the advantage of such setting. However, maybe this helps

\documentclass{scrartcl}
\renewcommand\){\,$}
\begin{document}

\noindent
$ y=f(x) $x \\
$ y=f(x) $ x \\
\( y=f(x) \)x

\end{document}

enter image description here

  • 2
    \) does much more than $. – egreg Nov 29 '18 at 10:09
  • 1
    sure, which is not important if he/she uses it only for something like above. If not, then he/she can simply overwrite the original definition: \DeclareRobustCommand\){\relax\ifmmode\ifinner\,$\else\@badmath\fi\else \@badmath\fi} –  Nov 29 '18 at 10:56