[Tex/LaTex] Stretchable square brackets outside math environment

brackets

I would like use stretchable square brackets outside of a math environment. Ideally, I would like to use \left[ blah \right. right in my text.

Is it possible ? How ?

Note : I would like to be able to include new environment in place of my "blah", like this :

\left[
\begin{array}{l}
    blah \\
    blah
\end{array}
\right.

Example #1 :

enter image description here

Best Answer

Here's another solution using TiKZ which gets you a look more or less as you describe.

Preamble

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\tikzset{
  grouping/.style={inner sep=2pt, baseline=0ex, left delimiter={[}},
  grouplabel/.style={anchor=west, yshift=0.125\baselineskip}
}

\newlength\groupinglength
\setlength\groupinglength{\textwidth}

\def\BEGIN #1 \END{%
  \bgroup
  \addtolength\groupinglength{-1ex}%
  \hspace*{1.5ex}%
  \tikz \node [grouping] {\hspace{-0.5ex}\parbox{\groupinglength}{#1}};%
  \egroup
}

\newcommand\labelledgroup[3]{%
  \begin{tikzpicture}[every left delimiter/.style={yshift=-0.1\baselineskip}]
    \addtolength\groupinglength{-1ex}%
    \node [grouping, inner ysep=0.5\baselineskip] (block) {%
      \parbox{\groupinglength}{#2}%
    };    
    \node [grouplabel] at (block.north west) {#1};
    \node [grouplabel] at (block.south west) {#3};
  \end{tikzpicture}%
}

\newcommand\IF[2]{\labelledgroup{if #1}{#2}{}}
\newcommand\ELSE[1]{\\[-0.6\baselineskip]\labelledgroup{else}{#1}{end}}

These definitions define macros to produce code blocks, which have a uniformly customizable delimiter on the left. Each distinct line of code, or code block, should be ended with an end-of-line. We define the \IF and \ELSE block in terms of a generic code block, which starts off (and conceivably ends, as well) with some label aligned with the top of the delimiter. You could use similar code to define a repeat ... until code block, or a procedure ... return block. The various dimensions were picked more or less arbitrarily, except for the cases of 0.5\baselineskip.

Document body

\begin{document}

\BEGIN 
  Get the height of the box \texttt{hBox} \\
  Get the width of the box \texttt{wBox} \\
  Get the length of the box \texttt{lBox} \\
  $\texttt{vol} = \texttt{hBox} \times \texttt{wBox} \times \texttt{lBox}$ \\
  \IF {$\texttt{vol} > 10$}%
    {Display \textit{``Your box is too big''}}  
  \ELSE
    {Display \textit{``Your box is right-sized''}}  \\
\END

\end{document}

As it's currently defined, \BEGIN ... \END will complain if there's a blank line. There are a few ways to get around that (e.g. simply by using different syntax); I've written it in this way instead to keep things simpler and to emulate some of the syntax for existing algorithm/pseudocode packages.

Result

typeset pseudocode

Edit the code (e.g. remove the "end" in the definition of \ELSE) and define other blocks (perhaps things like \FOR and \WHILE) to get the sort of algorithm presentation that you want.