# How do I get function argument parenthesis to position correctly?

I'm having trouble with the appearance of parentheses representing function arguments. They appear to far away from the function name.

For example the code

\left(1-f_{p}\left(l+1\right)\right)\overline{w}\left(l\right)f_{p}\left(l\right)\overline{N}\left(l\right)\hat{H}_{s}\left(l\right)


produces

in which the arguments seem to float midway between successive function names; but I'd prefer (and expect) something more like

which does a better job of attaching the arguments to the function names.

Is there something I can do to achieve the result I'm looking for?

FWIW, I've settled (for now) on

\bigl(1\!-\! f_{p}(l\!+\!1)\bigr)\;\overline{w}(l)\; f_{p}(l)\;\,\overline{\! N}(l)\;\hat{H}_{s}(l)


which produces

-
I'm using the tufte-book document class with LyX, but I see pretty much the same result regardless of what tools I experiment with. – raxacoricofallapatorius Feb 21 '12 at 0:08
One should never use negative spacing like \! for kerning aroung binary operations or relations; see this answer of mine for details. – Hendrik Vogt Jun 15 '12 at 17:56
@HendrikVogt: Was uncomfortable with that, but it seems the only way to fix the problem that Todd identified. What approach would you recommend? – raxacoricofallapatorius Jun 15 '12 at 18:34
Use something like \mkern1mu{+}\mkern1mu (and adjust the 1 to your needs). – Hendrik Vogt Jun 15 '12 at 18:37

Mostly the extra space comes from \left \right which you don't really need here, you could also declare your compound operators are operators

\documentclass{article}

\begin{document}

$\left(1-f_{p}\left(l+1\right)\right)\overline{w}\left(l\right)f_{p}\left(l\right)\overline{N}\left(l\right)\hat{H}_{s}\left(l\right)$

$(1-f_{p}(l+1))\overline{w}(l)f_{p}(l)\overline{N}(l)\hat{H}_{s}(l)$

$(1-\mathop{f_{p}}(l+1))\mathop{\overline{w}}(l)\mathop{f_{p}}(l)\mathop{\overline{N}}(l)\mathop{\hat{H}_{s}}(l)$

\end{document}


-
Could you say a bit more about why they \left( and \right) aren't really needed here? According to the "book" it should be fine to use them. – Marc van Dongen Feb 21 '12 at 1:11
@MarcvanDongen, \left\right has two functions, they allow the operators to stretch (but in most cases no stretching was happening in this example) but the second function is that it makes the subterm a \mathinner atom and that gets additional white space in many contexts. Presumably Knuth preferred this in some contexts, but the OP was specifically asking not to get that space and so not generating mathinner atoms is the answer – David Carlisle Feb 21 '12 at 1:27
Thanks. I've never seen this expained in any documentation (but I may have missed it). I did notice Werner's answer touches it. – Marc van Dongen Feb 21 '12 at 1:34

The use of \left and \right extensible delimiters introduces additional horizontal spaces. I would suggest against using them in cases where it is obviously not necessary (like in your example). Rather introduce some distinction between factors in the expressions, if you which to distinguish functions and arguments, using \,:

\documentclass{article}
\begin{document}
The old\ldots
$\left(1-f_{p}\left(l+1\right)\right)\overline{w}\left(l\right)f_{p}\left(l\right)\overline{N}\left(l\right)\hat{H}_{s}\left(l\right)$

The new\ldots
$(1-f_{p}(l+1))\overline{w}(l)\,f_{p}(l)\,\overline{N}(l)\,\hat{H}_{s}(l)$
\end{document}​

-

I think you have two problems, actually. The first is that, as you noticed, the parentheses are too far from their associated functions; this is because you are overusing \left and \right. The second is that they are also too close to the following functions; this can be cured by some explicit spacing (similar to what you might want to use in, say, $\int f(x) \, dx$).

\documentclass{tufte-book}
\begin{document}
$\bigl(1-f_{p}(l+1)\bigr)\, \overline{w}(l)\, f_{p}(l)\, \overline{N}(l)\, \hat{H}_{s}(l)$
\end{document}


I removed all of your \left...\right pairs and replaced the first one with \bigl...\bigr. This produces slightly (but explicitly) larger parentheses around the contained expression, which creates a subtle visual effect against the nested set.

By the way, a complete compilable document is preferred in questions like these. As it turns out, my guess at your preamble was correct, but it might not have been.

-

## Fixing the kerning

In this case I would use \! to tighten the kerning of the plus and minus, because the expression (1-f_p(l+1)) is but one of five factors in the larger expression. (Alternatively, \mathord{+} and \mathord{-} could be used, but these kern a bit too tightly (unless \, is used between the other factors). I would also use \,\, instead of \, here as it provides a slight in increase in spacing that I think improves readability.

\big(1\!-\!f_p(l\!+\!1)\big)\,\,\overline{w}(l)\,\,f_p(l)\,\,\overline{N}(l)\,\,\hat{H}_s(l)


Here are a few variants. #1 is way too loose (as originally pointed out), #2 is way too tight, and the others are a matter of taste. Personally, #5, #7, and #9 are my favorites—with probably #7 being my most favorite.

If you want to get really picky about kerning, notice that the italic math l in #6–#11 is kerned too closely to the +. Fixing this for #6–8, you could use f_p(l\kern.1em\!+\!1) and f_p(l\kern.09em\mathord{+}1) for #9–11 (neither shown above). It’s actually also a wee bit tight in #3–5, but less noticeable there.

## Fixing the overline

You didn’t ask about the overline, but I can't help pointing out that the \overline{N} looks odd in the expression because \overline was not properly designed for tall italic letters.

If you would like the overlined N to look nice, you could replace all occurrences of $\overline{N}$ with \,$\overline{\!N}$. Or, a simpler solution could be to define a new command \overlinetall:

\newcommand{\overlinetall}[1]{\,\overline{\!#1}}


-
Great—now I'm going to be up all night! – raxacoricofallapatorius Feb 21 '12 at 4:44
It should be \bigl( and \bigr), to account for the roles of the parentheses. – egreg Feb 21 '12 at 7:36
Oops, thank you. – Todd Lehman Feb 21 '12 at 8:08
I totally agree with you on the \overline! (See also this answer of mine for automatic kerning of \overline.) But note that one shouldn't use negative spacing like \! for kerning around binary operations or relations; see this answer for details. Better use something like \mkern1mu{+}\mkern1mu. (Only in AMS environments like align, the negative spacing can't do any harm.) – Hendrik Vogt Jun 23 '12 at 11:20

This is a prime example of why \left and \right should not be abused. In the picture, the first line comes from your input, the second from

$(1-f_{p}(l+1))\overline{w}(l)f_{p}(l)\overline{N}(l)\hat{H}_{s}(l)$


-

I think that using \left and \right is the best way to go, as function arguments might as well grow taller than usual. But it is a matter of taste. For myself, I have defined the following command:

\newcommand{\of}[1]{\!\left({#1}\right)}


This gives me nice spacing for function arguments while preserving \left's and \right's functionality, and it also increases readability of the code. Compare your example:

\left(1-f_{p}\left(l+1\right)\right)\overline{w}\left(l\right)f_{p}\left(l\right)\overline{N}\left(l\right)\hat{H}_{s}\left(l\right)


giving:

and mine:

\left(1-f_p\of{l+1}\right)\overline{w}\of{l}f_p\of{l}\,\overline{\!N}\of{l}\hat{H}_s\of{l}


giving:

I borrowed the overline trick from Todd Lehman, thanks!

-
Better using \mleft and \mright from the mleftright package, then. – egreg May 12 at 11:05

In this specific example, one can avoid using \left( and right), and that fixes the spacing issue, as the other answers suggest.

However, there are cases where one must use \left( and right), for instance when the inner expression is significantly taller than the function name. In these cases, one can enclose the function arguments in curly braces, and then the spacing is improved.

For the specific example in the question, one could write the expression as

$$\left(1-f_{p}{ \left(l+1\right)}\right) \overline{w}{\left(l\right)} f_{p}{\left(l\right)} \overline{N}{\left(l\right)} \hat{H}_{s}{\left(l\right)}$$


(Note the curly braces)

This produces the following output:

-