Take the 2-minute tour ×
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.

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.

share|improve this question
1  
Inserting space manually is fine. You can hide that in a macro, but you have to do it somewhere. –  Philipp Nov 17 '10 at 7:42

2 Answers 2

up vote 14 down vote accepted

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}
share|improve this answer
    
This looks like the solution! –  Hendrik Vogt Nov 18 '10 at 10:06
    
Instead of typing \relmiddle|\relmiddle|, it may be better to type \relmiddle\Vert; the latter approach makes for slightly tighter (and probably more appropriate) spacing between the vertical bars. In fact, \relmiddle\Vert has the exact same look (and spacing properties) as does \parallel. –  Mico May 25 at 23:07

(Edit: This answer was based on the mistaken assumption that the question was about a binary operator, not a relation. Philippe's answer is better for the latter, but it is not quite so easy if you want a binary operator that grows. See also the comments.)

My answer is like Will's (now gone), except a bit more elaborate:

\def\binmiddle#1{\mathchoice{\mskip\medmuskip}{\mskip\medmuskip}{}{}\middle#1
                 \mathchoice{\mskip\medmuskip}{\mskip\medmuskip}{}{}}

Explanation: A binary operator is surrounded by \medmuskip in display and text mode, but no space in script and scriptscript mode.

share|improve this answer
4  
For those whose knowledge of Norwegian is even worse than mine (is that possible?), the command \medmuskip roughly translates as "with a stingy mouse". –  Loop Space Nov 17 '10 at 10:27
    
@Harald Much better on both counts! Without looking up the values I can never remember when to use what. –  Will Robertson Nov 17 '10 at 11:18
    
You can avoid the \mathchoice by using \nonscript: \nonscript\mskip\medmuskip. But the solution isn't correct any more with LuaTeX, where the spacing around a Rel atom might be different front \medmuskip. I think Philippe's solution is both more robust (since it always works) and more idiomatic (you say what you want, not how to achieve it). –  Philipp Nov 18 '10 at 10:22
1  
@Harald: a binary relation (\mathrel) like mid is surrounded by \thickmuskip; it's binary operations (\mathbin, like +, \times, etc.) which use \medmuskip. The difference is not really visible a lot, but can be in a context with strong inter-word stretching or shrinking (\medmuskip shrinks a lot but not \thickmuskip; here, that's not a real concern because there is no stretching/shrinking inside a \left...\right construct). –  Philippe Goutet Nov 19 '10 at 12:14
    
Yeah, yeah, I get the message … (sorry, I have been too busy to keep track lately). What happened is this: My brain latched onto the word “binary”, so I based my answer on the assumption that we were talking about binary operators, not relations – i.e., Bin objects, not Rel objects. Your answer is more appropriate for the latter, but mine is still the best I can come up with if the former is what is wanted. (In TeX, relations are binary, so we don't usually use that adjective with them. That is how the confusion arose.) –  Harald Hanche-Olsen Nov 19 '10 at 16:50

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.