[off-topic] LaTex for [[ ... ]]

Ross Paterson ross@soi.city.ac.uk
Fri, 1 Jun 2001 17:59:25 +0100


On Fri, Jun 01, 2001 at 12:41:05PM -0400, Ken Shan wrote:
> On 2001-06-01T08:41:34-0700, Andrew Moran wrote:
> > There's also \llbracket and \rrbracket, from stmaryrd.  They look better than
> > the negative space hack, IMHO (now all I need is for Alan Jeffrey to write in
> > and say that \{ll,rr}bracket are implemented with the negative space hack :-)
> 
> Heh.  Actually they're not (and cannot, because they are extensible
> delimiters -- useful for typesetting the denotation of multiple-line
> programs!).

Here's a negative space hack that gives extensible brackets: write
\Sem{expr} to wrap an expression.  (Doubtless someone who knows TeX
could do better.)

\newsavebox{\sembox}
\newlength{\semwidth}
\newlength{\boxwidth}

\newcommand{\Sem}[1]{%
\sbox{\sembox}{\ensuremath{#1}}%
\settowidth{\semwidth}{\usebox{\sembox}}%
\sbox{\sembox}{\ensuremath{\left[\usebox{\sembox}\right]}}%
\settowidth{\boxwidth}{\usebox{\sembox}}%
\addtolength{\boxwidth}{-\semwidth}%
\left[\hspace{-0.3\boxwidth}%
\usebox{\sembox}%
\hspace{-0.3\boxwidth}\right]%
}