72

I wonder how to typeset the restriction of a function to some subdomain, a la $f|_A$ or $f\restriction_A$ , but with the vertical bar being as big as possible.

6
  • It seems that one can just use \big| or \Big|. But is there something which chooses the optimal size (or can there not be such a thing)?
    – Michael
    Jul 4, 2011 at 7:50
  • And welcome to TeX.SE!
    – raphink
    Jul 4, 2011 at 8:33
  • 14
    For \restriction, \usepackage{amssymb}. Nov 22, 2013 at 6:18
  • @EvgeniSergeev Your answer is the best - why don't you make it one? Sep 9, 2014 at 6:47
  • 2
    @AriBrodsky It doesn't actually answer the OP's question (though it might be useful for folks like me who came to the page looking to answer the question restricted to its title :) Sep 10, 2014 at 1:56

7 Answers 7

65

If you want the vertical bar to be at least \big, the following doesn't have the spacing issues of Ulrich's solution:

\newcommand\restr[2]{{% we make the whole thing an ordinary symbol
  \left.\kern-\nulldelimiterspace % automatically resize the bar with \right
  #1 % the function
  \vphantom{\big|} % pretend it's a little taller at normal size
  \right|_{#2} % this is the delimiter
  }}

If you don't need the extra height for normal size symbols, comment the \vphantom line.

Use it as \restr{f}{A}.

The above code works best in display style. In other styles (particularly text style) it's likely better to remove the phantom.

\documentclass{article}
\usepackage{amsmath}

\newcommand\restr[2]{{% we make the whole thing an ordinary symbol
  \left.\kern-\nulldelimiterspace % automatically resize the bar with \right
  #1 % the function
  \littletaller % pretend it's a little taller at normal size
  \right|_{#2} % this is the delimiter
  }}

\newcommand{\littletaller}{\mathchoice{\vphantom{\big|}}{}{}{}}

\begin{document}

\[
\restr{f}{U}=\frac{\restr{g}{U}}{\restr{h}{U}}
\]

\end{document}

enter image description here

3
  • I thought you had a principle to always suppress end-line spaces with %, even in math mode, for the sake of “uniformity”. But perhaps that principle is less than a decade old? ;-)
    – Gaussler
    Sep 26, 2022 at 7:37
  • @Gaussler I leave as an exercise to the reader to explain why spaces here are not relevant. ;-)
    – egreg
    Sep 27, 2022 at 9:30
  • I know they’re not making any difference for commands intended for math mode, but look at your own comments right here. ;-)
    – Gaussler
    Sep 27, 2022 at 9:33
33

Does $\left.f\right|_A$ provide what you are looking for?

1
  • Hello @Lustique, is there a way to add another condition below? For example A and below B? Oct 18, 2022 at 14:01
5

How about \newcommand\restr[2]{\ensuremath{\left.#1\right|_{#2}}}, which can be used like this: $\restr{f}{A}$?

(Warning, haven't tested...)

5

I use the following:

\def\restrict#1{\raise-.5ex\hbox{\ensuremath|}_{#1}}

because normally the vertical bar must be lowered (and not centered on the math axis as other symbols). And it doesn't need to be very big, it is the fact that it goes lower than the rest that shows that it is a restriction and not an absolute value or a divides symbol.

1
  • 12
    Since it's LaTeX, it should be \newcommand\restrict[1]{\raisebox{-.5ex}{$|$}_{#1}}
    – egreg
    Nov 17, 2015 at 10:08
3

I had that problem recently and I looked it up here, but since then I usually type $f_{\big|A}$

2
  • Shouldn't it be $f{\big|}_A$? Aug 12, 2017 at 6:49
  • I wouldn't write it like that
    – Javi
    Aug 13, 2017 at 9:57
1

I would prefer $f\arrowvert_A$ to the above-mentioned suggested commands.

2
  • 2
    Welcome to TeX.SE! What do you mean with above commands?
    – Mensch
    Sep 22, 2021 at 16:44
  • 3
    Additionally, specify the source of \arrowvert.
    – Werner
    Sep 22, 2021 at 17:20
0

Another option is \eval{f}_A provided by the physics package:

enter image description here

\documentclass{standalone}
\usepackage{amssymb}
\usepackage{physics}

\begin{document}
\begin{tabular}{cccc}
\verb=f\restriction_A= & \verb={f|}_A= & \verb={f\bigr|}_A= & \verb=\eval{f}_A= \\
$f\restriction_A$ & ${f|}_A$ & ${f\bigr|}_A$  & $\eval{f}_A$ \\ \noalign{\vskip 1mm}
$f^{(n)}\restriction_A$ & ${f^{(n)}|}_A$ & ${f^{(n)}\bigr|}_A$  & $\eval{f^{(n)}}_A$  \\
\end{tabular}
\end{document}

You must log in to answer this question.

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