[comp.text.tex] double square brackets

yxoc@fb14vax.cs.uni-sb.de (Ralf Treinen) (01/24/91)

Included is a small documentstyle "meaning.sty" that provides a macro
for double square brackets as often used for the semantics of programming
languages. It works in all sizes and also as subscript or subsubscript.
Comments and suggestions are welcome.

Ralf

%
% Double square brackets, as used for semantics, e.g. [[ f(2+5) ]]
% Works in all sizes and also as sub- and subsubscript
% Usage: \Mean{ <math stuff> } in math mode
%
% Ralf Treinen (yxoc@cs.uni-sb.de) 23.1.91 . Comments welcome.
%
\newbox\M@contents	% the math stuff that goes inside the brackets
\newbox\M@KH		% two horizontal lines
\newbox\M@KV		% one vertical line
\newdimen\M@height	% height of the brackets
\newdimen\M@depth	% depth  of the brackets
\newdimen\M@total	% height + depth of the brackets
\newdimen\M@strength	% the strength of the lines of the brackets
\newdimen\M@width	% distance between the 2 vertical lines of the brackets
\def\Mean#1{\mathchoice%
{\setbox\M@contents\hbox{$\displaystyle#1$}\M@draw}
{\setbox\M@contents\hbox{$\textstyle#1$}\M@draw}
{\setbox\M@contents\hbox{$\scriptstyle#1$}\M@draw}
{\setbox\M@contents\hbox{$\scriptscriptstyle#1$}\M@draw}}
\def\M@draw{
%	calculate the sizes
\M@height=\ht\M@contents
\M@depth=\dp\M@contents
\advance\M@height by 2pt
\advance\M@depth by 2pt
\M@total=\M@height
\advance\M@total by\M@depth
\ifdim\M@total<18pt\M@strength=0.4pt
  \else\ifdim\M@total<45pt\M@strength=0.55pt
    \else\M@strength=0.7pt\fi\fi
\ifdim\M@total<18pt\M@width=1pt
  \else\ifdim\M@total<45pt\M@width=1.5pt
    \else\M@width=2.5pt\fi\fi
%	build the boxes
\setbox\M@KV\hbox{%
   \hbox{\vrule height\M@height depth\M@depth width\M@strength}}
\setbox\M@KH\hbox{\lower\M@depth\hbox{\vbox to \M@total{%
  \hrule width\M@width height0pt depth\M@strength%
  \vfil%
  \hrule width\M@width height\M@strength depth0pt}}}
%	ship out
\,\mathopen{\copy\M@KV\copy\M@KH\copy\M@KV\copy\M@KH}\,
\box\M@contents
\,\mathclose{\copy\M@KH\copy\M@KV\box\M@KH\box\M@KV}\,
}
% end of meaning.sty

% Sample input
\documentstyle[meaning]{article}
\begin{document}
This line in normal textmode\(\Mean{1+1}\) and \( \Mean{1^2_6} \)
\[ \Mean{1} * \Mean{1^2_2} * \Mean{{1^2_2}^3_3} * \Mean{{{1^2_2}^3_3}^4_4}
* \Mean{{{{1^2_2}^3_3}^4_4}^5_5}
* \Mean{{{{{1^2_2}^3_3}^4_4}^5_5}^6_6}
* \Mean{{{{{{1^2_2}^3_3}^4_4}^5_5}^6_6}^7_7}
\]
\[ \Mean{\sum_{i=4}^17 \Phi_i}\]

\[
\Mean{\begin{array}{lll}
\Phi & \Psi & \Xi \\
\Phi & \Psi & \Xi \\
\Phi & \Psi & \Xi
\end{array}
}
+
\Mean{\begin{array}{lll}
\Phi & \Psi & \Xi \\
\Phi & \Psi & \Xi \\
\Phi & \Psi & \Xi \\
\Phi & \Psi & \Xi
\end{array}
}
\]


\[ \Mean{\begin{array}{l}3\\3\\3\end{array}
\Mean{1+1} * \Mean{\bigcup_{i=1..n}i}
\begin{array}{l}3\\3\\3\end{array}}
\]

\[ \Mean{17 + 4 - 1^{\Mean{3+6}}_{i_{\Mean{\delta-\epsilon}}} } * \Mean{789} \]
OK, it looks better on a high resolution printer ...
\end{document}
% end of sample input
-- 
 Ralf Treinen                         | email: treinen@cs.uni-sb.de          
 FB 14 - Informatik (Dept. of CS)     |
 Universitaet des Saarlandes          | phone: +49 681 302 2065
 W-6600 Saarbruecken , Germany        | fax:   +49 681 302 4421