Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to declare a new math operator \ev for representing the expected value, in the form: E<.> so that it looks like the following but with an argument

\DeclareMathOperator{\ev}{\mathrm{E}\left<\right>}

Is there a way of declaring a math operator to take an argument so that I can call it using \ev{.} or would a TeXShop macro be more appropriate that prints:

\mathrm{E}\left*<\right> where the cursor would be placed at *?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

The best approach is with \DeclarePairedDelimiter of \mathtools:

\usepackage{mathtools}
\DeclarePairedDelimiter{\evdel}{\langle}{\rangle}
\newcommand{\ev}{\operatorname{E}\evdel}

This will allow you to say

\ev{x}
\ev[\big]{x}
\ev[\Big]{x}
\ev[\bigg]{x}
\ev[\Bigg]{x}
\ev*{x}

The first will use the delimiters at natural size, in the following four lines the size of the delimiters is selected, the last line shows how to use automatic sizing (which should be used sparingly and only when really necessary).

Complete example:

\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter{\evdel}{\langle}{\rangle}
\newcommand{\ev}{\operatorname{E}\evdel}

\begin{document}

$\ev{x}$
$\ev[\big]{x}$
$\ev[\Big]{x}$
$\ev[\bigg]{x}$
$\ev[\Bigg]{x}$
$\ev*{\dfrac{x}{2}}$

\end{document}

enter image description here

share|improve this answer
    
That's exactly what I was looking for, thanks. Just a follow up question, why should one avoid using automatic sizing? –  oLas Apr 19 '13 at 21:11
add comment

I think this is the simplest approach.

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\evsym}{E}
\newcommand\ev[1]{\evsym\left\langle#1\right\rangle}
\begin{document}
\[
\ev{a}
\]
\end{document}
share|improve this answer
1  
If you add in an \ensuremath command, then you can also use the command in text mode without having to explicitly switch to math mode. –  craigim Apr 19 '13 at 16:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.