34

I'm trying to determine if there is a best practice for typesetting the "evaluated at" bar for derivatives. The three possibilities I'm thinking of are shown in the code excerpt below:

\begin{gather*}
5 + \frac{df}{dt} \Bigr\rvert_{t = 0} \\
5 + \frac{df}{dt} \biggr\rvert_{t = 0} \\
5 + \left. \frac{df}{dt} \right\rvert_{t = 0} \\
\end{gather*}

enter image description here

The \Bigr option doesn't quite reach the top and bottom of the fraction. The \biggr option overshoots the top and bottom of the fraction by a little bit. And the \left...\right option has the same height as the \biggr option, but it introduces a little extra space between the + and the fraction. I'm having trouble deciding between these options. Is there a best practice for typesetting this?

4
  • Related/duplicate: tex.stackexchange.com/questions/122331 and tex.stackexchange.com/questions/15894
    – egreg
    Feb 17, 2016 at 20:32
  • @egreg I agree those are related, though I don't think either of them addresses best practices for this particular situation.
    – justin
    Feb 17, 2016 at 20:41
  • 5
    My suggestion would be to make it as a macro like \EvalAt[\Big]{t=0} and then leave it to each case as to how much to scale. Left right constructions end up looking bad on most cases anyway
    – daleif
    Feb 17, 2016 at 20:44
  • 3
    This looks like a task for mathtools’s \DeclarePairedDelimiter.
    – GuM
    Feb 17, 2016 at 21:17

5 Answers 5

18

Since \big is the minimum requested size anyway, it's better to use a simpler approach:

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

\NewDocumentCommand{\evalat}{sO{\big}mm}{%
  \IfBooleanTF{#1}
   {\mleft. #3 \mright|_{#4}}
   {#3#2|_{#4}}%
}

\begin{document}

\begin{align}
& \evalat{f(x)}{x=0} \\
& \evalat[\big]{f(x)}{x=0} \\
& \evalat[\Big]{\frac{\partial f}{\partial x}}{x=0} \\
& \evalat[\bigg]{\frac{\partial f}{\partial x}}{x=0} \\
& \evalat*{\frac{\partial f}{\partial x}}{x=0} \\
& \evalat[\bigg]{\frac{\partial^2 f}{\partial x^2}}{x=0} \\
& \evalat*{\frac{\partial^2 f}{\partial x^2}}{x=0} \\
& \evalat[\bigg]{\left(1+\frac{1}{x}\right)^{\!x^2}}{x=1} \\
& \evalat*{\left(1+\frac{1}{x}\right)^{\!x^2}}{x=1}
\end{align}

\end{document}

Note that the last one has a definitely too big bar.

enter image description here

11

Elaborating on daleif’s suggestion:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

\DeclarePairedDelimiter\evaluat{.}{\rvert}
\reDeclarePairedDelimiterInnerWrapper\evaluat{nostar}{\mathopen{}#2\mathclose{#3}}

\begin{document}

Some examples:
\begin{itemize}
    \item with \verb|\evaluat[\big]|
        \[\evaluat[\big]{\frac{\partial f}{\partial x}}_{x=0}\]
    \item with \verb|\evaluat[\Bigg]|
        \[\evaluat[\Bigg]{\frac{\partial f}{\partial x}}_{x=0}\]
    \item with \verb|\evaluat*|
        \[\evaluat*{\frac{\partial f}{\partial x}}_{x=0}\]
        (in this case, a \verb|\left|\ \ldots\verb|\right| construction is
        used);
    \item and with \verb|\evaluat| (thanks again, egreg~;-)
        \[\evaluat{\frac{\partial f}{\partial x}}_{x=0}\]
\end{itemize}

\end{document}

And here is the output:

Output of the code


Afterthought

Since the OP put an emphasis on questions of style and best usage, I must correct an evident imperfection of the above code: although the \evaluat command produces, in all variants, a math list that begins with an Open atom and ends with a Close atom, nevertheless \evaluat* inserts \nulldelimiterspace on the left of the mandatory argument, while the other forms do not. This is easily corrected:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

\DeclarePairedDelimiter\evaluat{.}{\rvert}
\reDeclarePairedDelimiterInnerWrapper\evaluat{nostar}{%
    \mathopen{}#2\mathclose{#3}%
}
\reDeclarePairedDelimiterInnerWrapper\evaluat{star}{%
    \mathopen{}\mathclose\bgroup #1\hskip -\nulldelimiterspace \relax
    #2\aftergroup\egroup #3%
}

\begin{document}

Some examples:
\begin{itemize}
    \item with \verb|\evaluat[\big]|
        \[\evaluat[\big]{\frac{\partial f}{\partial x}}_{x=0}\]
    \item with \verb|\evaluat[\Bigg]|
        \[\evaluat[\Bigg]{\frac{\partial f}{\partial x}}_{x=0}\]
    \item with \verb|\evaluat*|
        \[\evaluat*{\frac{\partial f}{\partial x}}_{x=0}\]
        (in this case, a \verb|\left|\ \ldots\verb|\right| construction is
        used);
    \item and with \verb|\evaluat| (thanks again, egreg~;-)
        \[\evaluat{\frac{\partial f}{\partial x}}_{x=0}\]
\end{itemize}

Difference between non-\verb|\big| and \verb|\big|:
$\evaluat{x}$, $\evaluat[\big]{x}$.

Test for \verb|\nulldelimiterspace|:
\begin{align*}
    & 1+\evaluat{f(x)}_{x=0} \\
    & 1+\evaluat*{f(x)}_{x=0}
\end{align*}

\end{document}

The output is:

Output of the amended code

Let us also magnify the portion pertaining to the \nulldelimiterspace test:

Detail of the previous image

Of course, the rationale behind the choice of using \DeclarePairedDelimiter was that a simple definition would suffice, with the mathtools package taking care of all the details; if one needs to have recourse so heavily to callback routines, I agree with egreg that this approach loses its sense, and that it is better to directly define an appropriate command, as he does (however, I would recommend the same correction in his code too, and also to arrange for the generated math list to always begin with an Open atom—albeit unlikely, an Op could precede).

4
  • 1
    Don't try \evaluat without the optional argument. ;-)
    – egreg
    Feb 17, 2016 at 23:05
  • A comment to myself: is really an initial Op atom the right thing to do? Consider \[\limsup_{n\to\infty} \evaluat[\bigg]{\frac{df}{dx}}_{x=1/n}\]
    – GuM
    Feb 18, 2016 at 21:15
  • @GustavoMezzetti Thanks for adding in the details to fix the \nulldelimiterspace. I didn't include any Open atoms in my first two examples, with \Bigr and \biggr; I guess I could have inserted some \mathopen{} atoms. But are you suggesting (in your comment to yourself) that such atoms are unnecessary?
    – justin
    Feb 18, 2016 at 22:11
  • @justin: Actually more than this: I am changing my mind once more, and I am beginning to think that an initial \mathopen is actually wrong. Perhaps the best thing of all is to encompass the whole construction in an Ord atom… I no longer know: now it’s bedtime for me, I’ll come back fresh tomorrow! :-) Edit: Good question, anyway!
    – GuM
    Feb 18, 2016 at 22:26
9

I've recently adopted the physics package as part of my usual tool kit, with the advantage that it provides a tool explicitly for this \evaluated{} (or \eval{}).

It seems to apply a minimum size bar, and to scale it up as needed.

Here is an minimal example extracted from a document I wrote for class recently

\documentclass{minimal}

\usepackage{physics}

\begin{document}
here we recognize the terminal velocity in the denominator of the
RHS
\begin{align*}
  \Delta x 
  &= \mp\frac{m}{k} \int_{v_1}^{v_2}
    \frac{v\dd{v}}{v^2 \pm v_t^2}  \\
  \\
  &= \mp\frac{m}{k} \frac{1}{2} \eval{\ln\qty({v^2 \pm
    v_t^2})}_{v_1}^{v_2}  \\
  \\
  &= \mp\frac{m}{2k} 
    \qty[\ln\qty(v_2^2 \pm v_t^2) - \ln\qty(v_1^2 \pm v_t^2)]  \,.
\end{align*}
\end{document}

which generates this output:

enter image description here

The use of \eval is on the second line of the align environment.

0
2

I propose another solution, base on raisebox and a tabular environment. It allows for a greater control on the height and depth of the bar. It is possible (I didn't do it) to have a key=value system to have the height of the bar as a factor times the height of its contents, and its depth as another factor times the depth of the contents.

\documentclass{article}%
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\newcommand\eval[1]{\begin{array}[t]{@{}c@{\,}|@{\,}}% 
\raisebox{0pt}[0.85\height][1.33\depth]{$ \displaystyle#1 $}\end{array}}

\begin{document}

\begin{align*}
    & 5 + \eval{\dfrac{df}{dt}}_{t = 0} \\[2ex]
    & 5 + \eval{\frac{d\Bigl(\dfrac{f}{g}\Bigr)}{dt}}_{t = 0}
\end{align*}

\end{document} 

enter image description here

2
  • The seems to be too much space before the condition t=0. Feb 18, 2016 at 16:51
  • @Andrew Swann: Yes? I wonder why I used \enspace. I guess I modified some older code and forgot to check this spacing I've replaced it with something more sensible. Thanks for pointing it!
    – Bernard
    Feb 18, 2016 at 19:14
1

While trying to adapt Bernard’s answer to a similar question (Vertical bar for “evaluated at”), I noticed that it is defective in that it smashes the height of the “evaluated” subformula, as it can clearly be seen in this modified example,

\documentclass{article}
\usepackage{amsmath}
\newcommand\eval[1]{\begin{array}[t]{@{}c@{\,}|@{\,}}% 
\raisebox{0pt}[0.33\height][1.33\depth]{$ \displaystyle#1 $}\end{array}}

\begin{document}

\begin{align*}
    & 5 + \eval{\dfrac{df}{dt}}_{t = 0} \\[2ex]
    & 5 + \eval{\frac{d\Bigl(\dfrac{f}{g}\Bigr)}{dt}}_{t = 0}
\end{align*}

\end{document}

which produces the following output:

Output of first code sample

However, I liked the idea of using a vertical rule instead of a \vert delimiter, so I worked out another solution based on this same principle. The height and the depth of the rule are computed keeping in mind the rules detailed in Appendix G of The TeXbook for the placement of subscripts (Rules 18a and 18b). Of course, I’ve open to suggestions for what concerns the value of the various parameters.

Here is my current proposal:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath} % I always load it when dealing with math!

\makeatletter

\newcommand*\evaluateat[2]{%
    #1% first, typeset the base symbol(s)
    \mkern .5\thinmuskip % too little? too much?
    \mathpalette{\EA@evaluate@at{#2}}{#1}% then, add the vertical bar
}
\newcommand*\EA@evaluate@at[3]{%
    % #1 <- subscripted annotation
    % #2 <- style selector, e.g., "\textstyle"
    % #3 <- base symbol(s)
    \setbox\z@ \hbox{$\m@th\color@begingroup #2#3\color@endgroup$}%
    \dimen@ \dimexpr \ht\z@ *\tw@/\thr@@ \relax
    \dimen@ii \dp\z@
    \ifx #2\scriptscriptstyle
        \EA@calc@style@dependent@values \scriptscriptfont \scriptscriptfont
    \else \ifx #2\scriptstyle
        \EA@calc@style@dependent@values \scriptfont \scriptscriptfont
    \else
        \EA@calc@style@dependent@values \textfont \scriptfont
    \fi \fi
    \vrule \@height\dimen@ \@depth\dimen@ii \@width\dimen4
    \mathord{% or "\mathclose{}\mathopen{}\mathinner{"?
        \vrule \@depth\dp\z@ \@height\z@ \@width\z@
    }% } brace match
    _{\,#1}%
}
\newcommand*\EA@calc@style@dependent@values[2]{%
    % #1 <- main font selector, e.g., "\textfont"
    % #2 <- relative script font selector, e.g., "\scriptfont"
    \advance \dimen@ii \fontdimen19#2\tw@
    \dimen4 \fontdimen16#1\tw@
    \ifdim \dimen@ii<\dimen4
        \dimen@ii \dimen4
    \fi
    \advance \dimen@ii \dimen4 % extra depth
    % \dimen4 \dimexpr \fontdimen5#1\tw@ *6/5\relax
    \dimen4 \fontdimen5#1\tw@ % the ex-height
    \ifdim \dimen4 <\z@
        \dimen4 -\dimen4
    \fi
    \ifdim \dimen@<\dimen4
        \dimen@ \dimen4
    \fi
    % Now re-use "\dimen4" to hold the default rule thickness:
    \dimen4 \fontdimen8#1\thr@@
}

\makeatother



\begin{document}

In-line: \( \evaluateat{\mathord.}{x=0} + \evaluateat{f}{x=0} +
\evaluateat{f(x)}{x=0} + \evaluateat{\frac{df}{dx}}{x=0} \).  And displayed:
\[
    \evaluateat{f}{x=0}+\evaluateat{\frac{df}{dx}}{x=0}
        - \evaluateat{\,\frac{\frac{df}{dx}\,}{\,\frac{df}{dy}\,}}{x=0,y=0}
\]

Example in \verb|\scriptstyle|:
\( \frac{\evaluateat{f(x)}{x=0}}{g\left(\evaluateat{f(x)}{x=0}\right)} \).

Another example:
\[ \evaluateat{df}{x} \colon T_{x}M\longrightarrow T_{y}N \]

\end{document}

This is the output it yields:

Output of the second code sample

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .