% \iffalse meta-comment
%
% File: pdfcol.dtx
% Version: 2026-06-20 v1.8
% Info: Handle new color stacks for pdfTeX
%
% Copyright (C)
%    2007 Heiko Oberdiek
%    2016-2026 Oberdiek Package Support Group
%    https://github.com/ho-tex/pdfcol/issues
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any later
% version. This version of this license is in
%    https://www.latex-project.org/lppl/lppl-1-3c.txt
% and the latest version of this license is in
%    https://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 Maintainers of this work are
% Heiko Oberdiek and the Oberdiek Package Support Group
% https://github.com/ho-tex/pdfcol/issues
%
%
% This work consists of the main source file pdfcol.dtx, pdfcol.ins
% and the derived files
%    pdfcol.sty, pdfcol.pdf
%    
% Distribution:
%    CTAN:macros/latex/contrib/pdfcol/pdfcol.dtx
%    CTAN:macros/latex/contrib/pdfcol/pdfcol.pdf
%
% Unpacking:
%    (a) If pdfcol.ins is present:
%           (la)tex pdfcol.ins
%
% Documentation:
%           latex pdfcol.dtx; ...
%
%    Programm calls to get the documentation (example):
%       lualatex pdfcol.dtx
%       makeindex -s gind.ist pdfcol.idx
%       lualatex pdfcol.dtx
%       makeindex -s gind.ist pdfcol.idx
%       lualatex pdfcol.dtx
%
% Installation:
%    TDS:tex/latex/pdfcol/pdfcol.sty
%    TDS:doc/latex/pdfcol/pdfcol.pdf
%    TDS:source/latex/pdfcol/pdfcol.dtx
%
%<*driver>
\DocumentMetadata{tagging=on}
\documentclass{l3in2edoc}
\DeclareDocElement[printtype=\textit{key},idxtype=key,idxgroup=Keys]{Key}{keydecl}
\NewDocumentCommand\xoption{m}{\textsf{#1\DescribeKey[noprint]{#1}}}

\newcommand*{\xpackage}[1]{\textsf{#1}}
\newcommand*{\xmodule}[1]{\textsf{#1}}
\newcommand*{\xclass}[1]{\textsf{#1}}
\newcommand*{\xfile}[1]{\texttt{#1}}
\newcommand*{\xext}[1]{\texttt{.#1}}
\newcommand*{\xemail}[1]{%
  \textless\texttt{#1}\textgreater%
}
\newcommand*{\xnewsgroup}[1]{%
  \href{news:#1}{\nolinkurl{#1}}%
}
\newcommand*{\CTANpkg}[1]{%
  \href{http://ctan.org/pkg/#1}{\nolinkurl{CTAN:pkg/#1}}%
}
\newcommand*{\CTAN}[1]{%
  \href{https://ctan.org/tex-archive/#1}{\nolinkurl{CTAN:#1}}%
}
\providecommand*{\docstrip}{\textsf{docstrip}}
\providecommand*{\mikTeX}{\hologo{MiKTeX}}



\newenvironment{Version}[1]
  {\subsection*[toc={[#1]}]{[#1]}\begin{itemize}}
  {\end{itemize}} 
\newenvironment{History}
 {\section{History}\raggedright}{}

\usepackage{etoolbox}
% get rid of index entries from macrocode environments
% 
\ExplSyntaxOn\makeatletter
\bool_new:N\l__pdfcol_index_macrocode_bool
\DeclareKeys [ pdfcol / doc ]
 {
  index-macrocode .bool_set:N=\l__pdfcol_index_macrocode_bool,
  index-macrocode .initial:n=true
 }
\patchcmd \__codedoc_special_index_aux:nnnnnn
  {\__codedoc_index_codeline_hc:nn}
  {
   \bool_if:NTF\l__pdfcol_index_macrocode_bool
   {\__codedoc_index_codeline_hc:nn}
   {\use_none:nn}
  }
  {}
  {\fail}
\SetKeys[pdfcol/doc]{index-macrocode=false}  
\ExplSyntaxOff\makeatother

\usepackage{pdfcol}
\pdfcolInitStack{test}
\begin{document}
  \DocInput{pdfcol.dtx}%
\end{document}
%</driver>
% \fi
%
% \title{The \xpackage{pdfcol} package}
% \date{2026-06-20 v1.8}
% \author{Heiko Oberdiek\thanks
% {Please report any issues at \url{https://github.com/ho-tex/pdfcol/issues}}}
%
% \maketitle
%
% \begin{abstract}
% Since version 1.40 \pdfTeX\ supports color stacks.
% The driver file \xfile{pdftex.def} for package \xpackage{color}
% defines and uses a main color stack since version v0.04b.
% Package \xpackage{pdfcol} is intended for package writers.
% It defines macros for setting and maintaining new color stacks.
% It works also with lua\TeX.
% \end{abstract}
%
% \tableofcontents
%
% \section{Documentation}
%
% Version 1.40 of \pdfTeX\ adds new primitives \cs{pdfcolorstackinit}
% and \cs{pdfcolorstack}. Now color stacks can be defined and used.
% A main color stack is maintained by the driver file \xfile{pdftex.def}
% similar to dvips or dvipdfm. However the number of color stacks
% is not limited to one in \pdfTeX. Thus further color problems
% can now be solved, such as footnotes across pages or text
% that is set in parallel columns (e.g. packages \xpackage{parallel}
% or \xpackage{parcolumn}). Unlike the main color stack,
% the support by additional color stacks cannot be done in
% a transparent manner.
%
% This package \xpackage{pdfcol} provides an easier interface to
% additional color stacks without the need to use the
% low level primitives.
%
% The engine lua\TeX\ is supported, but if the package \xpackage{luacolor} is detected
% (which uses attributes to set colors) the package interfaces are disabled.
%
% \subsection{Requirements}
% \label{sec:req}
%
% \begin{itemize}
% \item
%   \pdfTeX\ 1.40 or greater or lua\TeX.
% \item
%   \pdfTeX or lua\TeX\ in PDF mode. (I don't know a DVI driver that
%   support several color stacks.)
% \item
%   \xfile{pdftex.def} or \xfile{luatex.def} newer than 2007.
% \end{itemize}
% Package \xpackage{pdfcol} checks the requirements and
% sets switch \cs{ifpdfcolAvailable} accordingly.
%
% \subsection{Interface}
%
% \begin{function}{\ifpdfcolAvailable}
% \begin{syntax}
% \cs{ifpdfcolAvailable}\meta{true}\cs{else}\meta{false}\cs{fi}
% \end{syntax}
% If the requirements of section \ref{sec:req} are met the
% switch \cs{ifpdfcolAvailable} behaves as \cs{iftrue}.
% Otherwise the other interface macros in this section will
% be disabled with a message. Also the first use of such a
% macro will print a message. The messages are print to
% the \xext{log} file only if \pdfTeX\ and lua\TeX\ not used in PDF mode.
% \end{function}
%
% \begin{function}{\pdfcolErrorNoStacks}
% The first call of \cs{pdfcolErrorNoStacks} prints an error
% message, if color stacks are not available.
% \end{function}
%
% \begin{function}{\pdfcolInitStack}
% \begin{syntax}
% \cs{pdfcolInitStack}\Arg{name}
% \end{syntax}
% A new color stack is initialized by \cs{pdfcolInitStack}.
% The \meta{name} is used for identifying the stack. It usually
% consists of letters and digits. (The name must survive a \cs[no-index]{csname}.)
% \end{function}
%
% The intention of the macro is the definition of an additional
% color stack. Thus the stack is not page bounded like the
% main color stack. Black (\texttt{0 g 0 G}) is used as initial
% color value. And colors are written with modifier \texttt{direct}
% that means without setting the current transfer matrix and changing
% the current point (see documentation of \pdfTeX\ for
% |\pdfliteral direct{...}|).
%
% \begin{function}{\pdfcolIfStackExists}
% \begin{syntax}
% \cs{pdfcolIfStackExists} \Arg{name} \Arg{true} \Arg{false}
% \end{syntax}
% Macro \cs{pdfcolIfStackExists} checks whether color stack \meta{name}
% exists. In case of success argument \meta{then} is executed
% and \meta{else} otherwise.
% \end{function}
%
% \begin{function}{\pdfcolSwitchStack} 
% \begin{syntax}
% \cs{pdfcolSwitchStack}\Arg{name}
% \end{syntax}
% Macro \cs{pdfcolSwitchStack} switches the color stack. The color macros
% of package \xpackage{color}, \xpackage{xcolor} and the \xpackage{l3color}
% module now uses the new color stack with name \meta{name}.
% \end{function}
%
% \begin{function}{\pdfcolSetCurrentColor}
% Macro \cs{pdfcolSetCurrentColor} replaces the topmost
% entry of the stack by the current color (\cs{current@color}).
% \end{function}
%
% \begin{function}{\pdfcolSetCurrent} 
% \begin{syntax}
% \cs{pdfcolSetCurrent}\Arg{name}
% \end{syntax}
% Macro \cs{pdfcolSetCurrent} sets the color that is read in
% the top-most entry of color stack \meta{name}. If \meta{name}
% is empty, the default color stack is used.
% \end{function}
%
%  \subsection{Example (for \LaTeX)}
%
%  In \LaTeX{} colors can be set through the commands of the packages \xpackage{color}/\xpackage{xcolor},
%  with the in-built commands of the \xpackage{l3color} module in \xpackage{l3kernel}.
%  Unless the package \xpackage{luacolor} is used these commands do \emph{not} naturally
%  respect \TeX\ groups, instead they insert literals into the PDF that start a color
%  and the color must be reset to get back to the previous. This
%  is typically done with a command that is inserted with \cs[no-index]{aftergroup}
%  \emph{after} the enclosing group.
%  The command  \cs{pdfcolSwitchStack} on the other hand switches the color stack locally:
%  At the end of the enclosing group the stack is switched back again.
%  This can lead to the odd behaviour that a color takes it resets from the wrong stack:
%
%  \begin{verbatim}
% \showoutput
%  black             % main stack: black
%   {
%   \color{green}
%    green           % main stack: black, green
%    {
%      green
%      \pdfcolSwitchStack{test} % test stack: black
%      green
%      \color{yellow} % test stack: black, yellow
%      yellow
%                    % End of group: switch to main stack
%    }               % After group: reset of 'color{yellow}'
%                    % pops green from *main* stack and green ends
%                    % main stack: black
%    after group green? No black!!
%   }  
%  \end{verbatim}
%
%  If one checks with \cs{showoutput} one can see the following sequence
%  \begin{verbatim}
%  \pdfcolorstack 0 push {0 1 0 rg 0 1 0 RG} % from \color{green}
%  \pdfcolorstack 1 push {0 0 1 0 k 0 0 1 0 K} % from \color{yellow}
%  \pdfcolorstack 0 pop  % reset of \color{yellow}
%  \pdfcolorstack 0 pop  % reset of \color{green}
%  \end{verbatim}
%  and pdftex complains about one \texttt{pop} too much:
%  \begin{verbatim}
%  pdfTeX warning: pdflatex-dev.exe: pop empty color page stack 0
%  \end{verbatim}
%  
%  To avoid such problems it is important to ensure, that the 
%  reset of colors is done from the stack on which they pushed. This means that the
%  stack switch must outside of the group where the colors from the new stack are used:
%
%  \begin{verbatim}
%   black           % main stack: black
%   {
%    \color{green}
%     green           % main stack: black, green
%     {
%      green
%      \pdfcolSwitchStack{test} % test stack: black
%       {
%        green
%        \color{yellow} % test stack: black, yellow
%        yellow         % End of group: test stack still active
%       }
%         % After group: color yellow popped from test stack
%     }
%     after group green?? No still black!!
%   }
%  \end{verbatim}
%
%  \begin{flushleft}
%  \sffamily 
%  \fbox{ black { \color{green} green { green \pdfcolSwitchStack{test} {  green \color{yellow}  yellow  } }
%     after group green?? No still black!!  } }
%  \end{flushleft}
%     
%  Now the colors are popped from the correct stacks:
% \begin{verbatim}
%  \pdfcolorstack 0 push {0 1 0 rg 0 1 0 RG} % from \color{green}
%  \pdfcolorstack 1 push {0 0 1 0 k 0 0 1 0 K} % from \color{yellow}
%  \pdfcolorstack 1 pop  % reset of \color{yellow}
%  \pdfcolorstack 0 pop  % reset of \color{green}
% \end{verbatim}    
%     
%  But this still gives green after the group: Yellow has been correctly ended but that doesn't mean that 
%  green takes over again: The new color stack had black as starting value and this is used once the 
%  yellow is popped. To get green again one must therefore replace the starting value of the new
%  stack by the currently active color. For this the package offers the command \cs{pdfcolSetCurrentColor}
%  which replaces the current top most color of a stack by the color stored in \cs{current@color}:
%  \begin{verbatim}
%  black           % main stack: black
%  {
%   \color{green}
%    green           % main stack: black, green
%    {
%     green
%     \pdfcolSwitchStack{test} % test stack: black
%     \pdfcolSetCurrentColor   % test stack: green
%      {
%       green
%       \color{yellow} % test stack: green, yellow
%       yellow         % End of group: test stack still active
%      }
%        % After group: color yellow popped from test stack, green used
%    }
%    after group green!!
%  }%  
%  \end{verbatim}
%  
%   \begin{flushleft}
%  \sffamily 
%  { black { \color{green} green { green \pdfcolSwitchStack{test}\pdfcolSetCurrentColor
%   {  green \color{yellow}  yellow  } }
%     after group green!!  } }
%  \end{flushleft}
%     
%  An alternative method to the same effect is to take the current color from the main stack
%  and to issue it again after the group:
%  \begin{verbatim}
%  black           % main stack: black
%  {
%   \color{green}
%    green           % main stack: black, green
%    {
%     green
%     \pdfcolSwitchStack{test} % test stack: black
%      {
%       green
%       \color{yellow} % test stack: black, yellow
%       yellow         % End of group: test stack still active
%      }
%        % After group: color yellow popped from test stack
%    }%
%    \pdfcolSetCurrent{}% set current color of main stack = green
%    after group green!!
%  }%  
% \end{verbatim}    
% 
%   \begin{flushleft}
%  \sffamily 
%  { black { \color{green} green { green \pdfcolSwitchStack{test}
%   {  green \color{yellow}  yellow  } }\pdfcolSetCurrent{}
%     after group green!!  } }         
%   \end{flushleft}
%     
% \StopEventually{
% }
%
% \section{Implementation}
% \DoNotIndex{\\}
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% \subsection{Reload check and package identification}
%    Reload check, especially if the package is not used with \LaTeX.
%    \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
  \catcode13=5 % ^^M
  \endlinechar=13 %
  \catcode35=6 % #
  \catcode39=12 % '
  \catcode44=12 % ,
  \catcode45=12 % -
  \catcode46=12 % .
  \catcode58=12 % :
  \catcode64=11 % @
  \catcode123=1 % {
  \catcode125=2 % }
  \expandafter\let\expandafter\x\csname ver@pdfcol.sty\endcsname
  \ifx\x\relax % plain-TeX, first loading
  \else
    \def\empty{}%
    \ifx\x\empty % LaTeX, first loading,
      % variable is initialized, but \ProvidesPackage not yet seen
    \else
      \expandafter\ifx\csname PackageInfo\endcsname\relax
        \def\x#1#2{%
          \immediate\write-1{Package #1 Info: #2.}%
        }%
      \else
        \def\x#1#2{\PackageInfo{#1}{#2, stopped}}%
      \fi
      \x{pdfcol}{The package is already loaded}%
      \aftergroup\endinput
    \fi
  \fi
\endgroup%
%    \end{macrocode}
%    Package identification:
%    \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
  \catcode13=5 % ^^M
  \endlinechar=13 %
  \catcode35=6 % #
  \catcode39=12 % '
  \catcode40=12 % (
  \catcode41=12 % )
  \catcode44=12 % ,
  \catcode45=12 % -
  \catcode46=12 % .
  \catcode47=12 % /
  \catcode58=12 % :
  \catcode64=11 % @
  \catcode91=12 % [
  \catcode93=12 % ]
  \catcode123=1 % {
  \catcode125=2 % }
  \expandafter\ifx\csname ProvidesPackage\endcsname\relax
    \def\x#1#2#3[#4]{\endgroup
      \immediate\write-1{Package: #3 #4}%
      \xdef#1{#4}%
    }%
  \else
    \def\x#1#2[#3]{\endgroup
      #2[{#3}]%
      \ifx#1\@undefined
        \xdef#1{#3}%
      \fi
      \ifx#1\relax
        \xdef#1{#3}%
      \fi
    }%
  \fi
\expandafter\x\csname ver@pdfcol.sty\endcsname
\ProvidesPackage{pdfcol}%
  [2026-06-20 v1.8 Handle new color stacks for pdfTeX (HO)]%
%    \end{macrocode}
%
% \subsection{Catcodes}
%
%    \begin{macrocode}
\begingroup\catcode61\catcode48\catcode32=10\relax%
  \catcode13=5 % ^^M
  \endlinechar=13 %
  \catcode123=1 % {
  \catcode125=2 % }
  \catcode64=11 % @
  \def\x{\endgroup
    \expandafter\edef\csname PDFCOL@AtEnd\endcsname{%
      \endlinechar=\the\endlinechar\relax
      \catcode13=\the\catcode13\relax
      \catcode32=\the\catcode32\relax
      \catcode35=\the\catcode35\relax
      \catcode61=\the\catcode61\relax
      \catcode64=\the\catcode64\relax
      \catcode123=\the\catcode123\relax
      \catcode125=\the\catcode125\relax
    }%
  }%
\x\catcode61\catcode48\catcode32=10\relax%
\catcode13=5 % ^^M
\endlinechar=13 %
\catcode35=6 % #
\catcode64=11 % @
\catcode123=1 % {
\catcode125=2 % }
\def\TMP@EnsureCode#1#2{%
  \edef\PDFCOL@AtEnd{%
    \PDFCOL@AtEnd
    \catcode#1=\the\catcode#1\relax
  }%
  \catcode#1=#2\relax
}
\TMP@EnsureCode{39}{12}% '
\TMP@EnsureCode{40}{12}% (
\TMP@EnsureCode{41}{12}% )
\TMP@EnsureCode{43}{12}% +
\TMP@EnsureCode{44}{12}% ,
\TMP@EnsureCode{46}{12}% .
\TMP@EnsureCode{47}{12}% /
\TMP@EnsureCode{91}{12}% [
\TMP@EnsureCode{93}{12}% ]
\TMP@EnsureCode{96}{12}% `
\edef\PDFCOL@AtEnd{\PDFCOL@AtEnd\noexpand\endinput}
%    \end{macrocode}
%
% \subsection{Check requirements}
%
%    \begin{macro}[int]{\PDFCOL@RequirePackage}
%    \begin{macrocode}
\ifcsname RequirePackage\endcsname
  \def\PDFCOL@RequirePackage#1[#2]{%
    \RequirePackage{#1}[{#2}]%
  }%
\else
  \def\PDFCOL@RequirePackage#1[#2]{\input #1.sty\relax}%
\fi
%    \end{macrocode}
%    \end{macro}
%
% LuaTeX Compatability
%    \begin{macrocode}
\ifx\pdfextension\@undefined\else
 \def\pdfcolorstackinit {\pdffeedback colorstackinit}
 \protected\def\pdfcolorstack     {\pdfextension colorstack}
\fi
%    \end{macrocode}
%
%    \begin{macrocode}
\PDFCOL@RequirePackage{ltxcmds}[2010/03/01]
%    \end{macrocode}
%
%    \begin{macro}{\ifpdfcolAvailable}
%    \begin{macrocode}
\ltx@newif\ifpdfcolAvailable
\pdfcolAvailabletrue
%    \end{macrocode}
%    \end{macro}
%
% \subsubsection{Check package \xpackage{luacolor}}
%
%    \begin{macrocode}
\ltx@newif\ifPDFCOL@luacolor
\ifcsname ver@luacolor.sty\endcsname
  \PDFCOL@luacolortrue
\else
  \PDFCOL@luacolorfalse
\fi
%    \end{macrocode}
%
% \subsubsection{Check PDF mode}
%
%    \begin{macrocode}
\PDFCOL@RequirePackage{infwarerr}[2007/09/09]
\PDFCOL@RequirePackage{iftex}[2019/11/07]
\ifcase\ifpdf\ifPDFCOL@luacolor 1\fi\else 1\fi0 %
  \def\PDFCOL@Message{%
    \@PackageWarningNoLine{pdfcol}%
  }%
\else
  \pdfcolAvailablefalse
  \def\PDFCOL@Message{%
    \@PackageInfoNoLine{pdfcol}%
  }%
  \PDFCOL@Message{%
    Interface disabled because of %
    \ifPDFCOL@luacolor
      package `luacolor'%
    \else
      missing PDF mode of pdfTeX%
    \fi
  }%
\fi
%    \end{macrocode}
%
% \subsubsection{Check version of \pdfTeX}
% The version check has been removed. We assume a new enough \pdfTeX.
%
% \subsubsection{Check \xfile{pdftex.def}}
% We no longer check the version but assume that it is new enough.
%    \begin{macrocode}
\ifpdfcolAvailable
%    \end{macrocode}
%    Try to load package color if it is not yet loaded (\LaTeX\ case).
%    \begin{macrocode}
   \ifcsname documentclass\endcsname
     \RequirePackage{color}
     \RequirePackage{etoolbox}
%    \end{macrocode}
% To support l3color we need to set also the backend stack integer to the new value.
%    \begin{macrocode}
     \def\pdfcol@switch@kernel@colorstack#1%
      {\csname l__color_backend_stack_int\endcsname =\csname pdfcol@Stack@#1\endcsname}
%    \end{macrocode}
%    \begin{macrocode}
   \else
     \def\pdfcol@switch@kernel@colorstack#1{}
   \fi
\fi
%    \end{macrocode}
%
%    \begin{macrocode}
\let\pdfcolAvailabletrue\relax
\let\pdfcolAvailablefalse\relax
%    \end{macrocode}
%
% \subsection{Enabled interface macros}
%
%    \begin{macrocode}
\ifpdfcolAvailable
%    \end{macrocode}
%
%    \begin{macro}{\pdfcolErrorNoStacks}
%    \begin{macrocode}
  \let\pdfcolErrorNoStacks\relax
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}[int]{\pdfcol@Value}
%    \begin{macrocode}
  \expandafter\ifx\csname pdfcol@Value\endcsname\relax
    \def\pdfcol@Value{0 g 0 G}%
  \fi
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}[int]{\pdfcol@LiteralModifier}
%    \begin{macrocode}
  \expandafter\ifx\csname pdfcol@LiteralModifier\endcsname\relax
    \def\pdfcol@LiteralModifier{direct}%
  \fi
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\pdfcolInitStack}
%    \begin{macrocode}
  \def\pdfcolInitStack#1{%
    \expandafter\ifx\csname pdfcol@Stack@#1\endcsname\relax
      \global\expandafter\chardef\csname pdfcol@Stack@#1\endcsname=%
          \pdfcolorstackinit\pdfcol@LiteralModifier{\pdfcol@Value}%
          \relax
      \@PackageInfo{pdfcol}{%
        New color stack `#1' = \number\csname pdfcol@Stack@#1\endcsname
      }%
    \else
      \@PackageError{pdfcol}{%
        Stack `#1' is already defined%
      }\@ehc
    \fi
  }%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\pdfcolIfStackExists}
%    \begin{macrocode}
  \def\pdfcolIfStackExists#1{%
    \expandafter\ifx\csname pdfcol@Stack@#1\endcsname\relax
      \expandafter\@secondoftwo
    \else
      \expandafter\@firstoftwo
    \fi
  }%
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}[int]{\@firstoftwo}
%    \begin{macrocode}
  \ifcsname @firstoftwo\endcsname
    \long\def\@firstoftwo#1#2{#1}%
  \fi
%    \end{macrocode}
%    \end{macro}
%    \begin{macro}[int]{\@secondoftwo}
%    \begin{macrocode}
  \ifcsname @secondoftwo\endcsname
    \long\def\@secondoftwo#1#2{#2}%
  \fi
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\pdfcolSwitchStack}
%    \begin{macrocode}
  \def\pdfcolSwitchStack#1{%
    \pdfcolIfStackExists{#1}{%
      \expandafter\let\expandafter\@pdfcolorstack
                      \csname pdfcol@Stack@#1\endcsname
      \pdfcol@switch@kernel@colorstack{#1}%
    }{%
      \pdfcol@ErrorNoStack{#1}%
    }%
  }%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\pdfcolSetCurrentColor}
%    \begin{macrocode}
  \def\pdfcolSetCurrentColor{%
    \pdfcolorstack\@pdfcolorstack set{\current@color}%
  }%
%    \end{macrocode}
%    \end{macro}
%
%
%    \begin{macro}{\pdfcolSetCurrent}
%    \begin{macrocode}
  \def\pdfcolSetCurrent#1{%
    \ifx\\#1\\%
      \pdfcolorstack\@pdfcolorstack current\relax
    \else
      \pdfcolIfStackExists{#1}{%
        \pdfcolorstack\csname pdfcol@Stack@#1\endcsname current\relax
      }{%
        \pdfcol@ErrorNoStack{#1}%
      }%
    \fi
  }%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}[int]{\pdfcol@ErrorNoStack}
%    \begin{macrocode}
  \def\pdfcol@ErrorNoStack#1{%
    \@PackageError{pdfcol}{Stack `#1' does not exists}\@ehc
  }%
%    \end{macrocode}
%    \end{macro}
%
% \subsection{Disabled interface macros}
%
%    \begin{macrocode}
\else
%    \end{macrocode}
%
%    \begin{macro}{\pdfcolErrorNoStacks}
%    \begin{macrocode}
  \def\pdfcolErrorNoStacks{%
    \@PackageError{pdfcol}{%
      Color stacks are not available%
    }{%
      Update pdfTeX (1.40) and `pdftex.def' (0.04b) %
          if necessary.\MessageBreak
      Ensure that `pdftex.def' is loaded %
          (package `color' or `xcolor').\MessageBreak
      Further messages can be found in TeX's %
          protocol file `\jobname.log'.\MessageBreak
      \MessageBreak
      \@ehc
    }%
    \global\let\pdfcolErrorNoStacks\relax
  }%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}[int]{\PDFCOL@Disabled}
%    \begin{macrocode}
  \def\PDFCOL@Disabled{%
    \PDFCOL@Message{%
      pdfTeX's color stacks are not available%
    }%
    \global\let\PDFCOL@Disabled\relax
  }%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\pdfcolInitStack}
%    \begin{macrocode}
  \def\pdfcolInitStack#1{%
    \PDFCOL@Disabled
  }%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\pdfcolIfStackExists}
%    \begin{macrocode}
  \long\def\pdfcolIfStackExists#1#2#3{#3}%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\pdfcolSwitchStack}
%    \begin{macrocode}
  \def\pdfcolSwitchStack#1{%
    \PDFCOL@Disabled
  }%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\pdfcolSetCurrentColor}
%    \begin{macrocode}
  \def\pdfcolSetCurrentColor{%
    \PDFCOL@Disabled
  }%
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\pdfcolSetCurrent}
%    \begin{macrocode}
  \def\pdfcolSetCurrent#1{%
    \PDFCOL@Disabled
  }%
%    \end{macrocode}
%    \end{macro}
%    \begin{macrocode}
\fi
%    \end{macrocode}
%
%    \begin{macrocode}
\PDFCOL@AtEnd%
%</package>
%    \end{macrocode}
%% \section{Installation}
%
% \subsection{Download}
%
% \paragraph{Package.} This package is available on
% CTAN\footnote{\CTANpkg{pdfcol}}:
% \begin{description}
% \item[\CTAN{macros/latex/contrib/pdfcol/pdfcol.dtx}] The source file.
% \item[\CTAN{macros/latex/contrib/pdfcol/pdfcol.pdf}] Documentation.
% \end{description}
%
%
%
% \subsection{Package installation}
%
% The easiest is to use the package manager from your TeX system. If
% you want to install manually:
% 
% \paragraph{Unpacking.} The \xfile{.dtx} file is 
% \docstrip\ archive. The files are extracted from the \xfile{.dtx}
% by compiling the file with some TeX program.
%
% \paragraph{TDS.} Now the different files must be moved into
% the different directories in your installation TDS tree
% (also known as \xfile{texmf} tree):
% \begin{quote}
% \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
%   pdfcol.sty & tex/latex/pdfcol/pdfcol.sty\\
%   pdfcol.pdf & doc/latex/pdfcol/pdfcol.pdf\\
%   pdfcol.dtx & source/latex/pdfcol/pdfcol.dtx\\
% \end{tabular}
% \end{quote}
%
%
% \subsection{Refresh file name databases}
%
% If your \TeX~distribution
% (\TeX\,Live, \mikTeX, \dots) relies on file name databases, you must refresh
% these. For example, \TeX\,Live\ users run \verb|texhash| or
% \verb|mktexlsr|.
%

% \paragraph{Generating the documentation.}
% You can use the \xfile{.dtx} to generate
% the documentation. 
% \begin{quote}
%\begin{verbatim}
% lualatex pdfcol.dtx
% makeindex -s gind.ist pdfcol.idx
% lualatex pdfcol.dtx
% makeindex -s gind.ist pdfcol.idx
% lualatex pdfcol.dtx
%\end{verbatim}
% \end{quote}
%
% \begin{History}
%   \begin{Version}{2007/09/09 v1.0}
%   \item
%     First version.
%   \end{Version}
%   \begin{Version}{2007/12/09 v1.1}
%   \item
%     \cs{pdfcolSetCurrentColor} added.
%   \end{Version}
%   \begin{Version}{2007/12/12 v1.2}
%   \item
%     Detection for package \xpackage{luacolor} added.
%   \end{Version}
%   \begin{Version}{2016/05/16 v1.3}
%   \item
%     Documentation updates.
%   \end{Version}
%   \begin{Version}{2016/05/17 v1.4}
%   \item
%     Use luatex85 package for new luatex compatibility
%   \end{Version}
%   \begin{Version}{2018/11/01 v1.5}
%   \item
%     Remove luatex85 dependency
%   \end{Version}
%   \begin{Version}{2019/12/29 v1.6}
%   \item
%    \xpackage{iftex} package.
%   \end{Version}
%   \begin{Version}{2022-09-21 v1.7}
%   \item Improved luatex compatibility, removed unneeded version checks.
%   \end{Version}
%   \begin{Version}{2026-06-20 v1.8}
%   \item Added support for color commands of the  l3color module, requires L3 programming layer
%         2026-06-19
%   \item Documentation is now tagged.
%   \end{Version}
% \end{History}
%
% \PrintIndex
%
% \Finale
\endinput
