3

I'd like to create a macro of some sort which produces a vertical bar | which scales with the height of the object it's referred to. Using the physics package this works as follows:

\eval{\pdv{f}{x}}_y

However I'd like to use something like:

\pdv{f}{x}\eval|_x
\pdv{f}{x}\eval_x
\pdv{f}{x}\eval{x}

This is because when I'm writing it comes more natural to write the vertical bar after the derivative. I may use $\bigg|$ or $\Bigg|$ since most of my expressions have similar heights but I'd like to know if there's some way to make this work so that it scales.

1
  • 1
    I usually just use an explicit \left. f(x) \right\rvert_{x=x_0} for this. You could wrap this in a macro if necessary, too.
    – chsk
    Mar 19, 2021 at 11:50

1 Answer 1

2

The point of having a macro \eval{...} is (I guess) to ensure the scaling (which I don't like in general). It would be possible to patch \pdv such that it saves the height of the whole construct in a length register which is later used to build the par, but I don't like and I don't use the physics package. Furthermore, automatic scaling is in general very dangerous as you see in the following example

\[
\left.\frac{\partial f}{\partial x}\right|_x
\left.\frac{\partial \tilde{f}}{\partial x}\right|_x
\]

enter image description here

I believe there is no doubt that the second expression looks appalling.

Honestly, I see no big difference in having something which works as

\frac{dy}{dx}\eval_x

over the more direct

\frac{dy}{dx}\biggr|_x

except sparing two keystrokes and making the code IMO less legible (though the latter comment might depend on how my eyes and brain parse LaTeX math). But if your \eval almost always have the same height (say \bigg) then you could define something like this

\documentclass{article}

\makeatletter
\newcommand*{\eval}[1][\bigg]{%
   \if\relax\detokenize{#1}\relax
      \def\next{\mathclose|}%
   \else
      \def\next{\csname\expandafter\@gobble\string#1r\endcsname|}%
   \fi
   \next
}
\makeatother

\begin{document}

\[
\frac{\partial f}{\partial x}\eval_x \quad
a\eval[\big]_x \quad
a\eval[]_x \quad
\frac{\partial f}{\partial x}\eval[\Bigg]_x^y
\]

\end{document}

enter image description here

By default \bigg is used; different sizes can be given as optional parameter.

1
  • This is close enough to what I was looking for, thanks. Mar 19, 2021 at 12:39

You must log in to answer this question.

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