[Tex/LaTex] Evaluation Symbol: Consistent Implementation

delimitersmath-modemathjaxsymbols

This question has been posted several times but…

I'm looking for a consistent implementation of the evaluation symbol:

  • Evaluation bar as delimeter: <...>|
  • Auto-size to its enclosing expression: \left<...>\right

What I'm not looking for is:

  • Evaluation bar as relation: <...>\mid
  • Manual-size to its enclosing expression: <...>bigg|
  • A whole macro!

Now, the problem is that \rvert does not auto-size, whereas \left. inserts extra spacing.

Perfect would be something of the form \left_ telling latex to enclose the expression here while inserting no delimiter from the left at all, no matter wether visible or invisible.

Do you have an idea how to implement the evaluation bar?
(Not just circumventing the problem!)

As an example consider:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
y(a)&=\frac12 x^2|_a\\
y(a)&=\frac12 x^2\rvert_a\\
y(a)&=\left.\frac12 x^2\right|_a
\end{align}
\end{document}

Best Answer

Here is a macro that does auto scaling, but also allows you to manually specify a size if so desired. You can also specif a prefix for the limits if so desired as in the last example on the first group:

enter image description here

Notes:

  • The manually specified size example as just illustrate the possibilities in the size that you can select. I am not suggesting that all those sizes are appropriate for the given fraction.

Code:

\documentclass{article}

\usepackage{amsmath}
\usepackage{xparse}

% http://tex.stackexchange.com/questions/38868/big-parenthesis-in-an-equation
% http://tex.stackexchange.com/questions/6794/about-big-parenthesis-larger-than-bigg
\makeatletter
    \newcommand{\vast}{\bBigg@{3}}
    \newcommand{\Vast}{\bBigg@{3.5}}
    \newcommand{\vastt}{\bBigg@{4}}
    \newcommand{\Vastt}{\bBigg@{4.5}}
\makeatother


\newcommand{\BracKern}{\kern-\nulldelimiterspace}
\NewDocumentCommand{\Eval}{O{} o m m m}{%
    % #1 = prefix to be added to each limit of evaluation (ex "x=").
    % #2 = optional size specification to be applied (defaults to \left \right pair)
    %          \big \Big \bigg \Bigg \vast \Vast \vastt \Vastt
    %
    % #3 = expression being evaluated
    % #4 = lower limit of evaluation
    % #5 = upper limit of evaluation
    \IfNoValueTF{#2}{%
        \left.\BracKern#3\right\rvert_{#1#4}^{#1#5}%
    }{%
        #3#2\rvert_{#1#4}^{#1#5}%
    }%
}

\usepackage{amsmath}

\begin{document}
\noindent
Automatically sized:
\begin{gather*}
    \Eval{x^2}{0}{5} \quad
    \Eval{\frac{1}{x}}{0}{5} \quad
    \Eval[x=]{\frac{1}{x}}{0}{5} 
\end{gather*}
Manually sized
\begin{gather*}
    \Eval[][\big]{\frac{1}{x}}{0}{5}    \quad
    \Eval[][\Big]{\frac{1}{x}}{0}{5}    \quad
    \Eval[][\bigg]{\frac{1}{x}}{0}{5}   \quad
    \Eval[][\Bigg]{\frac{1}{x}}{0}{5}   \quad
    \Eval[][\vast]{\frac{1}{x}}{0}{5}   \quad
    \Eval[][\Vast]{\frac{1}{x}}{0}{5}   \quad
    \Eval[][\vastt]{\frac{1}{x}}{0}{5}  \quad
    \Eval[][\Vastt]{\frac{1}{x}}{0}{5}
\end{gather*}
\end{document}