%%
%% This is file `luacolor.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% luacolor.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Project: luacolor
%% Version: 2023-08-18 v1.18
%% 
%% Copyright (C)
%%    2007, 2009-2011 Heiko Oberdiek
%%    2016-2023 Oberdiek Package Support Group
%% 
%% 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/luacolor/issues
%% 
%% This work consists of the main source file luacolor.dtx
%% and the derived files
%%    luacolor.sty, luacolor.pdf, luacolor.ins, luacolor.drv,
%%    luacolor.lua,
%% 
\begingroup\catcode61\catcode48\catcode32=10\relax%
  \catcode13=5 % ^^M
  \endlinechar=13 %
  \catcode123=1 % {
  \catcode125=2 % }
  \catcode64=11 % @
  \def\x{\endgroup
    \expandafter\edef\csname LuaCol@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\LuaCol@AtEnd{%
    \LuaCol@AtEnd
    \catcode#1=\the\catcode#1\relax
  }%
  \catcode#1=#2\relax
}
\TMP@EnsureCode{34}{12}% "
\TMP@EnsureCode{39}{12}% '
\TMP@EnsureCode{40}{12}% (
\TMP@EnsureCode{41}{12}% )
\TMP@EnsureCode{42}{12}% *
\TMP@EnsureCode{43}{12}% +
\TMP@EnsureCode{44}{12}% ,
\TMP@EnsureCode{45}{12}% -
\TMP@EnsureCode{46}{12}% .
\TMP@EnsureCode{47}{12}% /
\TMP@EnsureCode{58}{12}% :
\TMP@EnsureCode{60}{12}% <
\TMP@EnsureCode{62}{12}% >
\TMP@EnsureCode{91}{12}% [
\TMP@EnsureCode{93}{12}% ]
\TMP@EnsureCode{95}{12}% _ (other!)
\TMP@EnsureCode{96}{12}% `
\edef\LuaCol@AtEnd{\LuaCol@AtEnd\noexpand\endinput}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luacolor}%
  [2023-08-18 v1.18 Color support via LuaTeX's attributes (HO)]
\RequirePackage{color}
\ifx\directlua\@undefined
  \PackageError{luacolor}{%
    This package may only be run using LuaTeX%
  }\@ehc
  \expandafter\LuaCol@AtEnd
\fi%
\ifcolors@
\else
  \PackageWarningNoLine{luacolor}{%
    Colors are disabled by option `monochrome'%
  }%
  \def\set@color{}%
  \def\reset@color{}%
  \def\set@page@color{}%
  \def\define@color#1#2{}%
  \expandafter\LuaCol@AtEnd
\fi%
\directlua{%
  require("luacolor")%
}
\begingroup
  \edef\x{\directlua{tex.write("2023-08-18 v1.18")}}%
  \edef\y{%
    \directlua{%
      if oberdiek.luacolor.getversion then %
        oberdiek.luacolor.getversion()%
      end%
    }%
  }%
  \ifx\x\y
  \else
    \PackageError{luacolor}{%
      Wrong version of lua module.\MessageBreak
      Package version: \x\MessageBreak
      Lua module: \y
    }\@ehc
  \fi
\endgroup
\ifnum\outputmode=\@ne
\else
  \begingroup
    \def\current@color{}%
    \def\reset@color{}%
    \setbox\z@=\hbox{%
      \begingroup
        \set@color
      \endgroup
    }%
    \edef\reserved@a{%
      \directlua{%
        oberdiek.luacolor.dvidetect()%
      }%
    }%
    \ifx\reserved@a\@empty
      \PackageError{luacolor}{%
        DVI driver detection failed because of\MessageBreak
        unrecognized color \string\special
      }\@ehc
      \endgroup
      \expandafter\expandafter\expandafter\LuaCol@AtEnd
    \else
      \PackageInfo{luacolor}{%
        Type of color \string\special: \reserved@a
      \@gobble}%
    \fi%
  \endgroup
\fi
\newattribute\LuaCol@Attribute
\let\LuaCol@setattribute\setattribute
\directlua{%
  oberdiek.luacolor.setattribute(\number\allocationnumber)%
}
\protected\def\set@color{%
  \LuaCol@setattribute\LuaCol@Attribute{%
    \directlua{%
      oberdiek.luacolor.get("\luaescapestring{\current@color}")%
    }%
  }%
 \aftergroup\reset@color
}
\def\reset@color{}
\def\luacolorProcessBox#1{%
  \directlua{%
    oberdiek.luacolor.process(\number#1)%
  }%
}
\directlua{%
  if luatexbase.callbacktypes.pre_shipout_filter then
    token.get_next()
  end
}\@secondoftwo\@gobble{
  \RequirePackage{atbegshi}[2011/01/30]
  \AtBeginShipout{%
    \luacolorProcessBox\AtBeginShipoutBox
  }
}
\set@color
\ifnum\outputmode=\@ne
    \let\LuaCol@org@pdfxform\saveboxresource
    \def\LuaCol@iii@i@ii#1#2#3{#3{#1}{#2}}
    \def\LuaCol@ii@i#1#2{{#2#1}}
    \def\LuaCol@if@keyword#1#2#3{%
      \expanded{\unexpanded{\LuaCol@iii@i@ii{#2}{#3}}\expandafter}%
      \directlua{%
        token.put_next(token.create(token.scan_keyword(token.scan_string())
        and '@firstoftwo'
        or '@secondoftwo'))
      }{#1}%
    }
    \def\LuaCol@scan@number{%
      \directlua{
        token.put_next(token.new(token.scan_int(), token.command_id'char_given'))
      }%
    }
    \def\LuaCol@scan@tobrace{%
      \directlua{
        local relax, space = token.command_id'relax', token.command_id'spacer'
        local t
        repeat
          t = token.scan_token()
        until not (t.command == relax or t.command == space)
        token.put_next(t)
      }%
    }
    \def\LuaCol@scan@boxresource@i#1#2{%
      \LuaCol@if@keyword{attr}{%
        \expanded{\unexpanded{\LuaCol@scan@boxresource@iI{#1#2attr}}%
          \expandafter\expandafter\expandafter}%
        \LuaCol@scan@tobrace
      }{%
        \LuaCol@scan@boxresource@ii{#1#2}%
      }%
    }
    \def\LuaCol@scan@boxresource@iI#1#2{\LuaCol@scan@boxresource@ii{#1{#2}}}
    \def\LuaCol@scan@boxresource@ii#1{%
      \LuaCol@if@keyword{resources}{%
        \expanded{\unexpanded{\LuaCol@scan@boxresource@iiI{#1resources}}%
          \expandafter\expandafter\expandafter}%
        \LuaCol@scan@tobrace
      }{%
        \LuaCol@scan@boxresource@iii{#1}%
      }%
    }
    \def\LuaCol@scan@boxresource@iiI#1#2{\LuaCol@scan@boxresource@iii{#1{#2}}}
    \def\LuaCol@scan@boxresource@iii#1{%
      \LuaCol@if@keyword{margin}{%
        \expanded{\unexpanded{\LuaCol@scan@boxresource@iv{#1margin }}%
          \expandafter\expandafter\expandafter}%
        \LuaCol@scan@number
      }{%
        \LuaCol@scan@boxresource@iv{#1}{}%
      }%
    }
    \def\LuaCol@scan@boxresource@iv#1#2{%
      \expanded{\unexpanded{\LuaCol@scan@boxresource@v{#1#2}}%
        \expandafter\expandafter\expandafter}%
      \LuaCol@scan@number
    }
    \def\LuaCol@scan@boxresource@v#1#2{%
      \luacolorProcessBox{#2}%
      \LuaCol@org@pdfxform#1#2%
    }

    \protected\def\saveboxresource{%
      \LuaCol@if@keyword{type}{%
        \expandafter
        \expanded{\unexpanded{\LuaCol@scan@boxresource@i{type }}%
          \expandafter\expandafter\expandafter}%
        \LuaCol@scan@number
      }{%
        \LuaCol@scan@boxresource@i{}{}%
      }%
    }
    \let\pdfxform\saveboxresource
\fi
\LuaCol@AtEnd%
\endinput
%%
%% End of file `luacolor.sty'.
