# math operator spacing when used with delimiter modifiers such as \left \right, \big \Big etc

I noticed that using any delimiter modifiers like \left( \right) or \big( \Big( etc after a math operator like \cos inserts a small horizontal space.

This question suggests that one simply not use these commands and use the \bigl, \Bigl etc alternatives; however, I was wondering what the recommended solution is when the argument is not known, in advance?

E.g. Maxima is an open-source computer algebra system that has the option of auto-generating tex output of the computations (similar to what Mathematica does, except it's free); however, the rules for generating tex output are set programmatically, for all output. As such, all powers of trigonometric functions would be rendered like \cos^{n} \left( <arg> \right) to ensure that the parentheses work with any argument.

Is there any way to redefine \left( \right to remove this extra horizontal space? or would it be more appropriate to modify the output for each type of operator, individually? e.g. use \hspace to delete space on an operator-by-operator case?

Apologies for the quasi-off-topic nature of the question: it seemed to me the TeX community was the more appropriate SE to go with, in this particular case

Here are some solutions:

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiter{\parens}{(}{)}

\begin{document}
\begin{align}
&\cos \left( \frac{t}{2} \right) \\
&\cos \mathopen{}\left( \frac{t}{2} \right) \\
&\cos\! \left( \frac{t}{2} \right) \\
&{\cos} \left( \frac{t}{2} \right) \\
&\cos \parens*{\frac{t}{2}}
\end{align}
\end{document}


(1) is the output you wanted to change, (2) is wipet’s excellent answer, (3) inserts a negative space, (4) changes the spacing of \cos from operator to ordinary (like f(x), but will also mess up the spacing of expressions like 2 {\cos}^2.) and (5) uses \DeclarePairedDelimiter from mathtools.

I would recommend (5) as the template to use for automatic generation, if you can also generate the preamble. If you need to be able to copy-and-paste the snippet into any document, go with (2).

The reason the default behavior is that way is that DEK was probably thinking of “math operators” like \sum and \int when he defined the spacing.

• Thank you very much for this detailed answer and clear exposition! Really appreciate your taking the time to reply so thoughtfully. Normally I leave a few days for others to way in, but I can't imagine a more comprehensive response. Again, much appreciated. Feb 10 at 22:51
• I would reminder that (5) is LaTeX-only solution. The OP mentions TeX, no LaTeX. Feb 11 at 9:32
• Comment ot solution (2): If you don't re-set the math-inner to math-ord usind {\left(...\right)}, then you (sometimes) get bad spacing after the closing parenthesis. Feb 11 at 10:58
• @wipet Thanks for the comments. Where does the question say, no LaTeX? Feb 11 at 19:30

You can use

\cos^{n} \mathopen{}{\left( argument\right)}


but auto-generated output has one problem: it is unable to generate human friendly text. Human can write \cos^2 x or \cos^2 (x+y) but machine must geneate \cos^{2} \mathopen{}{\left(x+y\right)}. Unfortunately. TeX language for math formula was intended for humans, not for machines.

• Thank you for the quick reply & great solution. \mathopen was not something I was familiar with. There is no doubt that there are many challenges associated with figuring out how to automate machine-generated TeX, but it seems a worthwhile project. Thank you for taking the time to share your knowledge! Feb 10 at 22:54