%%%%%%%%%%*******    Setting up macros for colours    *******%%%%%%%%%%

%What macro to use for defining colours
\ifdefined\DefColor
   \let\DefineColor\DefColor
   \let\DefineGray\DefGray
\else\ifdefined\definecolor
  \def\DefineColor#1#2{\definecolor{#1}{rgb}{#2}}
  \def\DefineGray#1#2{\definecolor{#1}{gray}{#2}}
\else\unless\ifdefined\DefineColour
  \ifdefined\AtBeginDocument
    \def\DefineColor#1#2{\AtBeginDocument{\definecolor{#1}{rgb}{#2}}}
    \def\DefineGray#1#2{\AtBeginDocument{\definecolor{#1}{gray}{#2}}}
    \AtBeginDocument{\def\DefineColor#1#2{\definecolor{#1}{rgb}{#2}}}
    \AtBeginDocument{\def\DefineGray#1#2{\definecolor{#1}{gray}{#2}}}
  \else
    \errhelp{The colour definitions for Tcode need either \definecolor from the "color" or similar
  		packages, or \DefColor from pdfcolor-rg.tex, or a user provided \DefineColor.^^J
  		I will make \DefineColor ignore its arguments, but you will likely
  		get errors later caused by undefined colour names.}
    \errmessage{\string\define color or similar should be defined at this point.
  			Did you forget to input some colour package before the Tcode package?}
    \errhelp{}
    \def\DefineColor#1#2{}
    \let\DefineGray\DefineColor
  \fi
\fi\fi\fi

\unless\ifdefined\DefineGray %This can only happen if the user provided his definition of \DefineColor but not of \DefineGray
  \def\DefineGray#1#2{\DefineColor{#1}{#2, #2, #2}}
\fi

%Setup a definition for \color that is suitable for placing inside an \edef.
% Previously we defined a command \Color, and it was defined as \protected\def\Color{\color} when either
% \color was undefined or had an unknown definition. But \Color maight be in use, so we named it \ColFilStr.
% But the latter confuses the readers of the highlighting files, So now we just require the user to have either
% LaTeX's \color or a \color that can be placed inside an \edef, or none.
\ifx\color\undefined \let\color\relax % \color must be defined later. Let's hope they don't check \color\undefined.
\else
  \edef\temptest{\noexpand\protect\exP\noexpand\csname color \endcsname} %The definition of \color of some packages. We have eTeX, so fix it.
  \ifx\color\temptest \protected\edef\color{\exP\noexpand\csname color \endcsname}\fi
  %else, the user should be sure that the \color he has is suitable for an \edef, or should not use \TcodeEdefFormat
\fi

\ifdefined\PdfFill \let\ColFill\PdfFill
\else\ifx\color\relax \def\ColFill{\color}
\else \let\ColFill\color
\fi\fi
