%%
%% This is file `luatextra.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% luatextra.dtx  (with options: `package')
%% This is a generated file.
%% 
%% Copyright (C) 2009 by Elie Roux <elie.roux@telecom-bretagne.eu>
%% 
%% This work is under the CC0 license.
%% 
%% This work consists of the main source file luainputenc.dtx
%% and the derived files
%%     luatextra.sty, luatextra.lua, luatextra-latex.tex, luatextra.pdf
%% 
\csname ifluatextraloaded\endcsname
\let\ifluatextraloaded\endinput


\expandafter\ifx\csname ProvidesPackage\endcsname\relax
  \expandafter\ifx\csname ifluatex\endcsname\relax
    \input ifluatex.sty
  \fi
\else
  \RequirePackage{ifluatex}
  \NeedsTeXFormat{LaTeX2e}
  \ProvidesPackage{luatextra}
    [2009/12/16 v0.95 LuaTeX extra low-level macros]
  \RequirePackage{etex}[1998/03/26]
\fi


\def\LuaTeX{Lua\TeX }
\def\LuaLaTeX{Lua\LaTeX }


\ifluatex\else
  \expandafter\ifx\csname ProvidesPackage\endcsname\relax
    \immediate\write16{}
    \immediate\write16{Package luatextra Warning: this package should be used with LuaTeX.}
  \else
    \PackageWarning{luatextra}{this package should be used with LuaTeX.}
  \fi
  \expandafter\endinput
\fi

\expandafter\ifx\csname ProvidesPackage\endcsname\relax
  \def\luatexRequireModule#1#2{\luadirect{luatextra.require_module([[#1]], [[#2]])}}
\else
  \RequirePackage{environ}
  \NewEnviron{luacode}{\luadirect{\BODY}}
  \newcommand\luatexRequireModule[2][0]{\luadirect{luatextra.require_module([[#2]], [[#1]])}}
  \input luatextra-latex.tex
\fi


\ifnum\luatexversion<36
  \def\directlua{\pdfprimitive\directlua0}
  \def\latelua{\pdfprimitive\latelua0}
  \def\luadirect{\pdfprimitive\directlua0}
  \def\lualate{\pdfprimitive\latelua0}
  \def\luatexattribute{\attribute}
  \def\luatexattributedef{\attributedef}
  \def\luatexclearmarks{\pdfprimitive\luaclearmarks}
  \def\luatexformatname{\pdfprimitive\formatname}
  \def\luatexscantexttokens{\pdfprimitive\scantexttokens}
  \def\luatexcatcodetable{\catcodetable}
  \def\initluatexcatcodetable{\pdfprimitive\initcatcodetable}
  \def\saveluatexcatcodetable{\pdfprimitive\savecatcodetable}
  \def\luaclose{\pdfprimitive\closelua}
\else
  \directlua{tex.enableprimitives('luatex', {'attribute'})}
  \directlua{tex.enableprimitives('luatex', {'attributedef'})}
  \directlua{tex.enableprimitives('luatex', {'clearmarks'})}
  \directlua{tex.enableprimitives('luatex', {'formatname'})}
  \directlua{tex.enableprimitives('luatex', {'scantexttokens'})}
  \directlua{tex.enableprimitives('luatex', {'catcodetable'})}
  \directlua{tex.enableprimitives('luatex', {'latelua'})}
  \directlua{tex.enableprimitives('luatex', {'initcatcodetable'})}
  \directlua{tex.enableprimitives('luatex', {'savecatcodetable'})}
  \directlua{tex.enableprimitives('luatex', {'closelua'})}
  \let\luadirect\directlua
  \let\lualate\luatexlatelua
  \let\initluatexcatcodetable\luatexinitcatcodetable
  \let\saveluatexcatcodetable\luatexsavecatcodetable
  \let\luaclose\luatexcloselua
\fi


\luadirect{dofile(kpse.find_file("luatextra.lua"))}


\def\ltxtra@RegisterFontCallback{
  \luadirect{luatextra.register_font_callback()}
}


\def\luatexModuleError#1#2{%
  \errorcontextlines=0\relax
  \immediate\write16{}%
  \errmessage{Module #1 error: #2^^J^^J%
See the module #1 documentation for explanation.^^J ...^^J}%
}

\def\luatexUseModule#1{\luadirect{luatextra.use_module([[#1]])}}


\newcount\luatexattdefcounter
\luatexattdefcounter = 1

\def\newluatexattribute#1{%
  \ifnum\luatexattdefcounter<65535\relax %
    \global\advance\luatexattdefcounter by 1\relax %
    \allocationnumber\luatexattdefcounter %
    \ifluatex %
      \global\luatexattributedef#1=\allocationnumber %
    \fi %
    \wlog{\string#1=\string\luatexattribute\the\allocationnumber}%
    \luadirect{%
      luatextra.attributedef_from_tex([[\noexpand#1]], '\number\allocationnumber')}%
  \else %
    \errmessage{No room for a new \string\attribute}%
  \fi %
}


\def\setluatexattribute#1#2{%
  #1=\numexpr#2\relax %
}

\def\unsetluatexattribute#1{%
  \ifnum\luatexversion<37\relax %
    #1=-1\relax %
  \else %
    #1=-"7FFFFFFF\relax %
  \fi %
}


\newcount\luatexcatcodetabledefcounter

\luatexcatcodetabledefcounter = 1

\def\newluatexcatcodetable#1{%
  \ifnum\luatexcatcodetabledefcounter<1114110\relax % 0x10FFFF is maximal \chardef
    \global\advance\luatexcatcodetabledefcounter by 1\relax %
    \allocationnumber=\luatexcatcodetabledefcounter %
    \global\chardef#1=\allocationnumber %
    \luadirect{%
      luatextra.catcodetabledef_from_tex([[\noexpand#1]], '\number\allocationnumber')}%
    \wlog{\string#1=\string\catcodetable\the\allocationnumber}%
  \else %
    \errmessage{No room for a new \string\catcodetable}%
  \fi %
}


\expandafter\edef\csname ltxtra@AtEnd\endcsname{%
  \catcode64 \the\catcode64\relax
}

\catcode 64=11\relax

\expandafter\ifx\csname @tempcnta\endcsname\relax
  \csname newcount\endcsname\@tempcnta
\fi
\expandafter\ifx\csname @tempcntb\endcsname\relax
  \csname newcount\endcsname\@tempcntb
\fi


\def\luatexsetcatcoderange#1#2#3{%
  \edef\luaSCR@temp{%
    \noexpand\@tempcnta=\the\@tempcnta
    \noexpand\@tempcntb=\the\@tempcntb
    \noexpand\count@=\the\count@
    \relax
  }%
  \@tempcnta=#1\relax
  \@tempcntb=#2\relax
  \count@=#3\relax
  \loop\unless\ifnum\@tempcnta>\@tempcntb
    \catcode\@tempcnta=\count@
    \advance\@tempcnta by 1\relax
  \repeat
  \luaSCR@temp
}


\newluatexcatcodetable\CatcodeTableIniTeX
\newluatexcatcodetable\CatcodeTableString
\newluatexcatcodetable\CatcodeTableOther
\newluatexcatcodetable\CatcodeTableLaTeX
\newluatexcatcodetable\CatcodeTableLaTeXAtLetter
\newluatexcatcodetable\CatcodeTableExpl
\initluatexcatcodetable\CatcodeTableIniTeX

\expandafter\ifx\csname @firstofone\endcsname\relax
  \long\def\@firstofone#1{#1}%
\fi

\begingroup
  \def\@makeother#1{\catcode#1=12\relax}%
  \@firstofone{%
    \luatexcatcodetable\CatcodeTableIniTeX
    \begingroup
      \luatexsetcatcoderange{0}{8}{15}%
      \catcode9=10  % tab
      \catcode11=15 %
      \catcode12=13 % form feed
      \luatexsetcatcoderange{14}{31}{15}%
      \catcode35=6 % hash
      \catcode36=3 % dollar
      \catcode38=4 % ampersand
      \catcode94=7 % circumflex
      \catcode95=8 % underscore
      \catcode123=1 % brace left
      \catcode125=2 % brace right
      \catcode126=13 % tilde
      \catcode127=15 %
      \saveluatexcatcodetable\CatcodeTableLaTeX
      \catcode64=11 %
      \saveluatexcatcodetable\CatcodeTableLaTeXAtLetter
    \endgroup
    \begingroup
      \luatexsetcatcoderange{0}{8}{15}%
      \catcode9=9 % tab ignored
      \catcode11=15 %
      \catcode12=13 % form feed
      \luatexsetcatcoderange{14}{31}{15}%
      \catcode32=9 % space is ignored
      \catcode35=6 % hash mark is macro parameter character
      \catcode36=3 % dollar (not so sure about the catcode...)
      \catcode38=4 % ampersand
      \catcode58=11 % colon letter
      \catcode94=7 % circumflex is superscript character
      \catcode95=11 % underscore letter
      \catcode123=1 % left brace is begin-group character
      \catcode125=2 % right brace is end-group character
      \catcode126=10 % tilde is a space char.
      \catcode127=15 %
      \saveluatexcatcodetable\CatcodeTableExpl
    \endgroup
    \@makeother{0}% nul
    \@makeother{13}% carriage return
    \@makeother{37}% percent
    \@makeother{92}% backslash
    \@makeother{127}%
    \luatexsetcatcoderange{65}{90}{12}% A-Z
    \luatexsetcatcoderange{97}{122}{12}% a-z
    \saveluatexcatcodetable\CatcodeTableString
    \@makeother{32}% space
    \saveluatexcatcodetable\CatcodeTableOther
  \endgroup
}

\ltxtra@AtEnd

\luadirect{luatextra.catcodetable_do_shortcuts()}


\let\newluaattribute\newluatexattribute
\let\luaattribute\luatexattribute
\let\unsetluaattribute\unsetluatexattribute
\let\initluacatcodetable\initluatexcatcodetable
\let\luasetcatcoderange\luatexsetcatcoderange
\let\newluacatcodetable\newluatexcatcodetable
\let\setluaattribute\setluatexattribute
\let\luaModuleError\luatexModuleError
\let\luaRequireModule\luatexRequireModule
\let\luaUseModule\luatexUseModule


\expandafter\ifx\csname ProvidesPackage\endcsname\relax
  \input luaotfload.sty
\else
  \RequirePackage{luaotfload}
\fi

\endinput
%%
%% End of file `luatextra.sty'.
