3

This question is about having the most generic parenthesis code if one doesn't know the contents size of the parenthesis a priori.

If I want to write a function or parenthesized equation I write, for example, $f(...)$.

If I want to use the same code regardless of the contents of the parenthesis ... one tends to find that \left(...\right) is likely to look better if the contents are big.

However the spacing is not correct, even for small contents. In the sense that for example f(x) is not visually equivalent to f\left(x\right). So to cover for that case I write f\!\left(...\right).

I recently found that this works in many contexts but not in a superscript. For example \[ e^{i\arg\!\left(z\right)} \], produced a badly spaced formula:

badspacing

Is there a parenthesis code that works more or less well regardless of content and the context?

It looks like \! is pretty close to a solution, so preferably without using additional packages. (references to packages are still welcome).


EDIT: From @Manuel's answer below, it looks like the most elegant solution is to use the package mleftright and leave all the \left(, \right) commands as they are. It also looks like one can use \mathopen{}\mathclose{\left(...\right)} if one doesn't want to include packages.

Here it is a sample to show that all solutions give a consistent output:

\documentclass[]{article}
\begin{document}

\[ i \arg(z) \]
\[ i \arg\left(z\right) \]
\[ e^{i \arg\!\left(z\right)} \]
\[ e^{i \arg\mathopen{}\mathclose{\left( z\right)}} \]
\[ i \arg\mathopen{}\mathclose{\left( z\right)} \]
\[ i \arg\mathopen{}\mathclose{\left(\frac{z}{y}\right)} \]

\end{document}

spacing

\documentclass[]{article}
\usepackage{mathtools,mleftright}
\mleftright
\begin{document}

\[ i \arg(z) \]
\[ i \arg\left(z\right) \]
\[ e^{i \arg\!\left(z\right)} \]
\[ e^{i \arg\mathopen{}\mathclose{\left( z\right)}} \]
\[ i \arg\mathopen{}\mathclose{\left( z\right)} \]
\[ i \arg\mathopen{}\mathclose{\left(\frac{z}{y}\right)} \]

\end{document}

spacingmleftright

7
  • 2
    mleftright and \mleft and \mright?
    – Manuel
    May 25, 2015 at 19:36
  • Even if you fix the horizontal spacing matter -- using, say, the suggestion of @Manuel to employ \mleft and \mright -- you still run into the issue that you'll sometimes have parentheses that are too large (from a typographer's point of view) or, in other circumstances, too small. Thus, I don't think it can be said that there's automated code for parentheses that works under circumstances.
    – Mico
    May 25, 2015 at 20:12
  • 1
    AFAIR nath did an OK job. But it is incompatible with a lot of stuff and have redefine most math. So I agree with Mico, it takes experience to know what is best. In general, don't use autoscaling too much it often ends up overpowering an expression or (if used within normal text) disturbs line spacing
    – daleif
    May 25, 2015 at 20:43
  • Ah, and if you end up not using autoscaling (e.g. \bigl(, \Bigr), etc.) you should patch the \bigx commands because, by default they only use the \displaystyle font. Shameless plug.
    – Manuel
    May 25, 2015 at 20:49
  • For more information on why using \left and \right everywhere is not a good idea in general, check out the postings "(" or "\left(" parentheses? and Is it ever bad to use \left and \right?
    – Mico
    May 26, 2015 at 3:48

1 Answer 1

2
\documentclass{scrartcl}

\usepackage{mathtools,mleftright}
\mleftright % Or comment this line and use \mleft and \mright instead

\begin{document}
$f\left(x\right)$
$\arg\left(z\right)$
$e^{i\arg\left(z\right)}$ 
\end{document}
4
  • Do you know what is the secret of mleftright? it seems that smartly chooses the spacing before the opening (...). The size it self seems to be that of the default \left( \right).
    – alfC
    May 26, 2015 at 6:42
  • 1
    Basically defines, for instance \mleft( to be \mathopen{}\mathclose{\left( and \mright) to \right)}, so it ends being a \mathopen{}\mathclose{..} rather than \mathinner{..} (with \mleftright you redefine the \left/\right commands, so there's no need to change anything at all in the document.
    – Manuel
    May 26, 2015 at 11:16
  • from you comment I understand that \mathopen{}\mathclose{ ... \right)} is the poor's man version (or equivalent to) of mleftright. Indeed it works pretty well.
    – alfC
    May 27, 2015 at 21:06
  • You could say that. But I don't see the advantage of using \mathopen{}\mathclose{\left( .. \right)}.
    – Manuel
    May 27, 2015 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .