# Parenthesis too big with \hat in between

The calculation of the correct parentheses size fails when a letter with a \hat accent is in between:

\left(\hat{x}\right)


Manually specifying the size of the brackets would be a lot of work as they are part of a command (statistics: expected value):

\newcommand{\E}[1]{\mathbb{E}\left[{#1}\right]}


Is there a way to modify the command to produce correctly-sized brackets?

Meta: Is there a way to have LaTeX code converted to images? Maybe it's that obvious that the help page do not mention it ...

-
What do you mean by correctly sized? –  Ian Thompson Mar 4 '12 at 14:09
For direct conversion to images the standalone package together with convert from Imagemagick is very handy. –  zeroth Mar 4 '12 at 14:10
What does the question at the end have to do with the main question? I strongly suggest that you do some minimal amount of research before asking this tacked-on question. –  qubyte Mar 4 '12 at 14:15
@MarkS.Everitt: I suspect the OP, coming from another stackexchange site, expected TeX code to automatically be rendered using MathJax (as on other sites). Mirko, on TeX.sx, we are mostly interested by the code, hence rendering is disabled: follow zeroth's suggestions to produce an image (but you would need more reputation anyways to post it, so for this question, don't worry). –  Bruno Le Floch Mar 4 '12 at 18:31
@BrunoLeFloch: Ah, I misinterpreted completely then. My apologies to Mirko. –  qubyte Mar 5 '12 at 4:49

This is another case showing that automatic resizing with \left and \right should be used with care. It gives unwanted spaces in some cases and wrong results in others like this.

The best thing I can suggest you is to avoid \left and \right for this command or at least to use the facilities offered by mathtools.

For example, you could define

\usepackage{amssymb,mathtools}
\newcommand{\shat}[1]{\vphantom{#1}\smash[t]{\hat{#1}}}

\DeclarePairedDelimiter{\Ex}{[}{]}
\newcommand{\E}{\mathbb{E}\Ex}


so that

$\E{A}$

$\E{\hat{A}}$

$\E{\frac{A}{2}}$

$\E*{\frac{A}{2}}$

$\E*{\dfrac{A}{2}}$


will give the following result (\left and \right are applied only when the you call \E* instead of \E):

One can also specify explicit size of the brackets with an optional argument:

$\E[\big]{\hat{A}}$


will produce slightly bigger brackets than $\E{A}$.

-
Thanks for pointing me to the \smash[t] command, that's what I was looking for. –  Mirko Vogel Mar 5 '12 at 11:28