I'm trying to make a little style package to make some nice blocks with icons and so on. I'm using environ
package + tikz
. Actually the document compiles and shows me my boxes but with errors saying that some environments are not closed.
I created a "iconbox" environment with environ
package that accepts some arguments (title, icon, colors...) and I want to use it to generalize some boxes: info
box, danger
box...
The problem begins when I want to create a new environment that uses the iconbox I've created.
If I want to use \NewEnviron
that calls another one, LaTeX crashes in recursion.
If I use the legacy newenvironment
so LaTeX says that I didn't close the iconbox block.
And of course, I tried \beginiconbox
and \endiconbox
in start and end block but it doesn't work.
Here is a "copy/paste" that should give you the problem
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{environ} % NewEnviron
\usepackage{fontawesome} % font awesome icons
%Options: Sonny, Lenny, Glenn, Conny, Rejne, Bjarne, Bjornstrup
\usepackage[Sonny]{fncychap}
\usepackage{tikz}
\usetikzlibrary{babel}
\usetikzlibrary{shadows.blur}
\usepackage{color}
\usepackage{pbsi} % for handwriting
\usepackage{bera}
\definecolor{m3dorange}{HTML}{ff9966}
\definecolor{m3dred}{HTML}{c9453e}
\definecolor{m3dgreen}{HTML}{4f9c45}
\definecolor{m3dblue}{HTML}{2499d0}
% title, icon, color, title color
\NewEnviron{iconbox}[4]{%
\begin{center}
\begin{tikzpicture}
\node [
top color=#3!10,
bottom color = white,
inner sep=2em,
rounded corners=1em,
draw=#3!60,
inner sep=1.2em,
text width=\textwidth*.7,
drop shadow = {opacity=.4},
shadow yshift = -4,
shadow xshift = 4,
font=\par\itshape
] (frame) at (0, 0) {\hspace{1.5em}\textbf{\bsifamily{\centering\Large\textcolor{#4}{#1}}}\vspace{.8em}\par\BODY};%
\node [
shape=circle,
top color=#4!90,
bottom color=white!50,
color=white,
circular drop shadow={opacity = .7},
font=\Huge,
inner sep=6pt] at (frame.north west) {\centering\textbf{#2}};
\end{tikzpicture}
\end{center}
}
\newenvironment{danger}[1]
{\begin{iconbox}{#1}{\faExclamation}{m3dorange}{red}}
{\end{iconbox}}
\newenvironment{success}[1]
{\begin{iconbox}{#1}{\faStickyNoteO}{m3dgreen}{m3dgreen}}
{\end{iconbox}}
\newenvironment{info}[1]
{\begin{iconbox}{#1}{\faBookmark}{m3dblue}{m3dblue}}
{\end{iconbox}}
\begin{document}
\begin{danger}{Warning}
You do it wrong.
\end{danger}
\end{document}
It generates that kind of box:
But... with errors...
So, how can I do ?
Thanks a lot.
tcolorbox
?tcolorbox
does not forbid you doing this.\end{iconbox}
because it is replaced by\end{danger}
which would expand to\end{iconbox}
. I am sure there are posts on this...)