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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
    
    
@egreg I agree those are related, though I don't think either of them addresses best practices for this particular situation. – justin Feb 17 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 at 20:44
3  
This looks like a task for mathtools’s \DeclarePairedDelimiter. – Gustavo Mezzetti Feb 17 at 21:17
up vote 6 down vote accepted

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

share|improve this answer

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).

share|improve this answer
1  
Don't try \evaluat without the optional argument. ;-) – egreg Feb 17 at 23:05
    
@egreg: Oops, thanks. See edit. – Gustavo Mezzetti Feb 17 at 23:24
    
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}\] – Gustavo Mezzetti Feb 18 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 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! – Gustavo Mezzetti Feb 18 at 22:26

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.

share|improve this answer
    
Thanks. would you mind including the code for the displayed equation? – justin Feb 18 at 0:35
    
OK. How's that? – dmckee Feb 18 at 16:39

I propose anther 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

share|improve this answer
    
The seems to be too much space before the condition t=0. – Andrew Swann Feb 18 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 at 19:14

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.