2

I sometimes need to write expressions which include derivatives evaluated at a certain point (for example, a Taylor series). My preferred notation (see addendum) is as in the first equation of the MWE below.

Now, one of my pet peeves is setting font sizes (or any other sizes, for that matter) by hand in LaTeX. I am currently using \bigg|, but that won't work anymore if the function and/or the variable becomes bigger, and I really don't want to set all the sizes by hand on all my equations (I have quite a few instances of derivatives evaluated at specific points in different chapters of my document, and each chapter is in its own .tex file). I've tried \vrule, but this resulted in an undesirable vertical positioning of the subscript (see MWE below). Is there a command that produces a vertical bar which scales to the height of whatever it is adjacent to and positions subscripts appropriately?

MWE (some of the packages might be unnecessary; sorry about that):

\documentclass[11pt]{book}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{esvect}
\usepackage{latexsym}
\usepackage{mathtools}
\newcommand{\der}[2]{\frac{\text{d}{#1}}{\text{d}{#2}}}
\newcommand{\dder}[3]{\frac{\text{d}^{#1}{#2}}{\text{d}{#3}^{#1}}}
\begin{document}
\noindent This looks nice:
\begin{eqnarray}
f(x) & = & \sum_{k=0}^\infty\frac{(x-x_0)^k}{k!}\,\dder{k}{f}{x}\bigg|_{x=x_0}
\end{eqnarray}
But this doesn't:
\begin{eqnarray}
f(x) & = & \sum_{k=0}^\infty\frac{(x-x_0)^k}{k!}\,\dder{k}{f}{x}\vrule_{x=x_0}
\end{eqnarray}
\end{document}

First equation has a \bigg|, second one has a \vrule.

As an addendum, I do appreciate conciseness in a document, but I value clarity as well. I'm reluctant to use f' to denote df/dx or \partial f/\partial x because f may be a function of many variables (as in the case with the \partials). I'm also reluctant to use f_x to denote df/dx because I often use subscripts to tell apart different contributions to (or components of) a quantity. Therefore, I don't want to write f^{(k)}(x_0) or other such things. This is non-negotiable; I'd rather not have answers like "change your notation", please. :)

Thanks in advance!

6
  • addressing just the vertical bar, \vrule is never correct here. if you don't want to set the size by hand, then put \left. just after the sum component, and \right| or \right\rvert between the end of the evaluated expression and the "subscript". that will usually result in something reasonable, although a manual selection can often be more precise. Sep 10, 2016 at 1:52
  • 1
    Welcome to TeX SX! Yet, one thing you should change is\eqnarray in favour of align: your spacing around = is much too large. In addition, the syntax will be simpler.
    – Bernard
    Sep 10, 2016 at 2:08
  • @barbarabeeton Thanks, \left. maths go here \right| works! I can't believe I didn't think of that before; I use \left( and \right) all the time. :)
    – Rain
    Sep 10, 2016 at 2:47
  • @Bernard Thanks for the welcome! I actually like the extra space around the =, as it increases the readability of the equation. If you have a polynomial sort of thing (i.e. many terms on one or both sides of the equation separated by minus and/or plus signs), it can be a little difficult to tell where the left side ends and the right side begins if the space around the = is the same as that around the minus and plus signs, don't you think?
    – Rain
    Sep 10, 2016 at 2:49
  • I don't think there's a real chance for this, as generally there are several = signs vertically aligned.
    – Bernard
    Sep 10, 2016 at 2:58

1 Answer 1

1

I propose two solutions: an \eval macro, with two arguments, which is adapted from a code found on this site – I don't remember where, and a different version with the starred version of \diff, from package esdiff. Note the same package has handy \diffp and its starred version for partial derivatives.

I also replaced eqnarray with align for a better horizontal spacing around the alignment point. Also note you don't have to load amsmath if you load mathtools.

\documentclass[11pt]{book}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{esvect, esdiff}
\usepackage{latexsym}
\usepackage{mathtools}

\def\eval#1#2{\mathchoice
              {\setbox0\hbox{${\displaystyle #1}_{\scriptstyle #2}$}
              \evalaux{#1}{#2}}
              {\setbox0\hbox{${\textstyle #1}_{\scriptstyle #2}$}
              \evalaux{#1}{#2}}
              {\setbox0\hbox{${\scriptstyle #1}_{\scriptscriptstyle #2}$}
              \evalaux{#1}{#2}}
              {\setbox0\hbox{${\scriptscriptstyle #1}_{\scriptscriptstyle #2}$}
              \evalaux{#1}{#2}}}
\def\evalaux#1#2{{#1\,{\vrule height .67\ht0 depth 1.2\dp0}_{\,#2}} }

\begin{document}

\begin{align}
f(x) & =\sum_{k=0}^\infty\frac{(x-x_0)^k}{k!}\,\eval{\diff[k]{f}{x}}{x=x_0}\\[1ex]
f(x) & =\sum_{k=0}^\infty\frac{(x-x_0)^k}{k!}\diff*[k]{f}{x}{x = x_0}
\end{align}

\end{document} 

enter image description here

10
  • should use box0 not box1 for local assignments Sep 10, 2016 at 8:28
  • @David Carlisle: Thanks. It's an old code I have, and I didn't know that. I've fixed it. As I'm curious: what is the reason for that?
    – Bernard
    Sep 10, 2016 at 9:00
  • convention of plaintex and latex as documented in texbook, registers 0-9 are scratch registers with odd numbered ones for global and even numbered ones for local assignments. If you don't follow the convention you may get an unexpected nested global assignment changing things and you can generate excessive save stack use due to the way tex copes with local and global assignments to the same register Sep 10, 2016 at 9:03
  • others may disagree, but the vertical bar looks too short at the top. the usual appearance is for the vertical bar to be symmetrical about the math axis. see math.stackexchange.com/q/983398/233629 for an example. Sep 10, 2016 at 12:55
  • @barbara beeton: It was purposely, to make a difference between the vertical bar used for definite integrals – difference (!) of values of the anti-derivative at the bounds of the interval of integration, and the vertical bar used for evaluating a function at some point, or restricting it to a subdomain. It also shows one can play with height and depth of the vertical rule, contrary to an approach base on, say, tabular. That said, perhaps I'm too much of a nitpicker.
    – Bernard
    Sep 10, 2016 at 13:07

You must log in to answer this question.

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