# How to format this formula, in particular, the parentheses better?

 $$\mathrm{err} \left( h(\vec{\theta}, \vec{x}), y \right) = \delta_{0y} ~ H \left( h(\vec{x}; \vec{\theta}) - \frac{1}{2} \right) + \delta_{1y} ~ H \left( \frac{1}{2} - h(\vec{x}; \vec{\theta}) \right)$$

-

1. You should never use $$ in LaTeX, see Why is $…$ preferable to $$?

2. “err” should be a math operator.

3. Never use a ~ in math mode; multiplication doesn't want space.

4. \left and \right add unwanted space when they surround the argument to a function.

5. A \vec near a closed parenthesis needs a thin space.

6. There's no need to have big parentheses for the argument to err; I'd use normal size, but I show also how to get slighly bigger ones.

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\err}{err}

\begin{document}
First version
$\err( h(\vec{\theta}, \vec{x}\,), y ) = \delta_{0y} H \biggl( h(\vec{x}; \vec{\theta}\,) - \frac{1}{2} \biggr) + \delta_{1y} H \biggl( \frac{1}{2} - h(\vec{x}; \vec{\theta}\,) \biggr)$

Second version
$\err\bigl( h(\vec{\theta}, \vec{x}\,), y \bigr) = \delta_{0y} H \biggl( h(\vec{x}; \vec{\theta}\,) - \frac{1}{2} \biggr) + \delta_{1y} H \biggl( \frac{1}{2} - h(\vec{x}; \vec{\theta}\,) \biggr)$

\end{document}


Other options include not having \DeclareMathOperator{\err}{err} in the preamble but the equivalent \operatorname{err} in the formula and using \tfrac{1}{2} as suggested by daleif, although I'm not sure about this. Here's the example.

\documentclass{article}
\usepackage{amsmath}

Third version
$\operatorname{err}\bigl( h(\vec{\theta}, \vec{x}\,), y \bigr) = \delta_{0y} H \bigl( h(\vec{x}; \vec{\theta}\,) - \tfrac{1}{2} \bigr) + \delta_{1y} H \bigl( \tfrac{1}{2} - h(\vec{x}; \vec{\theta}\,) \bigr)$

\end{document}


-
Almost identical to what I was about to post, the only addition I had was to add phantom vertical spacing on the vector arrows \vec{x\vphantom{\theta} so that they are the same height. – Peter Grill May 10 '14 at 22:44
@PeterGrill I wouldn't do it; I wouldn't use the arrow for the vector, either. – egreg May 10 '14 at 22:48
@egreg: once more I forgot to check if an answer was posted while I was checking mine! However I have smaller parentheses through the use of nccmath for fractions. – Bernard May 10 '14 at 22:56
Would look even better using \tfrac – daleif May 11 '14 at 7:40
@Problemania For $$ see Why is $…$ preferable to $$?; for the operator you can use \operatorname{err} in the formula, which is better than \mathrm in this case (and is equivalent to what you get if you define \err as shown in the preamble). – egreg May 11 '14 at 17:52

Supposing it is a LaTeX document, first replace $$…$$ with $…$. Also define err as a math operator to have a correct horizontal spacing. Then you can use the nccmath package to use medium sized fractions, and replace \left … \right with the manually adjusted \Bigl … \Bigr:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}

\usepackage{mathtools}
\usepackage{nccmath}

\DeclareMathOperator{\err}{err}

\begin{document}

$\err\bigl( h(\vec{\theta}, \vec{x}), y \bigr) = \delta_{0y}\,H\Bigl(h( \vec{x}; \vec{\theta}) - \mfrac{1}{2} \Bigr) + \delta_{1y}\, H\Bigl( \mfrac{1}{2} - h(\vec{x}; \vec{\theta}) \Bigr)$

\end{document}


-
FYI, I used to use the nccmath package package but ran into numerous issues that I decided to drop it. See Is there a replacement for nccmath? and the problems listed in the question. – Peter Grill May 10 '14 at 23:27
@Peter Grill: I know that (can't remember under which exact circumstances, but I never met those difficulties). The closest would be the \mathsmaller command from relsize. Maybe you should try to contact the author of nccmath — in my opinion, this concept of medium sized math formulae is really useful, as you can see from this example. – Bernard May 10 '14 at 23:33