%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% - chemnum - chemnum-codehelper.tex                                                  - %
% - a comprehensive approach for the numbering of chemical compounds                  - %
% ------------------------------------------------------------------------------------- %
% - Clemens NIEDERBERGER                                                              - %
% - 2011/12/08                                                                        - %
% ------------------------------------------------------------------------------------- %
% - http://www.mychemistry.eu/                                                        - %
% - contact@mychemistry.eu                                                            - %
% ------------------------------------------------------------------------------------- %
% - If you have any ideas, questions, suggestions or bugs to report, please feel free - %
% - to contact me.                                                                    - %
% ------------------------------------------------------------------------------------- %
% - Copyright 2011 Clemens Niederberger                                               - %
% -                                                                                   - %
% - This work may be distributed and/or modified under the                            - %
% - conditions of the LaTeX Project Public License, either version 1.3                - %
% - 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.3 or later is part of all distributions of LaTeX                    - %
% - version 2005/12/01 or later.                                                      - %
% -                                                                                   - %
% - This work has the LPPL maintenance status `maintained'.                           - %
% -                                                                                   - %
% - The Current Maintainer of this work is Clemens Niederberger.                      - %
% -                                                                                   - %
% - This work consists of the files chemnum.sty, chemnum_doc_de.tex,                  - %
% - chemnum_doc_en.tex, chemnum-codehelper.tex, scheme-tmp.eps, scheme-bla.eps,       - %
% -  README and the derived files chemnum_doc_de.pdf and chemnum_doc_en.pdf           - %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% This code is just a copy from the LaTeXdemo environment in the siunitx documentation
% which has been (minimally) adapted and provides environment beispiel with options
%  [code and example] (default)
%  [code only]
%  [code and float]
%
% Clemens NIEDERBERGER, 2011/12/01
%
% For creating examples with nice highlighting of code, and so
% on; based on the system used in the listings source (lstsample).
\RequirePackage[final]{listings}
\RequirePackage{framed}
\RequirePackage{xcolor}
  \xdefinecolor{code}{rgb}{.6,.25,.15}
  \xdefinecolor{key}{rgb}{0.02,0.48,0.18}
  \xdefinecolor{myblue}{rgb}{0.02,0.04,0.48}
  \xdefinecolor{myred}{rgb}{0.65,0.04,0.07}
  \xdefinecolor{mygray}{rgb}{0.4,0.4,0.4}
\makeatletter
\lst@RequireAspects{writefile}
\newsavebox{\beispiel@box}
\lstnewenvironment{beispiel}[1][code and example]
  {%
    \global\let\lst@intname\@empty
    \expandafter\let\expandafter\beispiel@end
      \csname beispiel@#1@end\endcsname
    \@nameuse{beispiel@#1}%
  }
  {\beispiel@end}
\newcommand*\beispiel@new[3]{%
  \expandafter\newcommand\expandafter*\expandafter
    {\csname beispiel@#1\endcsname}{#2}%
  \expandafter\newcommand\expandafter*\expandafter
    {\csname beispiel@#1@end\endcsname}{#3}%
}
\newcommand*\beispiel@common{%
  \setkeys{lst}
    {
      language=[LaTeX]TeX,
      basicstyle={\ttfamily\footnotesize},          % Grundstil
      extendedchars=true,
      numbers=left,                                 % Zeilennummern
      numberstyle=\tiny,                            % Größe des Zeilennummern
      numberblanklines=true,                        % Leerzeilen nummerieren
      gobble=0,                                     % das erste Leerzeichen abschneiden
      xleftmargin=20pt,                             % Einrückung links
      breaklines=true,                              % Zeilenumbruch
      literate={ä}{{\"a}}1 {ö}{{\"o}}1 {ü}{{\"u}}1 {Ä}{{\"A}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1 {ß}{{\ss}}1,
      moredelim=[is][\color{red!25!purple}]{!!}{!!},% Hervorhebung
      moredelim=[is][\color{black}]{++}{++},        % Hervorhebung der Keywords rückgängig
      commentstyle={\color{mygray}},
      keywordstyle=\color{code},
      texcsstyle=[30]\color{code},
      moretexcs=[30]
        {
          @m,
          arrow,
          bf,
          chemfig,
          chemname,
          cmpd,
          cmpdinit,
          cmpdref,
          cmpdreset,
          cmpdsetup,
          CNlabel,
          CNlabelnoref,
          CNref,
          CNlabelsub,
          CNlabelsubnoref,
          CNrefsub,
          declarecompound,
          color,
          compound,
          compoundprefix,
          compoundsuffix,
          fcite,
          includegraphics,
          lstinline,
          marker,
          midrule,
          penalty,
          renewcommand,
          schemename,
          schemestart,
          schemestop,
          selectlanguage,
          setarrowoffset,
          setatomsep,
          setcompoundsep,
          setdoublesep,
          section,
          sf,
          subsection,
          subsubsection,
          texorpdfstring,
          textcolor,
          textnumero,
          theffbibliography,
          uline
        }
    }%
}
\newcommand*\beispiel@input[1][\jobname.tmp]{%
  \catcode`\^^M=5\relax
  \small
  \begingroup
    \leavevmode
      \input{#1}%
  \endgroup
}
\beispiel@new{code and example}
  {%
    \setbox\beispiel@box=\hbox\bgroup
      \lst@BeginAlsoWriteFile{\jobname.tmp}%
      \beispiel@common
  }
  {%
      \lst@EndWriteFile
    \egroup
    \colorlet{shadecolor}{yellow!20}
    \begin{shaded}
      \ifdim\wd\beispiel@box>0.48\linewidth\relax
        \begin{minipage}{.9\linewidth}
          \hbox to \linewidth{\box\beispiel@box\hss}%
        \end{minipage}
        \vskip3mm
        \begin{minipage}{.9\linewidth}
          \beispiel@input
        \end{minipage}
      \else
        \begin{minipage}{0.48\linewidth}
          \hbox to\linewidth{\box\beispiel@box\hss}%
        \end{minipage}
        \hfill
        \begin{minipage}{0.48\linewidth}
          \beispiel@input
        \end{minipage}
      \fi
    \end{shaded}
  }
\beispiel@new{code and float}{%
  \colorlet{shadecolor}{yellow!20}
  \shaded
  \lst@BeginAlsoWriteFile{bsp.tmp}%
  \beispiel@common
}{%
  \lst@EndWriteFile
  \endshaded
  \beispiel@input[bsp.tmp]
}
\beispiel@new{code only}
  {\colorlet{shadecolor}{yellow!20}\shaded\beispiel@common}{\endshaded}
\makeatother

\lstset{
      language=[LaTeX]TeX,
      basicstyle={\ttfamily},                       % Grundstil
      extendedchars=true,
      numbers=left,                                 % Zeilennummern
      numberstyle=\tiny,                            % Größe des Zeilennummern
      numberblanklines=true,                        % Leerzeilen nummerieren
      gobble=0,                                     % das erste Leerzeichen abschneiden
      xleftmargin=20pt,                             % Einrückung links
      breaklines=true,                              % Zeilenumbruch
      literate={ä}{{\"a}}1 {ö}{{\"o}}1 {ü}{{\"u}}1 {Ä}{{\"A}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1 {ß}{{\ss}}1,
      moredelim=[is][\color{myred}]{!!}{!!},% Hervorhebung
      moredelim=[is][\color{black}]{++}{++},        % Hervorhebung der Keywords rückgängig
      commentstyle={\color{mygray}},
      keywordstyle=\color{code},
      texcsstyle=[30]\color{code},
      moretexcs=[30]
        {
          @m,
          cmpd,
          cmpdinit,
          cmpdref,
          cmpdreset,
          cmpdsetup,
          CNlabel,
          CNlabelnoref,
          CNref,
          CNlabelsub,
          CNlabelsubnoref,
          CNrefsub,
          declarecompound,
          color,
          compoundprefix,
          compoundsuffix,
          fcite,
          lstinline,
          penalty,
          psfrag,
          schemeref,
          tableofcontents,
          textnumero,
          theffbibliography,
          uline
        }
    }%

\makeatletter
\def\GetFileInfo#1{%
  \def\filename{#1}%
  \def\@tempb##1 ##2 ##3\relax##4\relax{%
    \def\filedate{##1}%
    \def\fileversion{##2}%
    \def\fileinfo{##3}}%
  \edef\@tempa{\csname ver@#1.sty\endcsname}%
  \expandafter\@tempb\@tempa\relax? ? \relax\relax}
\makeatother

\ExplSyntaxOn
\DeclareDocumentEnvironment { myquote } { o }
  {
    \quote
    \small\sffamily
  }
  {
    \IfNoValueF { #1 }
      {
        \par\noindent
        \parbox { \linewidth } { \raggedleft \normalfont \itshape #1 }
      }
    \endquote
  }

\NewDocumentCommand \paket { sm }
  {
    \textsf { #2 }
    \cs_if_exist:cF { paket @ #2 }
      {
        \cs_new_nopar:cpn { paket @ #2 } { }
        \IfBooleanF { #1 }
          { \footnote { CTAN: ~ \href { http://www.ctan.org/pkg/#2/ } { #2 } } }
      }
    \index { #2 @ \textsf { #2 } }
  }

\NewDocumentCommand \key { mg }
  {
    \textcolor{key}{ \texttt { #1 } }
    \IfNoValueF { #2 } { \texttt { ~=~#2 } }
    \index { #1 @ \textcolor{key}{ \texttt { #1 } } }
  }

\NewDocumentCommand \cmd { omoog }
  {
    \textcolor{code} { \texttt { \textbackslash #2 } }
    \IfNoValueF { #3 } { \texttt { [ #3 ] } }
    \IfNoValueF { #4 } { \texttt { [ #4 ] } }
    \IfNoValueF { #5 } { \texttt { \{ #5 \} } }
    \index
      {
        \IfNoValueTF { #1 } { #2 } { #1 }
        @ \textcolor { code } { \texttt { \textbackslash #2 } }
      }
  }

\NewDocumentCommand \secidx { som }
  {
    \IfBooleanTF { #1 }
      { \index { \IfNoValueTF { #2 } { #3 } { #2 } @ \textbf { #3 } |) } }
      { \index { \IfNoValueTF { #2 } { #3 } { #2 } @ \textbf { #3 } |( } }
  }

\NewDocumentCommand \ma { m }
  { \texttt { \{ #1 \} } }

\NewDocumentCommand \oa { m }
  { \texttt { [ #1 ] } }
\ExplSyntaxOff