summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/newenviron/newenviron-examples.tex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/newenviron/newenviron-examples.tex
Initial commit
Diffstat (limited to 'macros/latex/contrib/newenviron/newenviron-examples.tex')
-rw-r--r--macros/latex/contrib/newenviron/newenviron-examples.tex74
1 files changed, 74 insertions, 0 deletions
diff --git a/macros/latex/contrib/newenviron/newenviron-examples.tex b/macros/latex/contrib/newenviron/newenviron-examples.tex
new file mode 100644
index 0000000000..58b80bfea8
--- /dev/null
+++ b/macros/latex/contrib/newenviron/newenviron-examples.tex
@@ -0,0 +1,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}