[Tex/LaTex] How to get a \mid binary relation that grows

math-modesymbols

This question relates to one about getting a vertical bar longer than \mid.

How to get a vertical bar which is longer than \mid ?

However while the given \middle| solution works for me, it no longer behaves as a binary relation and so loses the space to the left-and-right of it that \mid puts in.

(I know I could manually add space, but I want the right way to do this.)

In fact I want a "growable \mid" that works like \left\{ and its relatives.

Best Answer

If you want to get \middle| to behave exactly as \mid on all accounts (spacing, stacking in the form \mid\mid, etc.), you need to use \mathrel{} on both sides of \middle| (manual spaces like \; won't do the job correctly in all situations):

\newcommand{\relmiddle}[1]{\mathrel{}\middle#1\mathrel{}}

Here's a code that compares \mid and the new command \relmiddle on two different formulas and shows that the spacing is identical:

alt text

\documentclass{article}
\newcommand{\relmiddle}[1]{\mathrel{}\middle#1\mathrel{}}
\begin{document}
\nulldelimiterspace=0pt% to kill the little space before \left and after \right (not a good idea in a real document)
$a \mid -b$\par
$\left. a \relmiddle| -b \right.$

$a \mid\mid -b$\par
$\left. a \relmiddle|\relmiddle| -b \right.$
\end{document}