Debian Codegraph @

texmf-dist/doc/latex/newenviron/newenviron-examples.tex

raw
1 \documentclass{article}
2 \usepackage{newenviron,xcolor}
3
4 % \envbody will always work for 'unnested' environments:
5
6 % \newenviron{assertion}{}{Assertion: \envbody}
7
8 % But if you intend to nest the environment, it will be safer to use
9 % \assertionbody:
10
11 \newenviron{assertion}{%
12 % Test <start-code>. Note the doubling of the hash characters:
13 \def\acmd##1{##1}%
14 }{%
15 \def\bcmd##1{##1}%
16 Assertion: \assertionbody
17 }
18
19 \newenviron{outerassertion}{%
20 % Put any start code here.
21 }{%
22 \textcolor{blue}{Outer assertion:} %
23 \begin{assertion}\outerassertionbody\end{assertion}%
24 }
25
26 \begin{document}
27
28 % Just for testing:
29 \EveryEndOfEnvironment{\def\ccmd#1{#1}}
30
31 \begin{assertion}
32 test
33 \end{assertion}
34 \endgraf\bigskip
35
36 \begin{outerassertion}
37 test2
38 \end{outerassertion}
39 \endgraf\bigskip
40
41 % Another test. Note the use of \usename{env-1body} and \usename{env-2body}:
42 \newenviron{env-1}[2][blue]{%
43 \fboxrule=#2\relax
44 \cptdimdef\temp{.5\textwidth-0.1cm*\currentgrouplevel}%
45 \endgraf\noindent
46 \fcolorbox{#1}{gray!10}{\parbox{\temp}{\textcolor{#1}{\usename{env-1body}}}}%
47 }{}
48 \newenviron*{env-2}[1][black]{%
49 \noindent
50 \fcolorbox{#1}{gray!30}{%
51 \parbox{.7\textwidth}{%
52 \leftskip=1cm
53 \textcolor{#1}{\usename{env-2body}}%
54 }%
55 }%
56 }{%
57 \def\testcmd##1{##1}%
58 }
59
60 \begin{env-2}[red]
61 Outer box\endgraf
62 \def\tempa#1{***#1***}\tempa{aa}%
63 \endgraf\vspace*{5mm}%
64 \begin{env-1}[blue]{1pt}%
65 Inner box\endgraf\vspace*{5mm}%
66 \def\tempa#1{+++#1+++}\tempa{bb}%
67 \end{env-1}%
68 \begin{env-1}[brown]{4pt}%
69 Inner box\endgraf\vspace*{5mm}%
70 \def\tempa#1{---#1---}\tempa{cc}%
71 \end{env-1}%
72 \end{env-2}
73
74 \end{document}