% \iffalse meta-comment
%
% Copyright (C) 2014 by Dominik Siegel
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.2 of this license or (at your option) any later
% version. The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.2 or later is part of all distributions of
% LaTeX version 1999/12/01 or later.
%% 
%% To produce the documentation, do the following
%%
%%    latex chemschemex.dtx
%
% <package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
% <package>\ProvidesPackage{chemschemex}
% <package>[2014/07/15 v1.0]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{chemschemex}
\usepackage{caption}
\usepackage{float}
\newfloat{example}{htbp}{los}%
\floatname{example}{Example}%
\captionsetup{font={footnotesize},textfont={sf},labelfont={sf,bf}}
%\captionsetup[example]{singlelinecheck=false}
\usepackage{sectsty}
\usepackage[hidelinks]{hyperref}
\usepackage{fancyvrb}
\allsectionsfont{\sffamily}
\GetFileInfo{chemschemex.dtx}
\EnableCrossrefs
\CodelineIndex
\OnlyDescription
\RecordChanges
\newstruct[{R=H},{R=Me},{R=Ph}]{maleimid}{maleimid}{Maleimid}{}
\newstruct{cp}{cyclopentadiene}{Cyclopentadiene}{cp}
\newstruct[{R=H},{R=Me},{R=Ph}]{product}{}{}{}
\date{2014/07/15}
\begin{document}
    \DocInput{chemschemex.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.0}{2014/07/15}{Initial version}
%
% \GetFileInfo{chemschemex.sty}
%
%
% \title{The \CSX{} package\thanks{This document corresponds to \CSX{}~\fileversion{}, dated \filedate.}}
%
% \author{Dominik Siegel \\ \texttt{dominik.siegel@yahoo.de}}
% \newcommand{\CSX}{\textsf{chemschemex}}
% \newcommand{\FL}{\textsf{fancylabel}}
% \newcommand{\TikZ}{\textsf{Ti\emph{k}Z}}
% 
% \maketitle
%
% \begin{abstract}
% The \CSX{} package provides a comfortable method for the typesetting of (chemical) schemes based on \TikZ{} code, including an automatical structure referencing.
% \end{abstract}
%
% \begin{example}
% \begin{minipage}[c]{0.49\linewidth}
%     \begin{Chemscheme}
%         \struct{maleimid}
%         \RightArrow{\struct{cp}}{DEE}
%         \struct[80\,\%]{product}
%     \end{Chemscheme}
% \end{minipage}
% \begin{minipage}[c]{0.5\linewidth}
%\begin{verbatim}
%\begin{Chemscheme}
%   \struct{maleimid}
%   \RightArrow{\struct{cp}}{DEE}
%   \struct[80\,\%]{product}
%\end{Chemscheme}
%\end{verbatim}
% \end{minipage}
% \caption{Chemical scheme (left) produced by a simple code (right).}\label{fig.intro.1}
% \end{example}
%
% \tableofcontents
%
% \section{Introduction and motivation}
% While \LaTeX{} is a powerful tool for mathematical or physical issues the typesetting of chemistry derived problems is still a little bit annoying. When I wrote my thesis in organic chemistry I missed a package which produces chemical schemes as easy as you include a graphic into your document. I simply wanted to draw my structures in \textsc{ChemDraw}, inlcude them into my document and label them.
% 
% The packages \textsf{chemscheme} and \textsf{chemnum} offer a possibility to rerender image files for this purpose. Nevertheless, they only modify a scheme that already exists. This means, that arrows, margins, alignments and other parameters cannot be defined or changed globally in your document.
%
% By using the \TikZ{} and the \FL{} package (which has actually been written as slave of this package) the \CSX{} package meets all these requirements (see example \ref{fig.intro.1}).
%
%
%
% \section{Usage}
% \noindent\DescribeMacro{\usepackage}
% |\usepackage[<options>]{chemschemex}|\vspace{0.5em}
%
% \noindent The command above will load the \CSX{} package. It requires the packages \textsf{xkeyval}, \textsf{etextools}, \textsf{xargs}, \textsf{ifthen}, \textsf{suffix}, \TikZ{}, \textsf{graphicx}, and \FL{}. I strongly recommend to read the documentation of the \FL{} package because all referencing functions are provided by this package. It contains a lot of useful options that are not described in this documentation.
%
%
% \newpage
% \section{User commands}
%
% \subsection{Basic commands}
% \noindent\DescribeMacro{\customstruct}
% |\customstruct[<TikZ-capt>][<TikZ-obj>]{<capt>}{<obj>}|\vspace{0.5em}
%
% \noindent The |\customstruct| command typesets the object \textcolor{red}{|<obj>|} in the first row of a \TikZ{} matrix and the caption \textcolor{blue}{|<capt>|} in the second row. The caption is supposed to be given as comma-separated list of label(s) and text. The two optional arguments |<TikZ-capt>| and |<TikZ-obj>| can be used to pass options to \TikZ{} elements (for further information see section \ref{custom}). All the following structure commands are based on |\customstruct|.
%
% \begin{minipage}{0.27\linewidth}
% \begin{Chemscheme}
% \customstruct[nodes={draw=blue}]
%              [draw=red]
%              {{{label1:},{text}},{{ll2:},{a longer text}}}
%              {object e.g. image}
% \end{Chemscheme}
% \end{minipage}
% \begin{minipage}{0.6\linewidth}
% \begin{verbatim}
% \customstruct[nodes={draw=blue}][draw=red]
%              {{{label1:},{text}},
%               {{ll2:},{a longer text}}}
%              {object e.g. image}
% \end{verbatim}
% \end{minipage}
%
%
% \vspace{3ex}\noindent\DescribeMacro{\CSXimage}
% |\CSXimage[<img-opt>]{<img>}|\vspace{0.5em}
%
% \noindent The |\CSXimage| command includes the image |<img>| using the global options |<global-img-opt>| defined by the |image| option (see section \ref{image}) and the options given by |<img-opt>|. This command is used in all the following structure commands and expands to |\includegraphics[<global-img-opt>,<img-opt>]{<img>}|.
% 
%
%
% \subsection{Structure commands}
% \vspace{3ex}\noindent\DescribeMacro{\struct}
% |\struct[<capt>][<fam>][<img-opt>][<TikZ-capt>][<TikZ-obj>]{<img>}|\vspace{0.5em}
%
% \noindent The |\struct| command inlcudes the image |<img>|, sets a fancylabel (therefore it uses |<img>| as marker and |<fam>| as family, default: |<fam>|=|CSX|; the use of families is described in the \FL{} package) and prints it. If a |<caption>| is given, it will also print the caption behind the label. The macro |\CSXlabelsep| can be changed with the |labelseparator| option.
%
% \begin{minipage}{0.2\linewidth}
% \struct[text]{maleimid}
% \end{minipage}
% \begin{minipage}{0.79\linewidth}
% \begin{verbatim}
% \struct[text]{maleimid}
%    expands to:
% \customstruct{{{\fancylabel[CSX]{maleimid}\CSXlabelsep},{}}}
%              {\CSXimage{maleimid}}
% \end{verbatim}
% \end{minipage}
%
%
% \newpage
% \vspace{3ex}\noindent\DescribeMacro{\structalt}
% |\structalt[<capt>][<fam>][<img-opt>][<TikZ-capt>][<TikZ-obj>]{<img>}{<alt-img>}|\vspace{0.5em}
%
% \noindent The |\structalt| command includes an image |<alt-img>| but the labeling corresponds to |<img>|.
%
% \begin{minipage}{0.2\linewidth}
% \structalt{product}{product_num}
% \end{minipage}
% \begin{minipage}{0.7\linewidth}
% \begin{verbatim}
% \structalt{product}{product_num}
%    expands to:
% \customstruct{{{\fancylabel[CSX]{product}},{}}}
%              {\CSXimage{product_num}}
% \end{verbatim}
% \end{minipage}
%
%
% \vspace{3ex}\noindent\DescribeMacro{\struct*}
% \noindent\DescribeMacro{\structalt*}
% |\struct*[<capt>][<fam>][<img-opt>][<TikZ-capt>][<TikZ-obj>]{<img>}|\\
% |\structalt*[<capt>][<fam>][<img-opt>][<TikZ-capt>][<TikZ-obj>]{<img>}{<alt-img>}|\vspace{0.5em}
%
% \noindent The |\struct*| and |\structalt*| commands do the same as the corresponding nonstarred versions but use |\fancylabel*| instead of |\fancylabel|. This means, that a label for this structure will be defined but not printed.
%
% \begin{minipage}{0.2\linewidth}
% \struct*{maleimid}
% \end{minipage}
% \begin{minipage}{0.7\linewidth}
% \begin{verbatim}
% \struct*{maleimid}
%    expands to:
% \customstruct{{{\fancylabel*[CSX]{maleimid}},{}}}
%              {\CSXimage{maleimid}}
% \end{verbatim}
% \end{minipage}
%
%
% \vspace{3ex}\noindent\DescribeMacro{\struct-}
% |\struct-[<capt>][<img-opt>][<TikZ-capt>][<TikZ-obj>]{<img>}|\vspace{0.5em}
%
% \noindent The |\struct-| command includes an image |<img>| without any labeling.
%
% \begin{minipage}{0.2\linewidth}
% \struct-[text]{maleimid}
% \end{minipage}
% \begin{minipage}{0.7\linewidth}
% \begin{verbatim}
% \struct-[text]{maleimid}
%    expands to:
% \customstruct{{{},{text}}}
%              {\CSXimage{maleimid}}
% \end{verbatim}
% \end{minipage}
%
%
%
%
% \vspace{3ex}\noindent\DescribeMacro{\newstruct}
% |\newstruct[<sublabels>]{<img>}{<structname>}{<Structname>}{<abbr>}|\vspace{0.5em}
%
% \noindent If you want to use substructures you have to define them in the preamble. The optional argument |<sublabels>| is a comma-separated list of subcaptions. Whenever you want to refer to them you just have to use their numbers. In this example the first entry (|R=H|) gets the number 1, the second entry (|R=Me|) gets the number 2 and so on. If you use a structure without substructures it is not necessary to use |\newstruct|. However, the |\newstruct| command defines the name (and Name) und abbreviation of the structure what allows you to use the commands |\structname|, |\Structname| and |\structabbr| for this structure.\vspace{2ex}
%
% \begin{minipage}{0.9\linewidth}
% \begin{verbatim}
%\newstruct[{R=H},{R=Me},{R=Ph}]{product}{}{}{}
% \end{verbatim}
% \end{minipage}
%
% \vspace{3ex}\noindent\textbf{Note:} All of the following structure commands assume that |\newstruct| has been used for the filename |<img>| before.
%
% \vspace{3ex}\noindent\DescribeMacro{\Struct}
% |\Struct[<fam>][<img-opt>][<TikZ-capt>][<TikZ-obj>]{<sublabels>}{<img>}|\vspace{0.5em}
%
% \noindent To use the |\Struct| command, the structure and its substructure have to be defined by the |\newstruct| command. It inlcudes the image |<img>|, sets the sublabels given in the comma-separated list of |<sublabels>| and prints each sublabel with the subcaption previously given to the |\newstruct| command (one line per sublabel).
%
% \begin{minipage}{0.2\linewidth}
% \Struct{1,2,3}{product}
% \end{minipage}
% \begin{minipage}{0.7\linewidth}
% \begin{verbatim}
% \Struct{1,2,3}{product}
%    expands to:
% \customstruct{{{\fancysublabel[CSX]{product}{1}\CSXlabelsep},{R=H}},
%               {{\fancysublabel[CSX]{product}{2}\CSXlabelsep},{R=Me}},
%               {{\fancysublabel[CSX]{product}{3}\CSXlabelsep},{R=Ph}}}
%              {\CSXimage{product}}
% \end{verbatim}
% \end{minipage}
%
% \vspace{3ex}\noindent\DescribeMacro{\Struct*}
% |\Struct*[<fam>][<img-opt>][<TikZ-capt>][<TikZ-obj>]{<sublabels>}{<img>}|\vspace{0.5em}
%
% \noindent To use the |\Struct*| command, the structure and its substructure have to be defined by the |\newstruct| command. It inlcudes the image |<filename>|, sets the sublabels given in the comma-separated list of |<sublabels>| and prints each sublabel without its subcaption previously given to the |\newstruct| command.
%
% \begin{minipage}{0.2\linewidth}
% \Struct*{1,3}{product}
% \end{minipage}
% \begin{minipage}{0.7\linewidth}
% \begin{verbatim}
% \Struct*{1,3}{product}
%    expands to:
% \customstruct{{{\fancysublabel[CSX]{product}{1,3}},{}}}
%              {\CSXimage{product}}
% \end{verbatim}
% \end{minipage}
%
%
% \vspace{3ex}\noindent\DescribeMacro{\Structalt}
% |\Structalt[<fam>][<img-opt>][<TikZ-capt>][<TikZ-obj>]{<sublabels>}{<img>}{<alt-img>}|\vspace{0.5em}
%
% \noindent Works like the |\Struct| command but includes the image |<alt-img>|. Labeling corresponds to |<img>|.
%
%
% \vspace{3ex}\noindent\DescribeMacro{\Structalt*}
% |\Structalt*[<fam>][<img-opt>][<TikZ-capt>][<TikZ-obj>]{<sublabels>}{<img>}{<alt-img>}|\vspace{0.5em}
%
% \noindent Works like the |\Struct*| command but includes the image |<alt-img>|. Labeling corresponds to |<img>|.
%
%
% \vspace{3ex}\noindent\DescribeMacro{\structname}
% |\structname{<img>}|\vspace{0.5em}
%
% \noindent Prints the name of the structure |<img>| that has been previously defined by the |\newstruct| command. This command is recommended for the chemical name without a leading capital letter (inside a sentence).
%
%
% \vspace{3ex}\noindent\DescribeMacro{\Structname}
% |\Structname{<img>}|\vspace{0.5em}
%
% \noindent Prints the name of the structure |<img>| that has been previously defined by the |\newstruct| command. This command is recommended for the chemical name with a leading capital letter (at the beginning of a sentence).
%
%
% \vspace{3ex}\noindent\DescribeMacro{\structabbr}
% |\structabbr{<img>}|\vspace{0.5em}
%
% \noindent Prints the abbreviation of the structure |<img>| that has been previously defined by the |\newstruct| command.
%
%
%
%
% \subsection{The Chemscheme environment}
%
% \noindent\DescribeEnv{Chemscheme}
% |\begin{Chemscheme}...structure code...\end{Chemscheme}|\vspace{0.5em}
% 
% \noindent If a structure command appears outside a |Chemscheme| environment each command will typeset the image and caption in its own matrix. This causes no kind of adjustment.
%
% \begin{minipage}{0.3\linewidth}
% \struct{cp}
% \struct[long caption]{maleimid}
% \end{minipage}
% \begin{minipage}{0.59\linewidth}
% \begin{verbatim}
% \struct{cp}
% \struct[long caption]{maleimid}
% \end{verbatim}
% \end{minipage}
%
% \noindent But if structure commands appear inside a |Chemscheme| environment all images and captions are printed in one matrix. This causes adjustment of the image (by default center) and the caption row (by default top) according to the \TikZ{} style |CSXmatrix|.
%
%
% \begin{minipage}{0.3\linewidth}
% \begin{Chemscheme}
% \struct{cp}
% \struct[long caption]{maleimid}
% \end{Chemscheme}
% \end{minipage}
% \begin{minipage}{0.59\linewidth}
% \begin{verbatim}
% \begin{Chemscheme}
%    \struct{cp}
%    \struct[long caption]{maleimid}
% \end{Chemscheme}
% \end{verbatim}
% \end{minipage}
%
%
% \vspace{3ex}\noindent\DescribeMacro{\ChemschemeNextRow}
% |\ChemschemeNextRow[<row-sep>]|\vspace{0.5em}
%
% \noindent If you want to use the matrix adjustment over multiple lines you can produce a 'linebreak' using the |\ChemschemeNextRow| command. The optional argument |<row-sep>| allows you to define the space between the rows.
%
% \begin{minipage}[c]{0.49\linewidth}
%     \begin{Chemscheme}
%         \struct{maleimid}
%         \RightArrow{\struct{cp}}{DEE}
%         \struct[80\,\%]{product}
%         \ChemschemeNextRow[10pt]
%         \struct[80\,\%]{product}
%         \LeftArrow{\struct{cp}}{DEE}
%         \struct{maleimid}
%     \end{Chemscheme}
% \end{minipage}
% \begin{minipage}[c]{0.5\linewidth}
%\begin{verbatim}
%\begin{Chemscheme}
%   \struct{maleimid}
%   \RightArrow{\struct{cp}}{DEE}
%   \struct[80\,\%]{product}
%   \ChemschemeNextRow[10pt]
%   \struct[80\,\%]{product}
%   \LeftArrow{\struct{cp}}{DEE}
%   \struct{maleimid}
%\end{Chemscheme}
%\end{verbatim}
% \end{minipage}
%
% \begin{minipage}[c]{0.49\linewidth}
%     \begin{Chemscheme}
%         \struct{maleimid}
%         \RightArrow{\struct{cp}}{DEE}
%         \struct[80\,\%]{product}
%     \end{Chemscheme}
%     \begin{Chemscheme}
%         \struct[80\,\%]{product}
%         \LeftArrow{\struct{cp}}{DEE}
%         \struct{maleimid}
%     \end{Chemscheme}
% \end{minipage}
% \begin{minipage}[c]{0.5\linewidth}
%\begin{verbatim}
%\begin{Chemscheme}
%   \struct{maleimid}
%   \RightArrow{\struct{cp}}{DEE}
%   \struct[80\,\%]{product}
%\end{Chemscheme}
%\begin{Chemscheme}
%   \struct[80\,\%]{product}
%   \LeftArrow{\struct{cp}}{DEE}
%   \struct{maleimid}
%\end{Chemscheme}
%\end{verbatim}
% \end{minipage}
%
%
%
% \vspace{3ex}\noindent\DescribeMacro{\CSXcommands}
% |\CSXcommands{<TikZ-code>}|\vspace{0.5em}
%
% \noindent The |CSXcommands| macro allows you to draw any \TikZ{} element(s) after the typesetting of the structure matrix. 
%
% \hspace{-30pt}\begin{minipage}[c]{0.39\linewidth}
% \begin{Chemscheme}
%    \struct{maleimid}
%    \RightArrow{\struct{cp}}{DEE}
%    \Struct{1,2}{product}
%    \CSXcommands{\draw[->,CSXallarrows,draw=red]
%                         (Scheme\theCSXscheme Caption3Entry1.west) to 
%                         ([xshift=-8pt]Scheme\theCSXscheme Caption3Entry1.west) to 
%                         node[auto,swap,CSXlabelfont,red]{a}
%                         ([xshift=-8pt]Scheme\theCSXscheme Caption3Entry2.west) to 
%                         (Scheme\theCSXscheme Caption3Entry2.west);}
% \end{Chemscheme}
% \end{minipage}
% \begin{minipage}[c]{0.6\linewidth}
%\begin{verbatim}
%\begin{Chemscheme}
%    \struct{maleimid}
%    \RightArrow{\struct{cp}}{DEE}
%    \Struct{1,2}{product}
%    \CSXcommands{
%       \draw[->,CSXallarrows,draw=red]
%            (Scheme\theCSXscheme Caption3Entry1.west) to 
%            ([xshift=-8pt]Scheme\theCSXscheme Caption3Entry1.west) to 
%            node[auto,swap,CSXlabelfont,red]{a}
%            ([xshift=-8pt]Scheme\theCSXscheme Caption3Entry2.west) to 
%            (Scheme\theCSXscheme Caption3Entry2.west);
%    }
%\end{Chemscheme}
%\end{verbatim}
% \end{minipage}
% 
%
%
% \newpage
% \subsection{Ref commands}
% \noindent\DescribeMacro{\structref}
% \noindent\DescribeMacro{\structref*}
% \noindent\DescribeMacro{\structsubref}
% \noindent\DescribeMacro{\structsubref-}
% \noindent\DescribeMacro{\structsubref*}
% |\structref[<fam>]{<img>}|\\
% |\structref*[<fam>]{<img>}|\\
% |\structsubref[<fam>]{<img>}{<sublabels>}|\\
% |\structsubref-[<fam>]{<img>}{<sublabels>}|\\
% |\structsubref*[<fam>]{<img>}{<sublabels>}|\vspace{0.5em}
%
% \noindent The \CSX{} package defines ref commands that actually do exactly what their analogs from the \FL{} package do, but with |CSX| as default family.\footnote{For further information please have a look into the \textsf{fancylabel} package documentation.}
%
%
%
% \vspace{3ex}\noindent\DescribeMacro{\CSXstructref}
% \noindent The |\CSXstructref| macro allows you to change the style of all referencing commands that are shown above. The definition is shown below and may be changed as required.
%\begin{verbatim}
% \newcommand{\CSXstructref}[1]{%
%     % #1=fancyref command
%     \textbf{#1}%
% }
%\end{verbatim}
%
%
% \subsection{Arrows and simples}
%
% \noindent\DescribeMacro{\customarrow}
% |\customarrow[<length>]{<style>}{<upper-capt>}{<lower-capt>}|\vspace{0.5em}
%
% \noindent The basic command for arrows is the |\customarrow| command. If the optional argument |<length>| is used, the arrow will have this length. Otherwise the arrow is stretched to the length of the widest caption advanced by the length globally defined via the |arrowadvance| option. The style argument |<style>| allows you to pass options to the \TikZ{} |\draw| command.\vspace{1em}
%
% \begin{minipage}{0.25\linewidth}
% \customarrow{->,line width=1pt}{this is a long caption}{short}
% \end{minipage}
% \begin{minipage}{0.74\linewidth}
% \begin{verbatim}
% \customarrow{->,line width=1pt}
%             {this is a long caption}
%             {short}
% \end{verbatim}
% \end{minipage}
%
% \begin{minipage}{0.25\linewidth}
% \customarrow[60pt]{->,CSXarrowupper/.append style={red}}{this is a long caption}{short}
% \end{minipage}
% \begin{minipage}{0.74\linewidth}
% \begin{verbatim}
% \customarrow[60pt]
%             {->,CSXarrowupper/.append style={red}}
%             {this is a long caption}
%             {short}
% \end{verbatim}
% \end{minipage}
%
%
% \noindent\DescribeMacro{\RightArrow}
% \noindent\DescribeMacro{\<arrow-cmd>}
% |\RightArrow[<length>]{<upper-capt>}{<lower-capt>}|\\
% |\<arrow-cmd>[<length>]{<upper-capt>}{<lower-capt>}|\vspace{0.5em}
%
% \noindent The table below shows a couple of arrows that are based on the |\customarrow| command. You might define some other arrows using the |\CSXdeclarearrow| command.
% 
% {
% \newcommand{\CSXarrowtablex}[2][60pt]{
%    \CSXarrowtable[#1]{#2}
%    \CSXarrowtable[#1]{C#2}
%    \CSXarrowtable[#1]{S#2}
%    \CSXarrowtable[#1]{DS#2}
% }
% \newcommand{\CSXarrowtable}[2][60pt]{
%    \csname #2\endcsname[#1]{}{\textbackslash #2}
% }
% \def\CSXarrowadvance{0pt}
% \tikzset{%
%    CSXarrowfont/.style={%
%       font={\tiny\sffamily},%
%    },%
%    CSXmatrix/.style={%
%    column sep=20pt,%
%    row sep=5pt,%
%    }%
% }
% \begin{Chemscheme}
%    \CSXarrowtablex{RightArrow}\ChemschemeNextRow
%    \CSXarrowtablex{RightArrowDashed}
% \end{Chemscheme}
%
% \noindent All shown arrows have a normal, a crossed out (leading |C|), a striked out (leading |S|) and a double striked out (leading |DS|) version of the solid and the dashed (appending |Dashed|) arrow.
%
% \begin{Chemscheme}
%    \CSXarrowtable{RightArrow}
%    \CSXarrowtable{LeftArrow}
%    \CSXarrowtable{LeftRightArrow}\ChemschemeNextRow
%    \CSXarrowtable{DoubleRightArrow}
%    \CSXarrowtable{DoubleLeftArrow}
%    \CSXarrowtable{DoubleLeftRightArrow}\ChemschemeNextRow
%    \CSXarrowtable{RightupHarpoon}
%    \CSXarrowtable{RightdownHarpoon}
%    \CSXarrowtable{LeftupHarpoon}
%    \CSXarrowtable{LeftdownHarpoon}\ChemschemeNextRow
%    \CSXarrowtable{LeftupRightupHarpoon}
%    \CSXarrowtable{LeftupRightdownHarpoon}
%    \CSXarrowtable{LeftdownRightupHarpoon}
%    \CSXarrowtable{LeftdownRightdownHarpoon}\ChemschemeNextRow
%    \CSXarrowtable{Equilibrium}
%    \CSXarrowtable{RightEquilibrium}
%    \CSXarrowtable{RRightEquilibrium}
%    \CSXarrowtable{LeftEquilibrium}
%    \CSXarrowtable{LLeftEquilibrium}\ChemschemeNextRow
%    \CSXarrowtable{TwoRightArrow}
%    \CSXarrowtable{TTwoRightArrow}
%    \CSXarrowtable{TwoLeftArrow}
%    \CSXarrowtable{TTwoLeftArrow}\ChemschemeNextRow
%    \CSXarrowtable{ThreeRightArrow}
%    \CSXarrowtable{TThreeRightArrow}
%    \CSXarrowtable{ThreeLeftArrow}
%    \CSXarrowtable{TThreeLeftArrow}
% \end{Chemscheme}
% }
%
%
% \vspace{3ex}\noindent\DescribeMacro{\CSXdeclarearrow}
% |\CSXdeclarearrow{<arrow-cmd>}{<style>}|\vspace{0.5em}
%
% \noindent You can use the |\CSXdeclarearrow| command to declare arrows based on the customstruct command. The definition of |\RightArrow| is:
%
% \begin{verbatim}
% \CSXdeclarearrow{\RightArrow}{CSXnormalarrows,CSXRightArrow}
% \end{verbatim}
%
% \noindent Considering the default setting of |CSXnormalarrows| and |CSXRightArrow| this means:
%
% \begin{verbatim}
% \CSXdeclarearrow{\RightArrow}{line width=0.7pt,->}
% \end{verbatim}
%
%
% \noindent\DescribeMacro{\structplus}
% \noindent\DescribeMacro{\structminus}
% |\structplus|\\
% |\structminus|\vspace{0.5em}
%
% \noindent The simples (this is how I call arrow-like elements without a upper or lower caption) |\structplus| and |\structminus| can be used like any structure or arrow command:
%
% \begin{minipage}{0.59\linewidth}
% \begin{Chemscheme}
%    \struct{maleimid}
%    \structplus
%    \struct{cp}
%    \RightArrow{}{DEE}
%    \struct{product}
% \end{Chemscheme}
% \end{minipage}
% \begin{minipage}{0.35\linewidth}
% \begin{verbatim}
% \begin{Chemscheme}
%    \struct{maleimid}
%    \structplus
%    \struct{cp}
%    \RightArrow{}{DEE}
%    \struct{product}
% \end{Chemscheme}
% \end{verbatim}
% \end{minipage}
%
%
%
%
% \section{Options}
% \subsection{The image option}\label{image}
% \noindent\DescribeMacro{image=}
% |\usepackage[image={<global-img-opt>}]{chemschemex}|\vspace{0.5em}
%
% \noindent All structure commands except |\customstruct| internally use the |\CSXimage| command to include pictures with |\includegraphics|. The |image| option allows you to define options that will be passed to any image that is inserted via |\CSXimage|. The default value is |image={scale=0.7}|.
%
%
% \subsection{The labelseparator option}
% \noindent\DescribeMacro{labelseparator=}
% |\usepackage[labelseparator=<value>]{chemschemex}|\vspace{0.5em}
%
% \noindent The |<value>| given by the |labelseparator| option is set behind every |\fancylabel| inside a structure command if some text follows. The value is saved in |\CSXlabelsep|. The default value is |labelseparator={:\,}|.
%
%\begin{Chemscheme}
%   \struct[text]{maleimid}
%   \CSXcommands{%
%      \draw[<-,draw=red]([xshift=-2pt]Scheme\theCSXscheme Caption1Entry1.one split south)%
%           to  ([xshift=-2pt,yshift=-10pt]Scheme\theCSXscheme Caption1Entry1.one split south) node[yshift=-3pt,font={\tiny\sffamily}]{\textcolor{red}{labelseparator}};
%   }
%\end{Chemscheme}
%
%
%
%
% \subsection{The arrowadvance option}
% \noindent\DescribeMacro{arrowadvance=}
% |\usepackage[arrowadvance=<length>]{chemschemex}|\vspace{0.5em}
%
% \noindent Every arrow with undefined length argument will be as long as its widest caption plus the length given by the |arrowadvance| option. This is also the minimal length of an arrow (when no captions are given). The default value is |arrowadvance=10pt|.
%
%
%
%
% \section{Customization and advanced examples}
% \subsection{Predefined \TikZ{} styles}\label{custom}
%
% \noindent There are a lot of \TikZ{} styles that are already defined by the \CSX{} package. The following two examples show the code that is generated by \CSX{} and hopefully help you to understand the function of each style. Some of them can be changed (\textcolor{green!75!black}{green}), some of them must not be changed (\textcolor{red}{red}) to prevent strange results or even errors. If you want to change fonts please use the \textcolor{blue}{blue} coloured styles instead of appending |font=| to any style since this will cause wrong calculations. The \textcolor{orange}{orange} entries are styles that are optional arguments of |\customstruct|.
%
% \begin{minipage}{0.16\linewidth}
% \customstruct{{{text}}}{\CSXimage{maleimid}}
% \end{minipage}
% \begin{minipage}{0.7\linewidth}
% \begin{verbatim}
% \customstruct{{{text}}}{\CSXimage{maleimid}}
% \end{verbatim}
% \end{minipage}
% 
% \newcommand{\textred}[1]{\textcolor{red}{#1}}
% \newcommand{\textblue}[1]{\textcolor{blue}{#1}}
% \newcommand{\textorange}[1]{\textcolor{orange}{#1}}
% \newcommand{\textgreen}[1]{\textcolor{green!75!black}{#1}}
% \begin{Verbatim}[gobble=1,fontsize=\small,commandchars=!*~]
%\begin{tikzpicture}[!textgreen*CSX~]
%   \matrix [!textgreen*CSXmatrix~]{
%      % Image row
%      \node[!textorange*<TikZ-obj>~]
%           (Scheme1Image1)
%           {\CSXimage{maleimid}};\\
%      % Caption row
%      \node(Scheme1Caption1)
%           {\tikz[!textgreen*CSXcaption~,!textorange*<TikZ-capt>~]
%                 {\node[!textblue*CSXtextfont~,!textred*CSXsettextwidth~,!textgreen*CSXcaptionTextOnly~]
%                       (Scheme1Caption1Entry1)
%                       {text};
%                 }
%           };\\
%   };
%\end{tikzpicture}
% \end{Verbatim}
%
% 
%
% \vspace{3ex}\begin{minipage}{0.42\linewidth}
% \begin{Chemscheme}
%    \customstruct{{{text}}}{\CSXimage{maleimid}}
%    \RightArrow{\customstruct{{{1},{}}}{\CSXimage{cp}}}{DEE}   
%    \customstruct{{{label 1},{text 1}},
%                  {{label 2},{text 2}},
%                  {text 3}}
%                 {\CSXimage{product}}
% \end{Chemscheme}
% \end{minipage}
% \begin{minipage}{0.56\linewidth}
% \begin{verbatim}
% \begin{Chemscheme}
%    \customstruct{{{text}}}{\CSXimage{maleimid}}
%    \RightArrow{\customstruct{{{1},{}}}
%               {\CSXimage{cp}}}{DEE}   
%    \customstruct{{{label 1},{text 1}},
%                  {{label 2},{text 2}},
%                  {text 3}}
%                 {\CSXimage{product}}
% \end{Chemscheme}
% \end{verbatim}
% \end{minipage}
% 
% \begin{Verbatim}[gobble=1,fontsize=\small,commandchars=!*~]
%\begin{tikzpicture}[!textgreen*CSX~]
%   \matrix [!textgreen*CSXmatrix~]{
%      % Image row
%      \node[!textorange*<TikZ-obj>~]
%           (Scheme1Image1)
%           {\CSXimage{maleimid}};&
%      \node(Scheme1Image2)
%           {\hbox to <arrowlength>{}};&
%      \node[!textorange*<TikZ-obj>~]
%           (Scheme1Image3)
%           {\CSXimage{product}};\\
%      % Caption row
%      \node(Scheme1Caption1)
%           {\tikz[!textgreen*CSXcaption~,!textorange*<TikZ-capt>~]
%                 {\node[!textblue*CSXtextfont~,!textred*CSXsettextwidth~,!textgreen*CSXcaptionTextOnly~]
%                       (Scheme1Caption1Entry1)
%                       {text};
%                 }
%           };&
%      \node(Scheme1Caption2)
%           {};&
%      \node(Scheme1Caption3)
%           {\tikz[!textgreen*CSXcaption~,!textorange*<TikZ-capt>~]
%                 {\node[!textblue*CSXlabelfont~,!textred*CSXsetlabelwidth~,!textgreen*CSXcaptionLabelandText~,
%                        rectangle split,rectangle split horizontal,
%                        rectangle split parts=2,rectangle split part align=base,
%                        every two node part/.style={!textblue*CSXtextfont~,!textred*CSXsettextwidth~}]
%                       (Scheme1Caption3Entry1)
%                       {label 1\nodepart{two}text 1};
%                  \node[!textblue*CSXlabelfont~,!textred*CSXsetlabelwidth~,!textgreen*CSXcaptionLabelandText~,
%                        rectangle split,rectangle split horizontal,
%                        rectangle split parts=2,rectangle split part align=base,
%                        every two node part/.style={!textblue*CSXtextfont~,!textred*CSXsettextwidth~}
%                        below left=of Scheme1Caption3Entry1.one split south,
%                        anchor=one split north]
%                       (Scheme1Caption3Entry2)
%                       {label 2\nodepart{two}text 2};
%                  \node[!textblue*CSXtextfont~,!textred*CSXsettextwidth~,!textgreen*CSXcaptionTextOnly~%
%                        below=of Scheme1Caption3Entry2.south]
%                       (Scheme1Caption3Entry3)
%                       {text 3};
%                 }
%           };\\
%   };
%   \draw[!textgreen*CSXallarrows~,CSXRightArrow,text width=(<arrowlength>-\CSXarrowadvance)]
%        ([CSXshiftA]Scheme1Image2.west) to
%        node(Scheme1Image2Upper)
%            [!textblue*CSXarrowfont~,!textgreen*CSXarrowupper~,auto]
%            {\tikz[remember picture,!textgreen*CSXStructInArrow~]
%                  {\node[!textorange*<TikZ-obj>~]
%                        (Scheme1Image2UpperImage1)
%                        {\CSXimage{cp}};
%                   \node[below=of Scheme1Image2UpperImage1]
%                        (Scheme1Image2UpperCaption1)
%                        {\tikz[CSXcaption,!textorange*<TikZ-capt>~]
%                              {\node[!textblue*CSXlabelfont~,!textred*CSXsetlabelwidth~,
%                                     !textgreen*CSXcaptionLabelandText~,rectangle split,
%                                     rectangle split horizontal,
%                                     rectangle split parts=2,
%                                     rectangle split part align=base,
%                                     every two node part/.style={
%                                        !textblue*CSXtextfont~,
%                                        !textred*CSXsettextwidth~
%                                     }]
%                                    (Scheme1Image2UpperCaption1Entry1)
%                                    {1\nodepart{two}};
%                              }
%                        };
%                  }
%            }
%        node(Scheme1Image2Lower)
%            [!textblue*CSXarrowfont~,!textgreen*CSXarrowlower~,auto,swap]
%            {DEE}
%        ([CSXshiftB]Scheme1Image2.east);
%\end{tikzpicture}
% \end{Verbatim}
%
% \subsection{Style adjustment -- some examples}
%
% \noindent As already mentioned above, please use the styles \textblue{|CSXlabelfont|} and \textblue{|CSXtextfont|} for any changes of the node font. This is necessary to ensure correct measurements. For local font adjustment of captions in structure commands use the optional argument \textorange{|<TikZ-capt>|}. 
%
% \begin{minipage}{0.15\linewidth}
% \struct[text]{maleimid}
% \end{minipage}
% \begin{minipage}{0.75\linewidth}
% \begin{Verbatim}[gobble=1,fontsize=\small]
%\struct[text]{maleimid}
% \end{Verbatim}
% \end{minipage}
%
% \begin{minipage}{0.15\linewidth}
% \struct[text][][][CSXlabelfont/.style={red,font={\large}}]{maleimid}
% \end{minipage}
% \begin{minipage}{0.75\linewidth}
% \begin{Verbatim}[gobble=1,fontsize=\small]
%\struct[text]
%       []
%       []
%       [CSXlabelfont/.style={red,font={\large}}]
%       {maleimid}
% \end{Verbatim}
% \end{minipage}
%
% \begin{minipage}{0.15\linewidth}
% \struct[text][][][nodes={draw=green},CSXtextfont/.style={blue,font={\large}}]{maleimid}
% \end{minipage}
% \begin{minipage}{0.75\linewidth}
% \begin{Verbatim}[gobble=1,fontsize=\small]
%\struct[text]
%       []
%       []
%       [nodes={draw=green},
%        CSXtextfont/.style={blue,font={\large}}]
%       {maleimid}
% \end{Verbatim}
% \end{minipage}
%
% \begin{minipage}{0.15\linewidth}
% \struct[][][scale=1.5][][draw=red]{maleimid}
% \end{minipage}
% \begin{minipage}{0.75\linewidth}
% \begin{Verbatim}[gobble=1,fontsize=\small]
%\struct[][][scale=1.5][][draw=red]{maleimid}
% \end{Verbatim}
% \end{minipage}
%
%
% \subsection{Chemical mechanisms}
% \noindent For more complex chemical mechanisms you can either use the matrix provided by the |Chemscheme| environment or the internal commands |\CSXimage| and |\fancylabel|:
%
% {
%\tikzset{
%   CSXmatrix/.append style={
%      column sep=30pt,
%   }
%}
% \begin{Chemscheme}
%    \struct{R2-CH=CH-R1}
%    \struct{Ru=CH2}
%    \struct{R1-CH=CH2}\ChemschemeNextRow[20pt]
%    \struct{CH2=CH-R2}
%    \struct{Ru=CH-R1}
%    \struct{C2H4}
%    \CSXcommands{
%       \draw[->,draw=blue] (Scheme\theCSXscheme Image4)
%            to [bend right=90,distance=22pt] (Scheme\theCSXscheme Image1);
%       \draw[->,draw=red] (Scheme\theCSXscheme Image5)
%            to [bend right=-90,distance=22pt] (Scheme\theCSXscheme Image2);
%       \draw[->,draw=orange] (Scheme\theCSXscheme Image2)
%            to [bend right=-90,distance=22pt] (Scheme\theCSXscheme Image5);
%       \draw[->,draw=green!75!black] (Scheme\theCSXscheme Image3)
%            to [bend right=90,distance=22pt] (Scheme\theCSXscheme Image6);
%    }
% \end{Chemscheme}
% }
%
% \begin{Verbatim}[gobble=1,fontsize=\small,commandchars=?*~]
%\tikzset{CSXmatrix/.append style={column sep=30pt}}
%\begin{Chemscheme}
%   \struct{R2-CH=CH-R1}
%   \struct{Ru=CH2}
%   \struct{R1-CH=CH2}\ChemschemeNextRow[20pt]
%   \struct{CH2=CH-R2}
%   \struct{Ru=CH-R1}
%   \struct{C2H4}
%   \CSXcommands{
%      \draw[->,?textblue*draw=blue~] (Scheme\theCSXscheme Image4)
%           to [bend right=90,distance=22pt] (Scheme\theCSXscheme Image1);
%      \draw[->,?textred*draw=red~] (Scheme\theCSXscheme Image5)
%           to [bend right=-90,distance=22pt] (Scheme\theCSXscheme Image2);
%      \draw[->,?textorange*draw=orange~] (Scheme\theCSXscheme Image2)
%           to [bend right=-90,distance=22pt] (Scheme\theCSXscheme Image5);
%      \draw[->,?textgreen*draw=green!75!black~] (Scheme\theCSXscheme Image3)
%           to [bend right=90,distance=22pt] (Scheme\theCSXscheme Image6);
%   }
%\end{Chemscheme}
% \end{Verbatim}
% 
% \tikz[node distance=1pt,mycaption/.style={CSXlabelfont}]{
%    \node (n) at (0,2){\CSXimage{Ru=CH2}};
%    \node (ncapt) [mycaption,below=of n] {\fancylabel[CSX]{Ru=CH2}};
%    \node (s) at (0,-2){\CSXimage{Ru=CH-R1}};
%    \node (scapt) [mycaption,below=of s] {\fancylabel[CSX]{Ru=CH-R1}};
%    \node (nw) at (-4,1){\CSXimage{R2-CH=CH-R1}};
%    \node (nwcapt) [mycaption,below=of nw] {\fancylabel[CSX]{R2-CH=CH-R1}};
%    \node (sw) at (-4,-1){\CSXimage{CH2=CH-R2}};
%    \node (swcapt) [mycaption,below=of sw] {\fancylabel[CSX]{CH2=CH-R2}};
%    \node (ne) at (4,1){\CSXimage{R1-CH=CH2}};
%    \node (necapt) [mycaption,below=of ne] {\fancylabel[CSX]{R1-CH=CH2}};
%    \node (se) at (4,-1){\CSXimage{C2H4}};
%    \node (ecapt) [mycaption,below=of se] {\fancylabel[CSX]{C2H4}};
%    \node (w) at (-2.5,0) {};
%    \node (e) at (2.5,0) {};
%    \draw [->] (s) to [out=180,in=270] (w) to [out=90,in=180] (n);
%    \draw [->] (n) to [out=0,in=90] (e) to [out=270,in=0] (s);
%    \draw [->] (sw) to [out=0,in=270] (w) to [out=90,in=0] (nw);
%    \draw [->] (ne) to [out=180,in=90] (e) to [out=270,in=180] (se);
% }
%
% \begin{Verbatim}[gobble=1,fontsize=\small,commandchars=?*~]
% \tikz[node distance=1pt,mycaption/.style={CSXlabelfont}]{
%    \node (n) at (0,2){\CSXimage{Ru=CH2}};
%    \node (ncapt) [mycaption,below=of n] {\fancylabel[CSX]{Ru=CH2}};
%    \node (s) at (0,-2){\CSXimage{Ru=CH-R1}};
%    \node (scapt) [mycaption,below=of s] {\fancylabel[CSX]{Ru=CH-R1}};
%    \node (nw) at (-4,1){\CSXimage{R2-CH=CH-R1}};
%    \node (nwcapt) [mycaption,below=of nw] {\fancylabel[CSX]{R2-CH=CH-R1}};
%    \node (sw) at (-4,-1){\CSXimage{CH2=CH-R2}};
%    \node (swcapt) [mycaption,below=of sw] {\fancylabel[CSX]{CH2=CH-R2}};
%    \node (ne) at (4,1){\CSXimage{R1-CH=CH2}};
%    \node (necapt) [mycaption,below=of ne] {\fancylabel[CSX]{R1-CH=CH2}};
%    \node (se) at (4,-1){\CSXimage{C2H4}};
%    \node (ecapt) [mycaption,below=of se] {\fancylabel[CSX]{C2H4}};
%    \node (w) at (-2.5,0) {};
%    \node (e) at (2.5,0) {};
%    \draw [->] (s) to [out=180,in=270] (w) to [out=90,in=180] (n);
%    \draw [->] (n) to [out=0,in=90] (e) to [out=270,in=0] (s);
%    \draw [->] (sw) to [out=0,in=270] (w) to [out=90,in=0] (nw);
%    \draw [->] (ne) to [out=180,in=90] (e) to [out=270,in=180] (se);
% }
% \end{Verbatim}
%
%
%
% \StopEventually{}
%
% \section{The implementation}
% \subsection{Identification}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{chemschemex}[2014/07/15 v1.0 Typeset chemical schemes]
%    \end{macrocode}
%
% \subsection{Loading packages and define counter formats}
%    \begin{macrocode}
\RequirePackage{xkeyval}
\RequirePackage{etextools}
\RequirePackage{xargs}
\RequirePackage{ifthen}
\RequirePackage{suffix}
\RequirePackage{fancylabel}
\fancyref@DefineFamily{}{CSX}
\def\fancylabelformatCSX{\arabic{fancylabel}}%
\def\fancysublabelformatCSX{\arabic{fancylabel}\alph{fancysublabel}}%
\def\fancyonlysublabelformatCSX{\alph{fancysublabel}}%
\RequirePackage{graphicx}
\RequirePackage{tikz}
\usetikzlibrary{%   
   shapes.multipart,%
   decorations,%
   decorations.markings,%
   positioning,%
   arrows.meta%
}
%    \end{macrocode}
%
% \subsection{The options}
% \begin{macro}{image=}
%    \begin{macrocode}
\define@key{chemschemex}{image}{%
    % #1=additional options
    % #2=filename of the image
    \newcommand{\CSXimage}[2][]{%
        \includegraphics[#1,##1]{##2}%
    }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{labelseparator=}
%    \begin{macrocode}
\define@key{chemschemex}{labelseparator}{%
    \def\CSXlabelsep{#1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{arrowadvance=}
%    \begin{macrocode}
\define@key{chemschemex}{arrowadvance}{%
    \def\CSXarrowadvance{#1}%
}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
\presetkeys{chemschemex}{%
    image={scale=0.7},%
    labelseparator={:\,},%
    arrowadvance={10pt},%
}{}
\ProcessOptionsX<chemschemex>
%    \end{macrocode}
% \subsection{TikZ styles}
%    \begin{macrocode}
% TikZ styles that must not be changed
\tikzset{%
   CSXsettextwidth/.style={%
      text width=(%
         % if
         (\CSXtextwidth - \CSXimagewidth - \CSXmaxlabelwidth)>0%
         % then
         ?(\CSXimagewidth - \CSXmaxlabelwidth)%
         % else
         :(\CSXtextwidth+0.00001)%
      ),%
   },%
   CSXsetlabelwidth/.style={%
      text width=(%
         % if
         (\CSXlabelwidth)>0%
         % then
         ?(\CSXlabelwidth+0.00001)%
         % else
         :(0.00001)%
      ),%
   },%
   CSXshiftA/.style={},%
   CSXshiftB/.style={},%
   CSXshiftcompensation/.style={},%
}
% TikZ styles that can be changed
\tikzset{%
   % TikZ
   CSX/.style={%
      remember picture%
   },%
   % Matrix
   CSXmatrix/.style={%
      column sep=10pt,%
      row sep=4pt,%
      nodes={%
         inner xsep=0pt,%
         inner ysep=1pt,%
         outer sep=0pt%
      },%
      every odd row/.style={anchor=center},%
      every even row/.style={anchor=north},%
   },%
   % Structure caption
   CSXcaption/.style={%
      node distance=0pt,%
   },%
   CSXcaptionLabelandText/.style={%
      align=right,%
      every two node part/.style={%
         align=justify%
      },%
   },%
   CSXcaptionTextOnly/.style={%
      align=justify%
   },%
   % Fonts
   CSXlabelfont/.style={%
      font={\footnotesize\sffamily\bfseries}%
   },%
   CSXtextfont/.style={%
      font={\footnotesize\sffamily}%
   },%
   CSXarrowfont/.style={%
      font={\footnotesize\sffamily}%
   },%
   CSXsimple/.style={%
      x=3pt,%
      y=3pt,%
      line width=0.7pt%
   },%
   % Arrows
   CSXarrowupper/.style={%
      align=flush center,%
   },%
   CSXarrowlower/.style={%
      align=flush center%
   },%
   CSXStructInArrow/.style={%
      node distance=1pt,%
      text width=,%
      inner sep=0pt,%
      outer sep=0pt%
   },%
   CSXallarrows/.style={%
      x=1pt,y=1pt,%
      line width=0.7,%
      inner ysep=3,%
      >=Classical TikZ Rightarrow,%
   },%
   CSXdoublearrows/.style={%
      double distance=1.5,%
      >=Implies%
   },%   
   CSXharpoonup/.style={%
      >={Classical TikZ Rightarrow[harpoon]}%
   },%
   CSXharpoondown/.style={%
      >={Classical TikZ Rightarrow[harpoon,swap]}%
   },%
   CSXRightArrow/.style={%
      ->%
   },%
   CSXRightupHarpoon/.style={%
      ->[harpoon]%
   },%
   CSXRightdownHarpoon/.style={%
      ->[{harpoon,swap}]%
   },%
   CSXLeftArrow/.style={%
      <-%
   },%
   CSXLeftupHarpoon/.style={%
      <[{harpoon,swap}]-%
   },%
   CSXLeftdownHarpoon/.style={%
      <[harpoon]-%
   },%
   CSXLeftRightArrow/.style={%
      <->%
   },%
   CSXLeftupRightupHarpoon/.style={%
      <[{harpoon,swap}]->[harpoon]%
   },%
   CSXLeftupRightdownHarpoon/.style={%
      <[{harpoon,swap}]->[{harpoon,swap}]%
   },%
   CSXLeftdownRightupHarpoon/.style={%
      <[{harpoon}]->[{harpoon}]%
   },%
   CSXLeftdownRightdownHarpoon/.style={%
      <[{harpoon}]->[{harpoon,swap}]%
   },%
   CSXequilibrium/.style={%
      inner ysep/.expanded=(1+\pgfkeysvalueof{/pgf/inner ysep}),%
      CSXshiftA/.style={yshift=1},%
      CSXshiftB/.style={yshift=1},%
      CSXshiftcompensation/.style={yshift=-1},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw([yshift=-1]\CSXnodename .east) to%
                 ([yshift=-1]\CSXnodename .west);%
         }%
      }%
   },%
   CSXRightequilibrium/.style={%
      inner ysep/.expanded=(1+\pgfkeysvalueof{/pgf/inner ysep}),%
      CSXshiftA/.style={yshift=1},%
      CSXshiftB/.style={yshift=1},%
      CSXshiftcompensation/.style={yshift=-1},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw([yshift=-1,xshift=-0.25\CSXarrowlength]\CSXnodename .east) to%
                 ([yshift=-1,xshift=0.25\CSXarrowlength]\CSXnodename .west);%
         }%
      }%
   },%
   CSXLeftequilibrium/.style={%
      inner ysep/.expanded=(1+\pgfkeysvalueof{/pgf/inner ysep}),%
      CSXshiftA/.style={yshift=1,xshift=0.25\CSXarrowlength},%
      CSXshiftB/.style={yshift=1,xshift=-0.25\CSXarrowlength},%
      CSXshiftcompensation/.style={yshift=-1},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw([yshift=-1]\CSXnodename .east) to%
                 ([yshift=-1]\CSXnodename .west);%
         }%
      }%
   },%
   CSXslashtwoarrow/.style={%
      inner ysep/.expanded=(1.5+\pgfkeysvalueof{/pgf/inner ysep}),%
      CSXshiftA/.style={yshift=1.5,xshift=5},%
      CSXshiftB/.style={yshift=1.5},%
      CSXshiftcompensation/.style={yshift=-1.5,xshift=-2.5},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw([yshift=-1.5]\CSXnodename .west) to%
                 ([yshift=-1.5,xshift=-5]\CSXnodename .east);%
         }%
      }%
   },%
   CSXbackslashtwoarrow/.style={%
      inner ysep/.expanded=(1.5+\pgfkeysvalueof{/pgf/inner ysep}),%
      CSXshiftA/.style={yshift=1.5},%
      CSXshiftB/.style={yshift=1.5,xshift=-5},%
      CSXshiftcompensation/.style={yshift=-1.5,xshift=2.5},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw([yshift=-1.5,xshift=5]\CSXnodename .west) to%
                 ([yshift=-1.5]\CSXnodename .east);%
         }%
      }%
   },%
   CSXslashthreearrow/.style={%
      inner ysep/.expanded=(3+\pgfkeysvalueof{/pgf/inner ysep}),%
      CSXshiftA/.style={xshift=5},%
      CSXshiftB/.style={xshift=-5},%
      CSXshiftcompensation/.style={x=1.4,y=1.4},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw([yshift=3,xshift=10]\CSXnodename .west) to%
                 ([yshift=3]\CSXnodename .east);%
            \draw([yshift=-3]\CSXnodename .west) to%
                 ([yshift=-3,xshift=-10]\CSXnodename .east);%
         }%
      }%
   },%
   CSXbackslashthreearrow/.style={%
      inner ysep/.expanded=(3+\pgfkeysvalueof{/pgf/inner ysep}),%
      CSXshiftA/.style={xshift=5},%
      CSXshiftB/.style={xshift=-5},%
      CSXshiftcompensation/.style={x=1.4,y=1.4},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw([yshift=3]\CSXnodename .west) to%
                 ([yshift=3,xshift=-10]\CSXnodename .east);%
            \draw([yshift=-3,xshift=10]\CSXnodename .west) to%
                 ([yshift=-3]\CSXnodename .east);%
         }%
      }%
   },%
   CSXCrossArrow/.style={%
      inner ysep/.expanded=1.5+\pgfkeysvalueof{/pgf/inner ysep},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw[-,solid,CSXshiftcompensation](-3,-3)--(3,3);%
            \draw[-,solid,CSXshiftcompensation](3,-3)--(-3,3);%
         }%
      }%
   },%
   CSXStrikeArrow/.style={%
      inner ysep/.expanded=2+\pgfkeysvalueof{/pgf/inner ysep},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw[-,solid,CSXshiftcompensation](-2,-3.5)--(2, 3.5);%
         }%
      }%
   },%
   CSXDStrikeArrow/.style={%
      inner ysep/.expanded=2+\pgfkeysvalueof{/pgf/inner ysep},%
      postaction=decorate,%
      decoration={%
         markings,%
         mark=at position 0.5 with{%
            \draw[-,solid,xshift=-2,CSXshiftcompensation](-2,-3.5)--(2, 3.5);%
            \draw[-,solid,xshift=2,CSXshiftcompensation](-2,-3.5)--(2, 3.5);%
         }%
      }%
   }%
}
%    \end{macrocode}
% \subsection{Booleans, Lengths and Counters}
%    \begin{macrocode}
% Booleans
\newif\ifCSX@scheme\CSX@schemefalse % Is true, if the struct appears in a Chemscheme environment
\newif\ifCSX@generate@@@caption@% Is needed to get label and text out of the caption passed to customstruct
\newif\ifCSX@generate@@@caption@LastEntryWasTextOnly% Is needed to detect text-only caption entries
% Lengths
\newlength{\CSXimagewidth}\setlength{\CSXimagewidth}{0pt}
\newlength{\CSXlabelwidth}\setlength{\CSXlabelwidth}{0pt}
\newlength{\CSXmaxlabelwidth}\setlength{\CSXmaxlabelwidth}{0pt}
\newlength{\CSXtextwidth}\setlength{\CSXtextwidth}{0pt}
\newlength{\CSXmaxtextwidth}\setlength{\CSXmaxtextwidth}{0pt}
\newlength{\CSXarrowlength}\setlength{\CSXarrowlength}{0pt}
% Counters
\newcounter{CSXscheme}\setcounter{CSXscheme}{1}
\newcounter{CSXstruct}\setcounter{CSXstruct}{0}
\newcounter{CSXstructinarrow}\setcounter{CSXstructinarrow}{0}
\newcounter{CSXcaption}\setcounter{CSXcaption}{0}
%    \end{macrocode}
% \subsection{User macros}
% \begin{macro}{\newstruct}
%    \begin{macrocode}
\def\CSX@structlist@filenamesorted{}
\newcommand{\newstruct}[5][]{%
   % #1=comma-separated list of subcaptions
   % #2=filename
   % #3=structname
   % #4=Structname
   % #5=abbreviation
   \@ifundefined{CSX@newstruct@#2@structname}{%
      \global\@namedef{CSX@newstruct@#2@structname}{#3}%
      \global\@namedef{CSX@newstruct@#2@Structname}{#4}%
      \global\@namedef{CSX@newstruct@#2@abbreviation}{#5}%
      \ifthenelse{\equal{#1}{}}{}{%
         \setcounter{CSXcaption}{0}% No need to define a new counter, just use the CSXcaption
         \fancyref@foreach{\CSX@newsubstruct}{#2}{#1}%
      }%
      \AtBeginDocument{%
         \immediate\write\@auxout{%
            \string\fancyref@addtolist
               {\string{#2\string}}%
               {\string\CSX@structlist@filenamesorted}%
         }%
      }%
   }{%
      \PackageError{chemschemex}{Multiple definitions of '#2' by %
                                 \string\newstruct}{}%
   }%
}
\@onlypreamble\newstruct
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structname}
%    \begin{macrocode}
\DeclareRobustCommand{\structname}[1]{%
   \@ifundefined{CSX@newstruct@#1@structname}{%
      ???%
      \PackageWarning{chemschemex}{No structure '#1' defined by \string\newstruct}%
   }{%
      \ifthenelse{\equal{\@nameuse{CSX@newstruct@#1@structname}}{}}{%
         ???%
         \PackageWarning{chemschemex}{structname of structure '#1' is empty.}%
      }{%
         \@nameuse{CSX@newstruct@#1@structname}%
      }%
   }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Structname}
%    \begin{macrocode}
\DeclareRobustCommand{\Structname}[1]{%
   \@ifundefined{CSX@newstruct@#1@Structname}{%
      ???%
      \PackageWarning{chemschemex}{No structure '#1' defined by \string\newstruct}%
   }{%
      \ifthenelse{\equal{\@nameuse{CSX@newstruct@#1@Structname}}{}}{%
         ???%
         \PackageWarning{chemschemex}{Structname of structure '#1' is empty.}%
      }{%
         \@nameuse{CSX@newstruct@#1@Structname}%
      }%
   }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structabbr}
%    \begin{macrocode}
\DeclareRobustCommand{\structabbr}[1]{%
   \@ifundefined{CSX@newstruct@#1@abbreviation}{%
      ???%
      \PackageWarning{chemschemex}{No structure '#1' defined by \string\newstruct}%
   }{%
      \ifthenelse{\equal{\@nameuse{CSX@newstruct@#1@abbreviation}}{}}{%
         ???%
         \PackageWarning{chemschemex}{structabbr of structure '#1' is empty.}%
      }{%
         \@nameuse{CSX@newstruct@#1@abbreviation}%
      }%
   }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\customstruct}
%    \begin{macrocode}
\newcommandx\customstruct[4][1={},2={}]{%
   % #1=TikZ option for caption
   % #2=TikZ option for image
   % #3=caption
   % #4=image
   \customstruct@outarrow[#1][#2]{#3}{#4}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\struct}
%    \begin{macrocode}
\newcommandx\struct[6][1={},2=CSX,3={},4={},5={},usedefault]{%
   % #1=caption
   % #2=family
   % #3=image options
   % #4=TikZ option for caption
   % #5=TikZ option for image
   % #6=filename
   \@struct{#1}{#2}{#6}%
   \expandnext{\customstruct[#4][#5]}{\@@struct}{\CSXimage[#3]{#6}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structalt}
%    \begin{macrocode}
\newcommandx\structalt[7][1={},2=CSX,3={},4={},5={},usedefault]{%
   % #1=caption
   % #2=family
   % #3=image options
   % #4=TikZ option for caption
   % #5=TikZ option for image
   % #6=filename of the referenced image
   % #7=filename of the image shown instead of #6
   \@struct{#1}{#2}{#6}%
   \expandnext{\customstruct[#4][#5]}{\@@struct}{\CSXimage[#3]{#7}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\struct*}
%    \begin{macrocode}
\WithSuffix\newcommandx\struct*[6][1={},2=CSX,3={},4={},5={},usedefault]{%
   % #1=caption
   % #2=family
   % #3=image options
   % #4=TikZ option for caption
   % #5=TikZ option for image
   % #6=filename
   \@struct*{#1}{#2}{#6}%
   \expandnext{\customstruct[#4][#5]}{\@@struct}{\CSXimage[#3]{#6}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structalt*}
%    \begin{macrocode}
\WithSuffix\newcommandx\structalt*[7][1={},2=CSX,3={},4={},5={},usedefault]{%
   % #1=caption
   % #2=family
   % #3=image options
   % #4=TikZ option for caption
   % #5=TikZ option for image
   % #6=filename of the referenced image
   % #7=filename of the image shown instead of #6
   \@struct*{#1}{#2}{#6}%
   \expandnext{\customstruct[#4][#5]}{\@@struct}{\CSXimage[#3]{#7}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\struct-}
%    \begin{macrocode}
\WithSuffix\newcommandx\struct-[5][1={},2={},3={},4={},usedefault]{%
   % #1=caption
   % #2=image options
   % #3=TikZ option for caption
   % #4=TikZ option for image
   % #5=filename
   \expandnext{\customstruct[#3][#4]}{{{},{#1}}}{\CSXimage[#2]{#5}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Struct}
%    \begin{macrocode}
\newcommandx\Struct[6][1=CSX,2={},3={},4={},usedefault]{%
   % #1=family
   % #2=image options
   % #3=TikZ option for caption
   % #4=TikZ option for image
   % #5=list of sublabels previously defined with \newstruct
   % #6=filename
   \@Struct{#1}{#5}{#6}%
   \expandnext{\customstruct[#3][#4]}{\@@struct}{\CSXimage[#2]{#6}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Structalt}
%    \begin{macrocode}
\newcommandx\Structalt[7][1=CSX,2={},3={},4={},usedefault]{%
   % #1=family
   % #2=image options
   % #3=TikZ option for caption
   % #4=TikZ option for image
   % #5=list of sublabels previously defined with \newstruct
   % #6=filename of the referenced image
   % #7=filename of the image shown instead of #6
   \@Struct{#1}{#5}{#6}%
   \expandnext{\customstruct[#3][#4]}{\@@struct}{\CSXimage[#2]{#7}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Struct*}
%    \begin{macrocode}
\WithSuffix\newcommandx\Struct*[6][1=CSX,2={},3={},4={},usedefault]{%
   % #1=family
   % #2=image options
   % #3=TikZ option for caption
   % #4=TikZ option for image
   % #5=list of sublabels previously defined with \newstruct
   % #6=filename
   \@Struct*{#1}{#5}{#6}%
   \expandnext{\customstruct[#3][#4]}{\@@struct}{\CSXimage[#2]{#6}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Structalt*}
%    \begin{macrocode}
\WithSuffix\newcommandx\Structalt*[7][1=CSX,2={},3={},4={},usedefault]{%
   % #1=family
   % #2=image options
   % #3=TikZ option for caption
   % #4=TikZ option for image
   % #5=list of sublabels previously defined with \newstruct
   % #6=filename of the referenced image
   % #7=filename of the image shown instead of #6
   \@Struct*{#1}{#5}{#6}%
   \expandnext{\customstruct[#3][#4]}{\@@struct}{\CSXimage[#2]{#7}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structplus}
%    \begin{macrocode}
\newcommand{\structplus}{%
   \customstruct{}{\tikz[CSXsimple]{\draw[-](1,0)to(-1,0);\draw[-](0,1)to(0,-1);}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structminus}
%    \begin{macrocode}
\newcommand{\structminus}{%
   \customstruct{}{\tikz[CSXsimple]{\draw[-](1,0)to(-1,0);}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ChemschemeNextRow}
%    \begin{macrocode}
\def\ChemschemeNextRow@list{}%
\newcommand{\ChemschemeNextRow}[1][]{%
   \ExpandNext{\fancyref@addtolist}{\theCSXstruct}{\ChemschemeNextRow@list}%
   \expandafter\def\csname ChemschemeNextRow@\theCSXstruct\endcsname{#1}%
   \ignorespaces%
}
%    \end{macrocode}
% \end{macro}
% \begin{environment}{Chemscheme}
%    \begin{macrocode}
\newenvironment{Chemscheme}{%
   \CSX@schemetrue%
   \ignorespaces%
}{%
   \CSX@print%
   \CSX@schemefalse%
}
%    \end{macrocode}
% \end{environment}
% \begin{macro}{\structref}
%    \begin{macrocode}
\DeclareRobustCommand\structref[2][CSX]{%
    % #1=family
    % #2=label
    \CSXstructref{\fancyref[#1]{#2}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structref*}
%    \begin{macrocode}
\WithSuffix\DeclareRobustCommand\structref*[2][CSX]{%
    % #1=family
    % #2=label
    \CSXstructref{\fancyref*[#1]{#2}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structsubref}
%    \begin{macrocode}
\DeclareRobustCommand\structsubref[3][CSX]{%
    % #1=family
    % #2=label
    % #3=sublabel
    \CSXstructref{\fancysubref[#1]{#2}{#3}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structsubref-}
%    \begin{macrocode}
\WithSuffix\DeclareRobustCommand\structsubref-[3][CSX]{%
    % #1=family
    % #2=label
    % #3=sublabel
    \CSXstructref{\fancysubref-[#1]{#2}{#3}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\structsubref*}
%    \begin{macrocode}
\WithSuffix\DeclareRobustCommand\structsubref*[3][CSX]{%
    % #1=family
    % #2=label
    % #3=sublabel
    \CSXstructref{\fancysubref*[#1]{#2}{#3}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSXstructref}
%    \begin{macrocode}
\newcommand{\CSXstructref}[1]{%
    % #1=fancyref command
    \textbf{#1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSXcommands}
%    \begin{macrocode}
\newcommand{\CSXcommands}[1]{%
   \gappto\CSX@commands{#1}%
   \ignorespaces%
}
\def\CSX@commands{}%
%    \end{macrocode}
% \end{macro}
% \subsection{Helper macros}
% \begin{macro}{\CSX@newsubstruct}
%    \begin{macrocode}
\newcommand{\CSX@newsubstruct}[2]{%
   % #1=label
   % #2=caption
   \stepcounter{CSXcaption}%
   \xdef\chemschemes@getcountervalue{%
      \theCSXcaption%
   }%
   \expandafter\xdef\csname CSX@newstruct@#1@subcaption@%
                            \chemschemes@getcountervalue\endcsname{#2}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@customarrow@widestcaption}
%    \begin{macrocode}
\newcommand{\CSX@customarrow@widestcaption}[2]{%
   % #1=label
   % #2=style
   \pgfmathwidth{"%
      \noexpand\tikz[minimum width=0pt,inner sep=0pt,outer sep=0pt]{%
         \noexpand\node[\expandonce{#2}]{\noexpand#1};%
      }%
   "}%
   \pgfmathsetlength{\CSXlabelwidth}{\pgfmathresult}%
   \ifnum\CSXlabelwidth>\CSXarrowlength%
      \pgfmathsetlength{\CSXarrowlength}{\pgfmathresult}%
      \edef\CSX@arrowlength{\pgfmathresult}%
   \fi%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@savebox@set}
%    \begin{macrocode}
\def\CSX@savebox@set#1#2{%
   % #1=boxname
   % #2=box content
   \@ifundefined{#1}{%
      \expandnext{\newsavebox}{\csname #1\endcsname}%
   }{}
   \expandnext{\global\sbox}{\csname #1\endcsname}{#2}%
   \expandnext{\usebox}{\csname #1\endcsname}%
}% 
%    \end{macrocode}
% \end{macro}
% \begin{macro}{CSX@savebox@show}
%    \begin{macrocode}
\def\CSX@savebox@show#1#2{%
   % #1=boxname
   % #2=box content
   \expandnext{\usebox}{\csname #1\endcsname}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\customarrow}
%    \begin{macrocode}
\newcommand{\customarrow}[4][\the\CSXarrowlength]{%
   % #1=length
   % #2=arrow style
   % #3=upper text
   % #4=lower text
   \stepcounter{CSXstruct}%
   % Measure upper und lower text
   \setlength{\CSXarrowlength}{0pt}%
   \def\CSX@nodename{Scheme\theCSXscheme Image\theCSXstruct}%
   \def\CSXcustomarrow@uppertext{%
      \let\customstruct\customstruct@inarrow%
      \def\customstruct@inarrow@nodename{\CSX@nodename Upper}%
      #3%
      \let\customstruct\customstruct@outarrow%
   }%
   \def\CSXcustomarrow@lowertext{%
      \let\customstruct\customstruct@inarrow%
      \def\customstruct@inarrow@nodename{\CSX@nodename Lower}%
      #4%
      \let\customstruct\customstruct@outarrow%
   }%
   \let\CSX@savebox\CSX@savebox@set%
   \edef\CSX@arrowlength{0}%
   \CSX@customarrow@widestcaption{\CSXcustomarrow@uppertext}{CSXarrowfont,CSXarrowupper}%
   \CSX@customarrow@widestcaption{\CSXcustomarrow@lowertext}{CSXarrowfont,CSXarrowlower}%
   \let\CSX@savebox\CSX@savebox@show%
   % Set matrix entries
   \pgfmathsetlength{\CSXarrowlength}{\CSX@arrowlength + \CSXarrowadvance}%
   \edef\customarrow@temp{%
      % Reserve space in matrix
      \noexpand\node(\CSX@nodename)%
                    {\noexpand\hbox to #1{}};%
      % Add arrow command
      \noexpand\CSXcommands{%
         \noexpand\pgfmathsetlength{\noexpand\CSXarrowlength}{#1}%
         \noexpand\def\noexpand\CSXnodename{\CSX@nodename}%
         \noexpand\draw [text width=(#1-\CSXarrowadvance),#2]%
            ([CSXshiftA]\noexpand\CSXnodename .west) to%
               node (\noexpand\CSXnodename Upper)%
                    [CSXshiftcompensation,CSXarrowfont,CSXarrowupper,auto]%
                    {\expandonce\CSXcustomarrow@uppertext}%
               node (\noexpand\CSXnodename Lower)%
                    [CSXshiftcompensation,CSXarrowfont,CSXarrowlower,auto,swap]%
                    {\expandonce\CSXcustomarrow@lowertext}%
            ([CSXshiftB]\noexpand\CSXnodename .east);%
      }%
   }%
   \expandnext{\expandafter\gdef\csname CSX@list@image@\theCSXstruct\endcsname}{%
      \customarrow@temp%
   }%
   \expandafter\gdef\csname CSX@list@caption@\theCSXstruct\endcsname{%
      \node(Scheme\theCSXscheme Caption\theCSXstruct){};%
   }%
   \ifCSX@scheme%
      % Inside Chemscheme environment
   \else%
      % Outside Chemscheme environment
      \CSX@print%
   \fi%
   \ignorespaces%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSXdeclarearrow}
%    \begin{macrocode}
\newcommand{\CSXdeclarearrow}[2]{%
   % #1=macro name
   % #2=TikZ style
   \newcommand{#1}[3][\the\CSXarrowlength]{%
      % ##1=length
      % ##2=upper caption
      % ##3=lower caption
      \customarrow[##1]{#2}{##2}{##3}%
   }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSXdeclarearrowbundle}
%    \begin{macrocode}
\newcommand{\CSXdeclarearrowbundle}[2]{%
   % #1=macro name
   % #2=TikZ style
   % normal
   \CSX@declarearrowbundle{#1}{#2}%
   % dashed
   \CSX@declarearrowbundle{#1Dashed}{#2,dashed}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@declarearrowbundle}
%    \begin{macrocode}
\newcommand{\CSX@declarearrowbundle}[2]{%
   % #1=macro name
   % #2=TikZ style
   % normal arrow
   \expandnext{\CSXdeclarearrow}{\csname #1\endcsname}{#2}%
   % crossed out arrow
   \expandnext{\CSXdeclarearrow}{\csname C#1\endcsname}{#2,CSXCrossArrow}%
   % striked out arrow
   \expandnext{\CSXdeclarearrow}{\csname S#1\endcsname}{#2,CSXStrikeArrow}%
   % Double striked out arrow
   \expandnext{\CSXdeclarearrow}{\csname DS#1\endcsname}{#2,CSXDStrikeArrow}%
}
% Normal arrows
\CSXdeclarearrowbundle{RightArrow}{CSXallarrows,CSXRightArrow}
\CSXdeclarearrowbundle{LeftArrow}{CSXallarrows,CSXLeftArrow}
\CSXdeclarearrowbundle{LeftRightArrow}{CSXallarrows,CSXLeftRightArrow}
% Double arrow
\CSXdeclarearrowbundle{DoubleRightArrow}{CSXallarrows,CSXdoublearrows,CSXRightArrow}
\CSXdeclarearrowbundle{DoubleLeftArrow}{CSXallarrows,CSXdoublearrows,CSXLeftArrow}
\CSXdeclarearrowbundle{DoubleLeftRightArrow}{CSXallarrows,CSXdoublearrows,CSXLeftRightArrow}
% Single harpoons
\CSXdeclarearrowbundle{RightupHarpoon}{CSXallarrows,CSXRightupHarpoon}
\CSXdeclarearrowbundle{RightdownHarpoon}{CSXallarrows,CSXRightdownHarpoon}
\CSXdeclarearrowbundle{LeftupHarpoon}{CSXallarrows,CSXLeftupHarpoon}
\CSXdeclarearrowbundle{LeftdownHarpoon}{CSXallarrows,CSXLeftdownHarpoon}
\CSXdeclarearrowbundle{LeftupRightupHarpoon}{CSXallarrows,CSXLeftupRightupHarpoon}
\CSXdeclarearrowbundle{LeftupRightdownHarpoon}{CSXallarrows,CSXLeftupRightdownHarpoon}
\CSXdeclarearrowbundle{LeftdownRightupHarpoon}{CSXallarrows,CSXLeftdownRightupHarpoon}
\CSXdeclarearrowbundle{LeftdownRightdownHarpoon}{CSXallarrows,CSXLeftdownRightdownHarpoon}
% Equilibrium
\CSXdeclarearrowbundle{Equilibrium}{CSXallarrows,CSXequilibrium,CSXRightupHarpoon}
\CSXdeclarearrowbundle{RightEquilibrium}{CSXallarrows,CSXRightequilibrium,CSXRightupHarpoon}
\CSXdeclarearrowbundle{LeftEquilibrium}{CSXallarrows,CSXLeftequilibrium,CSXRightupHarpoon}
\CSXdeclarearrowbundle{RRightEquilibrium}{CSXallarrows,CSXLeftequilibrium,CSXLeftupHarpoon}
\CSXdeclarearrowbundle{LLeftEquilibrium}{CSXallarrows,CSXRightequilibrium,CSXLeftupHarpoon}
% Two Arrows
\CSXdeclarearrowbundle{TwoRightArrow}{CSXallarrows,CSXslashtwoarrow,CSXRightArrow}
\CSXdeclarearrowbundle{TTwoRightArrow}{CSXallarrows,CSXbackslashtwoarrow,CSXRightArrow}
\CSXdeclarearrowbundle{TwoLeftArrow}{CSXallarrows,CSXslashtwoarrow,CSXLeftArrow}
\CSXdeclarearrowbundle{TTwoLeftArrow}{CSXallarrows,CSXbackslashtwoarrow,CSXLeftArrow}
% Three Arrows
\CSXdeclarearrowbundle{ThreeRightArrow}{CSXallarrows,CSXslashthreearrow,CSXRightArrow}
\CSXdeclarearrowbundle{TThreeRightArrow}{CSXallarrows,CSXbackslashthreearrow,CSXRightArrow}
\CSXdeclarearrowbundle{ThreeLeftArrow}{CSXallarrows,CSXslashthreearrow,CSXLeftArrow}
\CSXdeclarearrowbundle{TThreeLeftArrow}{CSXallarrows,CSXbackslashthreearrow,CSXLeftArrow}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@struct}
%    \begin{macrocode}
\newcommand{\@struct}[3]{%
   % #1=caption
   % #2=family
   % #3=filename
   \ifthenelse{\equal{#1}{}}{%
      \def\@@struct{{{\fancylabel[#2]{#3}},{}}}%
   }{%
      \def\@@struct{{{\def\fancylabelShowLabelEvent{\CSXlabelsep}\fancylabel[#2]{#3}},{#1}}}%
   }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@struct*}
%    \begin{macrocode}
\WithSuffix\newcommand\@struct*[3]{%
   % #1=caption
   % #2=family
   % #3=filename
   \def\@@struct{{{\fancylabel*[#2]{#3}},{#1}}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@Struct}
%    \begin{macrocode}
\newcommand\@Struct[3]{%
   % #1=family
   % #2=list of sublabels previously defined with \newstruct
   % #3=filename
   % Use the sort-function of the fancylabel package to sort the label-list
   \def\@@struct{}%
   \def\fancyref@@@@@sort{fancyref@PrevRun@#1@#3@\fancyref@@sort@value}%
   \def\fancyref@sort@list{}%
   \def\fancyref@sort@labellist@unsorted{}%
   \fancyref@sort{#2}%
   \expandnext{\fancyref@addtolist}%
              {\fancyref@sort@labellist@unsorted}%
              {\fancyref@sort@list}%
   \edef\CSX@sorted@list{\fancyref@sort@list}%
   % Generate the caption
   \def\@Struct@family{#1}%
   \def\@Struct@filename{#3}%
   \expandnext{\fancyref@foreach{\@@Struct}{}}{\CSX@sorted@list}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@@Struct}
%    \begin{macrocode}
\newcommand{\@@Struct}[2]{%
   % #1=
   % #2=sublabel
   \@ifundefined{CSX@newstruct@\@Struct@filename @subcaption@#2}{%
      \PackageError{chemschemex}{Substructure '#2' not defined as %
                                 substructure of '\@Struct@filename '. %
                                 Use the \noexpand\newstruct  command for %
                                 the definition of substructures.}{}%
    }{%
      \fancyref@addtolist{%
         {{\def\fancylabelShowLabelEvent{\CSXlabelsep}\fancysublabel[\@Struct@family]{\@Struct@filename}{#2}},%
          {\@nameuse{CSX@newstruct@\@Struct@filename @subcaption@#2}}}}%
         {\@@struct}%
    }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@Struct*}
%    \begin{macrocode}
\WithSuffix\newcommand\@Struct*[3]{%
   % #1=family
   % #2=list of sublabels previously defined with \newstruct
   % #3=filename
   \def\@@struct{{{\fancysublabel[#1]{#3}{#2}},{}}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\customstruct@outarrow}
%    \begin{macrocode}
\newcommandx\customstruct@outarrow[4][1={},2={}]{%
   % #1=TikZ option for caption
   % #2=TikZ option for image
   % #3=caption
   % #4=image
   \stepcounter{CSXstruct}%
   % Set Image
   \edef\customstruct@outarrow@temp{%
      \noexpand\node[\expandonce{#2}](Scheme\theCSXscheme Image\theCSXstruct){\expandonce{#4}};%
   }%
   \expandnext{\expandafter\gdef\csname CSX@list@image@\theCSXstruct\endcsname}{%
      \customstruct@outarrow@temp%
   }%
   % Generate caption
   \CSXgeneratecaption{#3}{#4}{Scheme\theCSXscheme Caption\theCSXstruct}{#1}%
   % Set caption
   \edef\customstruct@outarrow@temp{%
      \noexpand\node(Scheme\theCSXscheme Caption\theCSXstruct){%
         \noexpand\tikz[CSXcaption,\expandonce{#1}]{%
            \expandonce\CSXcaption%
         }%
      };%
   }%   
   \expandnext{\expandafter\gdef\csname CSX@list@caption@\theCSXstruct\endcsname}{%
      \customstruct@outarrow@temp%
   }%
   \ifCSX@scheme%
      % Inside Chemscheme environment
   \else%
      % Outside Chemscheme environment
      \CSX@print%
   \fi%
   \ignorespaces%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\customstruct@inarrow}
%    \begin{macrocode}
\newcommandx\customstruct@inarrow[4][1={},2={}]{%
   % #1=TikZ option for caption
   % #2=TikZ option for image
   % #3=caption
   % #4=image
   \stepcounter{CSXstructinarrow}%
   \CSXgeneratecaption{#3}{#4}{\customstruct@inarrow@nodename Caption\theCSXstructinarrow}{#1}%
   \ifthenelse{\CSXmaxlabelwidth=0 \AND \CSXmaxtextwidth=0}{%
      \edef\customstruct@inarrow@temp{%
         \noexpand\tikz[remember picture,CSXStructInArrow]{%
            \noexpand\node [\expandonce{#2}]%
                           (\customstruct@inarrow@nodename Image\theCSXstructinarrow)%
                           {\expandonce{#4}};%
         }%
      }%
   }{%
      \edef\customstruct@inarrow@temp{%
         \noexpand\tikz[remember picture,CSXStructInArrow,%
                        baseline=(\CSX@generate@caption@captionname Entry\theCSXcaption .base)]{%
            \noexpand\node [\expandonce{#2}]%
                           (\customstruct@inarrow@nodename Image\theCSXstructinarrow)%
                           {\expandonce{#4}};%
            \noexpand\node [below=of \customstruct@inarrow@nodename Image\theCSXstructinarrow]%
                           (\customstruct@inarrow@nodename Caption\theCSXstructinarrow)%
                           {\noexpand\tikz[CSXcaption,\expandonce{#1}]{\expandonce\CSXcaption}};%
         }%
      }%
   }%
   \expandnext{\CSX@savebox{CSX@savebox@\theCSXstructinarrow}}{%
      \customstruct@inarrow@temp%
   }%
   \ignorespaces%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSXgeneratecaption}
%    \begin{macrocode}
\newcommand{\CSXgeneratecaption}[4]{%
   % #1=list of labels and text: {{label1},{text1}},{{label2},{text2}},...
   % #2=Image
   % #3=caption name
   % #4=caption style
   \setcounter{CSXcaption}{0}%
   \setlength{\CSXmaxlabelwidth}{0pt}%
   \setlength{\CSXmaxtextwidth}{0pt}%
   \def\CSXcaption{}%
   \def\CSX@generate@caption@image{#2}%
   \def\CSX@generate@caption@captionname{#3}%
   \def\CSX@generate@caption@captionstyle{CSXcaption,#4}%
   \CSX@generate@@@caption@true%
   \ifthenelse{\equal{#1}{}}{}{%
      \expandnext\expandnext\expandnext{%
         \fancyref@foreach{\CSX@generate@@caption}{}%
      }{#1}%
   }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@generate@@caption}
%    \begin{macrocode}
\newcommand{\CSX@generate@@caption}[2]{%
   % #1=
   % #2=label and text: {label1},{text1}
   \edef\CSX@generate@@@caption@lastCSXcaption{\theCSXcaption}%
   \stepcounter{CSXcaption}%
   \fancyref@foreach{\CSX@generate@@@caption}{}{#2}%
   % Execute text-only event
   \ifCSX@generate@@@caption@\else%
      \CSX@generate@@@caption@TextOnly%
         {\CSX@generate@caption@image}%
         {\CSX@generate@caption@captionname Entry\theCSXcaption}%
         {\CSX@generate@caption@captionname Entry\CSX@generate@@@caption@lastCSXcaption}%
         {\CSX@generate@@@caption@label}%
      \CSX@generate@@@caption@true%
   \fi%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@generate@@@caption}
%    \begin{macrocode}
\newcommand{\CSX@generate@@@caption}[2]{%
   % #1=
   % #2=label or text: label1 or text1
   \ifCSX@generate@@@caption@%
      % Label
      \def\CSX@generate@@@caption@label{#2}%
      \CSX@generate@@@caption@false%
   \else%
      % Text and execute label-and-text event
      \def\CSX@generate@@@caption@text{#2}%
      \CSX@generate@@@caption@LabelAndText%
         {\CSX@generate@caption@image}%
         {\CSX@generate@caption@captionname Entry\theCSXcaption}%
         {\CSX@generate@caption@captionname Entry\CSX@generate@@@caption@lastCSXcaption}%
         {\CSX@generate@@@caption@label}%
         {\CSX@generate@@@caption@text}%
      \CSX@generate@@@caption@true%
      \def\CSX@generate@@@caption@label{}%
      \def\CSX@generate@@@caption@text{}%
   \fi%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@setimagewidth}
%    \begin{macrocode}
\newcommand{\CSX@setimagewidth}[1]{%
   % #1=image
   \pgfmathwidth{"%
      \noexpand\tikz[minimum width=0pt,inner sep=0pt,outer sep=0pt]{%
         \noexpand\node{\noexpand#1};%
      }%
   "}%
   \edef\CSX@imagewidth{\pgfmathresult}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@setmaxlabelwidth}
%    \begin{macrocode}
\newcommand{\CSX@setmaxlabelwidth}[1]{%
   % #1=label
   \pgfmathwidth{"%
      \noexpand\tikz[\expandonce\CSX@generate@caption@captionstyle ,minimum width=0pt,inner sep=0pt,outer sep=0pt]{%
         \noexpand\node[CSXlabelfont]{\noexpand#1};%
      }%
   "}%
   \pgfmathsetlength{\CSXlabelwidth}{\pgfmathresult}%
   \edef\CSX@labelwidth{\pgfmathresult}%
   \ifnum\CSXlabelwidth<\CSXmaxlabelwidth%
   \else%
      \pgfmathsetlength{\CSXmaxlabelwidth}{\pgfmathresult}%
      \edef\CSX@maxlabelwidth{\pgfmathresult}%
   \fi%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@settextwidth}
%    \begin{macrocode}
\newcommand{\CSX@settextwidth}[1]{%
   % #1=text
   \pgfmathwidth{"%
      \noexpand\tikz[\expandonce\CSX@generate@caption@captionstyle ,minimum width=0pt,inner sep=0pt,outer sep=0pt]{%
         \noexpand\node[CSXtextfont]{\noexpand#1};%
      }%
   "}%
   \pgfmathsetlength{\CSXtextwidth}{\pgfmathresult}%
   \edef\CSX@textwidth{\pgfmathresult}%
   \ifnum\CSXtextwidth<\CSXmaxtextwidth%
   \else%
      \pgfmathsetlength{\CSXmaxtextwidth}{\pgfmathresult}%
      \edef\CSX@maxtextwidth{\pgfmathresult}%
   \fi%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@setvphantom}
%    \begin{macrocode}
\newcommand{\CSX@setvphantom}{%
   \ifdim\CSXlabelwidth=0pt%
      \ifdim\CSXtextwidth=0pt%
         \def\CSX@vphantom{}%
      \else%
         \def\CSX@vphantom{font/.expand once={\tikz@textfont\vphantom{Ag}}}%
      \fi%
   \else%
      \def\CSX@vphantom{font/.expand once={\tikz@textfont\vphantom{Ag}}}%
   \fi%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@generate@@@caption@LabelAndText}
%    \begin{macrocode}
\newcommand{\CSX@generate@@@caption@LabelAndText}[5]{%
   % #1=image command
   % #2=node name
   % #3=last node name
   % #4=label
   % #5=text
   % Get the image width
   \CSX@setimagewidth{#1}%
   % Get the widest label
   \CSX@setmaxlabelwidth{#4}%
   % Measure the text width
   \def\CSX@textwidth{0}%
   \CSX@settextwidth{#5}%
   \CSX@setvphantom%
   % Typeset caption
   \edef\CSX@generate@@@caption@tempentry{%
      \noexpand\gappto\noexpand\CSXcaption{%
         % Set \CSXimagewidth
         \noexpand\pgfmathsetlength{\noexpand\CSXimagewidth}%
                                   {\CSX@imagewidth}%
         % Set \CSXlabelwidth
         \noexpand\pgfmathsetlength{\noexpand\CSXlabelwidth}%
                                   {\CSX@labelwidth}%
         % Set \CSXmaxlabelwidth
         \noexpand\pgfmathsetlength{\noexpand\CSXmaxlabelwidth}%
                                   {\CSX@maxlabelwidth}%
         % Set \CSXtextwidth
         \noexpand\pgfmathsetlength{\noexpand\CSXtextwidth}%
                                   {\CSX@textwidth}%
         % Set \CSXmaxtextwidth
         \noexpand\pgfmathsetlength{\noexpand\CSXmaxtextwidth}%
                                   {\CSX@maxtextwidth}%
         % Print node
         \noexpand\node(#2)[%
            CSXlabelfont,%
            \expandonce\CSX@vphantom,%
            CSXsetlabelwidth,%
            CSXcaptionLabelandText,%
            rectangle split,%
            rectangle split horizontal,%
            rectangle split parts=2,%
            rectangle split part align=base,%
            every two node part/.append style={%
               CSXtextfont,%
               CSXsettextwidth,%
            },%
            \ifCSX@generate@@@caption@LastEntryWasTextOnly%
               \ifnum\theCSXcaption>1%
                  below=of #3.south,%
               \fi%
            \else%
               \ifnum\theCSXcaption>1%
                  below left=of #3.one split south,%
               \fi%
               anchor=one split north%
            \fi%
         ]{%
            \expandonce#4%
            \noexpand\nodepart{two}%
            \expandonce#5%
         };%
      }%
   }\CSX@generate@@@caption@tempentry%
   \CSX@generate@@@caption@LastEntryWasTextOnlyfalse%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@generate@@@caption@TextOnly}
%    \begin{macrocode}
\newcommand{\CSX@generate@@@caption@TextOnly}[4]{%
   % #1=image command
   % #2=node name
   % #3=last node name
   % #4=label
   % Get the image width
   \CSX@setimagewidth{#1}%
   % Get the widest label
   \CSX@setmaxlabelwidth{}%
   % Measure the text width
   \def\CSX@textwidth{0}%
   \CSX@settextwidth{#4}%
   \CSX@setvphantom%
   % Typeset caption
   \edef\CSX@generate@@@caption@tempentry{%
      \noexpand\gappto\noexpand\CSXcaption{%
         % Set \CSXimagewidth
         \noexpand\pgfmathsetlength{\noexpand\CSXimagewidth}%
                                   {\CSX@imagewidth}%
         % Set \CSXmaxlabelwidth
         \noexpand\pgfmathsetlength{\noexpand\CSXmaxlabelwidth}%
                                   {\CSX@maxlabelwidth}%
         % Set \CSXtextwidth
         \noexpand\pgfmathsetlength{\noexpand\CSXtextwidth}%
                                   {\CSX@textwidth}%
         % Set \CSXmaxtextwidth
         \noexpand\pgfmathsetlength{\noexpand\CSXmaxtextwidth}%
                                   {\CSX@maxtextwidth}%
         % Print node
         \noexpand\node(#2)[%
            CSXtextfont,%
            \expandonce\CSX@vphantom,%
            CSXsettextwidth,%
            CSXcaptionTextOnly,%
            \ifnum\theCSXcaption>1%
               below=of #3.south,%
            \fi%
         ]{%
            \expandonce#4%
         };%
      }%
   }\CSX@generate@@@caption@tempentry%
   \CSX@generate@@@caption@LastEntryWasTextOnlytrue%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@print}
%    \begin{macrocode}
\newcommand{\CSX@print}{%
   \ifnum\theCSXstruct=0%
      \PackageWarning{chemschemex}{Empty Chemscheme environment detected.}
   \else%
      \let\CSX@printlist\empty%
      \CSX@@print%
   \fi%
   \setcounter{CSXstructinarrow}{0}%
   % Print scheme
   \begin{tikzpicture}[CSX]%   
   \matrix [CSXmatrix]{%
      \CSX@printlist%
   };%
   \CSX@commands%
   \end{tikzpicture}%
   \stepcounter{CSXscheme}%
   \setcounter{CSXstruct}{0}%
   \setcounter{CSXstructinarrow}{0}%
   \gdef\CSX@printlist{}%
   \gdef\CSX@commands{}%
   \gdef\ChemschemeNextRow@list{}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@@print}
%    \begin{macrocode}
\newcommand{\CSX@@print}{%
   % #1=
   % #2=row (integer)
   \def\lastx{1}%
   \ChemschemeNextRow%
   \foreach \x [remember=\xplus as \lastx,%
                evaluate=\x as \xplus using int(\x+1)]%
               in \ChemschemeNextRow@list {%
      \ifthenelse{\x < \lastx}{}{%
         % Create Image row
         \foreach \y in {\lastx,...,\x}{%
            \CSX@@@print{\csname CSX@list@image@\y\endcsname}%
         }%      
         \gappto\CSX@printlist{\pgfmatrixendrow}%      
         % Create Caption row
         \foreach \y in {\lastx,...,\x}{%
            \CSX@@@print{\csname CSX@list@caption@\y\endcsname}%
         }%
         \edef\CSX@print@tempentry{%
            \noexpand\gappto\noexpand\CSX@printlist{%
               \noexpand\pgfmatrixendrow[\csname ChemschemeNextRow@\x\endcsname]%
            }%
         }\CSX@print@tempentry%
      }%
   }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\CSX@@@print}
%    \begin{macrocode}
\newcommand{\CSX@@@print}[2]{%
   % #1=image
   \ifnum\y<\x%
      \def\CSX@@@print@nextcell{\pgfmatrixnextcell}%
   \else%
      \def\CSX@@@print@nextcell{}%
   \fi%
   \edef\CSX@print@tempentry{%
      \noexpand\gappto\noexpand\CSX@printlist{%
         \noexpand#1%
         \expandonce\CSX@@@print@nextcell%
      }%
   }\CSX@print@tempentry%
}
%    \end{macrocode}
% \end{macro}
%
%
\endinput
% \Finale