Text FormattingWhite Space outside Parentheses

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
niles
Posts: 92
Joined: Mon Dec 01, 2008 9:35 pm

White Space outside Parentheses

Post by niles »

Hi

Please see my MWE:

Code: Select all

\documentclass[a4paper]{article}
\usepackage{amsmath} 
\usepackage[sc]{mathpazo}

\begin{document}
I have a function  
\begin{align}
f(x) = \left(\sqrt{ \frac{x}{20}} \right),
\end{align}
which is good.
\end{document}
What bothers me is the white space between the last paranthesis and the comma. Is there a clever way to remove it, or do I have to resort to \! every time?

Best,
Niles.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

White Space outside Parentheses

Post by Stefan Kottwitz »

Hi Niles,

very good MWE! Nice for testing.

This spacing problem with \left ... \right could be fixed by
  • enclosing the expression in braces:

    Code: Select all

    f(x) = {\left(\sqrt{ \frac{x}{20}} \right)},
  • inserting negative space before the comma as quick fix:

    Code: Select all

    f(x) = \left(\sqrt{ \frac{x}{20}} \right)\!, 
  • or by using \biggl( and \biggr) instead.
The first suggestion seems to be the cleanest to me. The enclosed expression would be treated like ordinary math regarding spacing, resulting in less space after it. It's also logical, as the comma is not part of the expression.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

White Space outside Parentheses

Post by localghost »

The following redefinition of the \left and \right command pair at first sight seems to have the desired effect.

Code: Select all

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[sc]{mathpazo}

\let\Right\right
\let\Left\left
\makeatletter
\def\right#1{\Right#1\@ifnextchar){\!\!\right}{}}
\def\left#1{\Left#1\@ifnextchar({\!\!\left}{}}
\makeatother

\begin{document}
  I have a function
  \begin{align}
    f(x) &= \left(\sqrt{\frac{x}{20}}\right),
  \end{align}
  which is good.
\end{document}
But it becomes ugly when there are other characters than e. g. punctuation marks.

Code: Select all

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[sc]{mathpazo}

\let\Right\right
\let\Left\left
\makeatletter
\def\right#1{\@ifnextchar){\Right}{}#1\!\!}
\def\left#1{\@ifnextchar({\!\!\Left}{}#1}
\makeatother

\begin{document}
  I have a function
  \begin{align}
    x \left(\sqrt{\frac{x}{20}}\right) y
  \end{align}
  which is good.
\end{document}
So I would use this with caution. You either have to balance superfluous space with negative space or missing space with additional space. This could end up in a vicious circle. And so the proposal of Stefan might be better.


Thorsten
niles
Posts: 92
Joined: Mon Dec 01, 2008 9:35 pm

Re: White Space outside Parentheses

Post by niles »

Thanks for the help to both of you. I'll try with Stefan's first suggestion.

Best wishes,
Niles.
Post Reply