%%
%% This is file `luamplib.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% luamplib.dtx  (with options: `package')
%% 
%% See source file 'luamplib.dtx' for licencing and contact information.
%% 
\bgroup\expandafter\expandafter\expandafter\egroup
\expandafter\ifx\csname ProvidesPackage\endcsname\relax
  \input luatexbase-modutils.sty
\else
  \NeedsTeXFormat{LaTeX2e}
  \ProvidesPackage{luamplib}
    [2014/01/23 v2.3 mplib package for LuaTeX]
  \RequirePackage{luatexbase-modutils}
  \RequirePackage{pdftexcmds}
\fi
\RequireLuaModule{luamplib}
\def\mplibsetformat#1{%
  \directlua{luamplib.setformat("\luatexluaescapestring{#1}")}}
\ifnum\pdfoutput>0
    \let\mplibtoPDF\pdfliteral
\else
    %\def\MPLIBtoPDF#1{\special{pdf:literal direct #1}} % not ok yet
    \def\mplibtoPDF#1{}
    \expandafter\ifx\csname PackageWarning\endcsname\relax
      \write16{}
      \write16{Warning: MPLib only works in PDF mode, no figure will be output.}
      \write16{}
    \else
      \PackageWarning{mplib}{MPLib only works in PDF mode, no figure will be output.}
    \fi
\fi
\def\mplibsetupcatcodes{%
  %catcode`\{=12 %catcode`\}=12
  \catcode`\#=12
  \catcode`\^=12 \catcode`\~=12 \catcode`\_=12
  %catcode`\%=12 %% don^^e2^^80^^99t in Plain!
  \catcode`\&=12 \catcode`\$=12
}
\def\mplibputtextbox#1{\vbox to 0pt{\vss\hbox to 0pt{\raise\dp#1\copy#1\hss}}}
\bgroup\expandafter\expandafter\expandafter\egroup
\expandafter\ifx\csname ProvidesPackage\endcsname\relax
\def\mplibcode{%
  \begingroup
  \bgroup
  \mplibsetupcatcodes
  \mplibdocode %
}
\long\def\mplibdocode#1\endmplibcode{%
  \egroup
  \def\mplibtemp{\directlua{luamplib.protecttextext([===[\unexpanded{#1}]===])}}%
  \directlua{luamplib.tempdata = luamplib.makeTEXboxes([===[\mplibtemp]===])}%
  \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
  \endgroup
}
\else
\newenvironment{mplibcode}{\toks@{}\ltxdomplibcode}{}
\def\ltxdomplibcode{%
  \begingroup
  \mplibsetupcatcodes
  \ltxdomplibcodeindeed %
}
\long\def\ltxdomplibcodeindeed#1\end#2{%
  \endgroup
  \toks@\expandafter{\the\toks@#1}%
  \ifnum\pdf@strcmp{#2}{mplibcode}=\z@
    \def\reserved@a{\directlua{luamplib.protecttextext([===[\the\toks@]===])}}%
    \directlua{luamplib.tempdata=luamplib.makeTEXboxes([===[\reserved@a]===])}%
    \directlua{luamplib.processwithTEXboxes(luamplib.tempdata)}%
    \end{mplibcode}%
  \else
    \toks@\expandafter{\the\toks@\end{#2}}\expandafter\ltxdomplibcode
  \fi
}
\fi
\newtoks\everymplibtoks
\newtoks\everyendmplibtoks
\protected\def\everymplib{%
  \begingroup
  \mplibsetupcatcodes
  \mplibdoeverymplib
}
\def\mplibdoeverymplib#1{%
  \endgroup
  \everymplibtoks{#1}%
}
\protected\def\everyendmplib{%
  \begingroup
  \mplibsetupcatcodes
  \mplibdoeveryendmplib
}
\def\mplibdoeveryendmplib#1{%
  \endgroup
  \everyendmplibtoks{#1}%
}
\def\mpdim#1{ begingroup \the\dimexpr #1\relax\space endgroup } % gmp.sty
\ifx\mplibscratchbox\undefined \newbox\mplibscratchbox \fi
\def\mplibstarttoPDF#1#2#3#4{%
  \hbox\bgroup
  \xdef\MPllx{#1}\xdef\MPlly{#2}%
  \xdef\MPurx{#3}\xdef\MPury{#4}%
  \xdef\MPwidth{\the\dimexpr#3bp-#1bp\relax}%
  \xdef\MPheight{\the\dimexpr#4bp-#2bp\relax}%
  \parskip0pt%
  \leftskip0pt%
  \parindent0pt%
  \everypar{}%
  \setbox\mplibscratchbox\vbox\bgroup
  \noindent
}
\def\mplibstoptoPDF{%
  \egroup %
  \setbox\mplibscratchbox\hbox %
    {\hskip-\MPllx bp%
     \raise-\MPlly bp%
     \box\mplibscratchbox}%
  \setbox\mplibscratchbox\vbox to \MPheight
    {\vfill
     \hsize\MPwidth
     \wd\mplibscratchbox0pt%
     \ht\mplibscratchbox0pt%
     \dp\mplibscratchbox0pt%
     \box\mplibscratchbox}%
  \wd\mplibscratchbox\MPwidth
  \ht\mplibscratchbox\MPheight
  \box\mplibscratchbox
  \egroup
}
\def\mplibtextext#1#2#3#4#5{%
  \begingroup
  \setbox\mplibscratchbox\hbox
    {\font\temp=#1 at #2bp%
     \temp
     #3}%
  \setbox\mplibscratchbox\hbox
    {\hskip#4 bp%
     \raise#5 bp%
     \box\mplibscratchbox}%
  \wd\mplibscratchbox0pt%
  \ht\mplibscratchbox0pt%
  \dp\mplibscratchbox0pt%
  \box\mplibscratchbox
  \endgroup
}
\endinput
%%
%% End of file `luamplib.sty'.
