%%
%% This is file `luainputenc.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% luainputenc.dtx  (with options: `package')
%% This is a generated file.
%% 
%% Written in 2009, 2010 by Manuel Pegourie-Gonnard and Elie Roux.
%% 
%% This work is under the CC0 license. As an exception, the files
%% luainputenc.sty, lutf8.def and lutf8x.def have more restrictions.
%% See these file for more details.
%% 
%% People who helped on this package:
%%   Javier Bezos
%%   Will Robertson
%%   Hans Hagen
%%   Heiko Oberdiek
%%   Javier Mugica
%% 
%% This work consists of the main source file luainputenc.dtx
%% and the derived files
%%    luainputenc.sty, luainputenc.lua, lutf8.def, lutf8x.def,
%%    and luainputenc.pdf
%% 

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luainputenc}
  [2010/11/19 v0.973 inputenc package for LuaTeX]

%% This file was adapted from inputenc.sty, which copyright is:
%% Copyright 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004
%% 2005 2006 The LaTeX3 Project.
%%
%% inputenc.sty is under the lppl version 1.3c or later, and can be
%% found in the base LaTeX system.
%%
%% The lppl can be found at http://www.latex-project.org/lppl.txt
%%
%% The changes to inputenc.sty are Copyright 2009 Elie Roux, and are
%% under the CC0 license.
%%
%% The changes are LuaTeX support.
%%
%% This file is distributed under the CC0 license, with clause 6 of the
%% lppl as additional restrictions.


\RequirePackage{ifluatex}
\RequirePackage{ifxetex}

\ifxetex
  \DeclareOption{unactivate}{\PassOptionsToPackage{utf8}{xetex-inputenc}}
  \DeclareOption{lutf8}{\PassOptionsToPackage{utf8}{xetex-inputenc}}
  \DeclareOption{lutf8x}{\PassOptionsToPackage{utf8}{xetex-inputenc}}
  \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{xetex-inputenc}}
  \ProcessOptions*
  \RequirePackage{xetex-inputenc}
  \expandafter\endinput
\fi

\ifluatex\else
  \DeclareOption{unactivate}{\PassOptionsToPackage{utf8}{inputenc}}
  \DeclareOption{lutf8}{\PassOptionsToPackage{utf8}{inputenc}}
  \DeclareOption{lutf8x}{\PassOptionsToPackage{utf8}{inputenc}}
  \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{inputenc}}
  \ProcessOptions*
  \RequirePackage{inputenc}
  \expandafter\endinput
\fi


\RequirePackage{luatexbase}
\luatexbase@ensure@primitive{luaescapestring}

\RequireLuaModule{luainputenc}


\def\DeclareInputMath#1{%
   \@inpenc@test
   \bgroup
      \uccode`\~#1%
      \uppercase{%
   \egroup
      \def~%
   }%
}
\def\DeclareInputText#1#2{%
   \def\reserved@a##1 ${}%
   \def\reserved@b{#2}%
   \ifcat_\expandafter\reserved@a\meaning\reserved@b$ $_%
      \DeclareInputMath{#1}{#2}%
   \else
      \DeclareInputMath{#1}{\IeC{#2}}%
   \fi
}
\def\IeC{%
  \ifx\protect\@typeset@protect
    \expandafter\@firstofone
  \else
    \noexpand\IeC
  \fi
}

\def\inputencoding#1{%
  \the\inpenc@prehook
  \gdef\@inpenc@test{\global\let\@inpenc@test\relax}%
  \edef\@inpenc@undefined{\noexpand\@inpenc@undefined@{#1}}%
  \edef\inputencodingname{#1}%
  \@inpenc@loop\^^A\^^H%
  \@inpenc@loop\^^K\^^K%
  \@inpenc@loop\^^N\^^_%
  \xdef\saved@endlinechar{\the\endlinechar }%
  \endlinechar=-1
  \xdef\saved@space@catcode{\the\catcode`\ }%
  \catcode`\ 9\relax
  \input{#1.def}%
  \endlinechar=\saved@endlinechar{}%
  \catcode`\ \saved@space@catcode\relax
  \ifx\@inpenc@test\relax\else
    \PackageWarning{inputenc}%
             {No characters defined\MessageBreak
              by input encoding change to `#1'\MessageBreak}%
  \fi
  \the\inpenc@posthook
  \luatexbase@directlua{luainputenc.set_option("\luatexluaescapestring{#1}")}
}
\newtoks\inpenc@prehook
\newtoks\inpenc@posthook
\def\@inpenc@undefined@#1{\PackageError{inputenc}%
        {Keyboard character used is undefined\MessageBreak
         in inputencoding `#1'}%
       {You need to provide a  definition with
        \noexpand\DeclareInputText\MessageBreak or
        \noexpand\DeclareInputMath before using this key.}}%
\def\@inpenc@loop#1#2{%
  \@tempcnta`#1\relax
  \loop
    \catcode\@tempcnta\active
    \bgroup
      \uccode`\~\@tempcnta
      \uppercase{%
    \egroup
         \let~\inpenc@undefined
      }%
  \ifnum\@tempcnta<`#2\relax
     \advance\@tempcnta\@ne
  \repeat}


\DeclareOption{utf8}{%
  \inputencoding{lutf8}%
}

\DeclareOption{lutf8}{%
  \inputencoding{lutf8}%
}

\DeclareOption{utf8x}{%
  \inputencoding{lutf8}%
}

\DeclareOption{lutf8x}{%
  \inputencoding{lutf8x}%
}


\DeclareOption{unactivate}{%
  \edef\inputencodingname{unactivate}%
  \luatexbase@directlua{luainputenc.set_option([[unactivate]])}
}


\DeclareOption*{%
  \lIE@activate %
  \@inpenc@loop\^^?\^^ff%
  \inputencoding{\CurrentOption}%
}


\ifnum\luatexversion>42

    \newcommand*{\lIE@activate}[0]{%
      \luatexbase@directlua{luainputenc.register_callbacks()}%
    }

\else


\newcommand*\lIE@setstarted[0]{%
  \ifnum\lIE@activated=1 %
    \luatexbase@directlua{luainputenc.setstarted()}%
  \fi %
}

\newcommand*\lIE@setstopped[0]{%
  \ifnum\lIE@activated=1 %
    \luatexbase@directlua{luainputenc.setstopped()}%
  \fi %
}


\newcommand*\lIE@SetUtfFile[1]{%
  \luatexbase@directlua{luainputenc.set_unicode_file("\luatexluaescapestring{#1}")}%
}


\newcommand*\lIE@SetNonUtfFile[1]{%
  \luatexbase@directlua{luainputenc.set_non_unicode_file("\luatexluaescapestring{#1}")}%
}


\newcommand*\lIE@UnsetFile[1]{%
  \luatexbase@directlua{luainputenc.unset_file("\luatexluaescapestring{#1}")}%
}


\newcommand*\lIE@SetUtfExt[1]{%
  \luatexbase@directlua{luainputenc.set_unicode_extention("\luatexluaescapestring{#1}")}%
}


\newcommand*\lIE@SetNonUtfExt[1]{
  \luatexbase@directlua{luainputenc.set_non_unicode_extention("\luatexluaescapestring{#1}")}
}


\newcommand*\lIE@InputUtfFile[1]{%
  \lIE@SetUtfFile{#1}%
  \input #1%
  \lIE@UnsetFile{#1}%
}


\newcommand*\lIE@InputNonUtfFile[1]{%
  \lIE@SetNonUtfFile{#1}%
  \input #1%
  \lIE@UnsetFile{#1}%
}


\newcommand*\InputUtfFile[1]{%
  \lIE@InputUtfFile{#1}%
}

\newcommand*\InputNonUtfFile[1]{%
  \lIE@InputNonUtfFile{#1}%
}

\newcount\lIE@activated

\newcommand*{\lIE@activate}[0]{%
  \lIE@activated=1 %
  \lIE@setstarted %
}

\newcommand*{\lIE@FromInputenc}[1]{%
  \ifnum\lIE@activated=0 %
    \lIE@activate %
  \fi%
}

\fi

\ProcessOptions*

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