7

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}
  • '\left.\right\rvert_{}` –  Dec 10 '14 at 21:51
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Martin Schröder Dec 10 '14 at 21:53
  • @MarcvanDongen: That is bad as it does not avoid the missing delimiter but inserts an invisible delimiter. – C-star-W-star Dec 10 '14 at 22:01
  • 2
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – cfr Dec 10 '14 at 22:04
  • @Freeze_S I am not sure you understand: it's your duty to make LaTeX aware of the delimiters, not the other way around (unfortunately...). –  Dec 10 '14 at 22:06
  • @cfr: Of course, one moment, please. – C-star-W-star Dec 10 '14 at 22:10
  • In general autoscaling is not a good idea. I'd make a macro where you add manual scaling via an optional argument. Autoscaling often ends up being too large – daleif Dec 10 '14 at 22:21
  • @daleif: But manual scaling sort of contradicts the principles of latex: Latex does the job for you. – C-star-W-star Dec 10 '14 at 22:50
  • @daleif why is autoscaling not a good idea? –  Dec 10 '14 at 23:04
  • @MarcvanDongen: The problem is that I'd need a no-delimiter argument. I don't know what to answer on this: I know what a computer is. ;) – C-star-W-star Dec 10 '14 at 23:05
  • @daleif: I'm sorry, my deleted comment was actually adressed to MarcvanDongen. – C-star-W-star Dec 10 '14 at 23:07
  • @Freeze_S Do you need just the subscript or also the superscript? – egreg Dec 10 '14 at 23:16
  • @egreg: For myself: Subscript only. – C-star-W-star Dec 10 '14 at 23:17
  • @Freeze_S In LaTeX terms, \rvert is a delimeter. –  Dec 11 '14 at 06:29
  • Try adding the auto scaling principle to \sum_j, that just get too large. You will find other people here how also advise against general autoscaling. Autoscaling should be used when appropriate, but not in every single case, that will end up biting you. – daleif Dec 11 '14 at 07:51
  • @MarcvanDongen: Yep but \rvert does not autoscale and \left. adds an invisible delimiter. Perfect would be something like \left_ instead of \left. telling latex to enclose the expression here and not to insert any delimiter from the left no matter wether visible or invisible. – C-star-W-star Dec 11 '14 at 09:45
  • @Freeze_S We're probably missing each other's point. Final attempt: no delimiter autoscales. Delimiters only autoscale with \left and \right. –  Dec 11 '14 at 10:10

2 Answers2

3

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}
Peter Grill
  • 223,288
3

An application of the macros in https://tex.stackexchange.com/a/136767/4427

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn
\DeclareDocumentCommand{\xDeclarePairedDelimiter}{mmmO{}}
 {
  \NewDocumentCommand{#1}{sO{}m}
   {
    \IfBooleanTF{##1}
     {
      \egreg_paired_delimiter_expand:nnnn {#2}{#3}{##3}{#4}
     }
     {
      \egreg_paired_delimiter_fixed:nnnnn {##2}{#2}{#3}{##3}{#4}
     }
   }
 }
\cs_new_protected:Npn \egreg_paired_delimiter_expand:nnnn #1 #2 #3 #4
 {% Fix the spacing issue with \left and \right (D. Arsenau, P. Stephani and H. Oberdiek)
  \mathopen{}
  \mathclose\c_group_begin_token
   \left#1
   \str_if_eq:nnT { . } { #1 } { \kern-\nulldelimiterspace }
   #3
   \group_insert_after:N \c_group_end_token
   \right#2
   \tl_if_empty:nF {#4} { \c_math_subscript_token {#4} }
 }
\cs_new_protected:Npn \egreg_paired_delimiter_fixed:nnnnn #1 #2 #3 #4 #5
 {
  \str_if_eq:nnF {.} { #2 } { \mathopen{#1#2} }
  #4
  \mathclose{#1#3}
  \tl_if_empty:nF {#5} { \c_math_subscript_token {#5} }
 }
\ExplSyntaxOff

%% the final optional argument to \xDeclarePairedDelimiter
%% is a subscript to the right fence
\xDeclarePairedDelimiter{\xeval}{.}{\rvert}[\evaluateat]
\newcommand{\evaluateat}{}
\NewDocumentCommand{\eval}{somm}{%
  \begingroup
  \renewcommand{\evaluateat}{#4}%
  \IfBooleanTF{#1}
    {\xeval*{#3}}
    {\IfNoValueTF{#2}{\xeval{#3}}{\xeval[#2]{#3}}}%
  \endgroup
}


\begin{document}
\begin{align}
y(a)&=\eval{\tfrac{1}{2}x^2}{a}\\
y(a)&=\eval[\Big]{\frac{1}{2}x^2}{a}\\
y(a)&=\eval[\bigg]{\frac{1}{2}x^2}{a}\\
y(a)&=\eval*{\dfrac{1}{2}x^2}{a}
\end{align}
\end{document}

The optional argument to \eval is for choosing manually a size; \eval* is like using \left and \right. The second argument is the point of evaluation.

enter image description here

egreg
  • 1,121,712