summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/newenviron/newenviron-examples.tex
blob: 58b80bfea84d473a30470bb24c3d57c7a932281d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
\documentclass{article}
\usepackage{newenviron,xcolor}

% \envbody will always work for 'unnested' environments:

% \newenviron{assertion}{}{Assertion: \envbody}

% But if you intend to nest the environment, it will be safer to use
% \assertionbody:

\newenviron{assertion}{%
  % Test <start-code>. Note the doubling of the hash characters:
  \def\acmd##1{##1}% 
}{%
  \def\bcmd##1{##1}%
  Assertion: \assertionbody
}

\newenviron{outerassertion}{%
  % Put any start code here.
}{%
  \textcolor{blue}{Outer assertion:} %
  \begin{assertion}\outerassertionbody\end{assertion}%
}

\begin{document}

% Just for testing:
\EveryEndOfEnvironment{\def\ccmd#1{#1}}

\begin{assertion}
  test
\end{assertion}
\endgraf\bigskip

\begin{outerassertion}
  test2
\end{outerassertion}
\endgraf\bigskip

% Another test. Note the use of \usename{env-1body} and \usename{env-2body}:
\newenviron{env-1}[2][blue]{%
  \fboxrule=#2\relax
  \cptdimdef\temp{.5\textwidth-0.1cm*\currentgrouplevel}%
  \endgraf\noindent
  \fcolorbox{#1}{gray!10}{\parbox{\temp}{\textcolor{#1}{\usename{env-1body}}}}%
}{}
\newenviron*{env-2}[1][black]{%
  \noindent
  \fcolorbox{#1}{gray!30}{%
    \parbox{.7\textwidth}{%
      \leftskip=1cm
      \textcolor{#1}{\usename{env-2body}}%
    }%
  }%
}{%
  \def\testcmd##1{##1}%
}

\begin{env-2}[red]
  Outer box\endgraf
  \def\tempa#1{***#1***}\tempa{aa}%
  \endgraf\vspace*{5mm}%
  \begin{env-1}[blue]{1pt}%
    Inner box\endgraf\vspace*{5mm}%
    \def\tempa#1{+++#1+++}\tempa{bb}%
  \end{env-1}%
  \begin{env-1}[brown]{4pt}%
    Inner box\endgraf\vspace*{5mm}%
    \def\tempa#1{---#1---}\tempa{cc}%
  \end{env-1}%
\end{env-2}

\end{document}