%% %% This is file `ocamltex.sty', %% %% Copyright (C) 2006 by Geoffrey Alan Washburn %% Copyright (C) 2004 by Scott Pakin %% %% This file may be distributed and/or modified under the conditions of %% the LaTeX Project Public License, either version 1.2 of this license %% or (at your option) any later version. The latest version of this %% license is in: %% %% http://www.latex-project.org/lppl.txt %% %% and version 1.2 or later is part of all distributions of LaTeX version %% 1999/12/01 or later. %% \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesPackage{ocamltex} [2004/10/07 v1.2 LaTeX macros for use with OCamlTeX] \newif\ifmlmac@have@ocamltex \mlmac@have@ocamltextrue \@ifundefined{mlmac@tag}{\mlmac@have@ocamltexfalse}{} \@ifundefined{mlmac@tofile}{\mlmac@have@ocamltexfalse}{} \@ifundefined{mlmac@fromfile}{\mlmac@have@ocamltexfalse}{} \@ifundefined{mlmac@toflag}{\mlmac@have@ocamltexfalse}{} \@ifundefined{mlmac@fromflag}{\mlmac@have@ocamltexfalse}{} \@ifundefined{mlmac@doneflag}{\mlmac@have@ocamltexfalse}{} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \def\getlength@i#1{\ifx#1\end \let\next=\relax \else \ifx#1\comma \advance\count0 by1 \let\next=\getlength@ii \else \let\next=\getlength@ii\fi\fi \next} \def\getlength@ii#1{\ifx#1\end \advance\count0 by1 \let\next=\relax \else \ifx#1\comma \advance\count0 by1 \let\next=\getlength@ii \else \let\next=\getlength@ii\fi\fi \next} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ifmlmac@have@ocamltex \else \PackageError{ocamltex}{Document must be compiled using ocamltex} {Instead of compiling your document directly with latex, you need to\MessageBreak use the ocamltex script. \space ocamltex sets up a variety of macros needed by\MessageBreak the ocamltex package as well as a listener process needed for\MessageBreak communication between LaTeX and OCaml.} \fi \def\ocamlnewcommand{% \let\mlmac@command=\newcommand \let\mlmac@next=\relax %\@ifnextchar*{\mlmac@newcommand@i}{\mlmac@newcommand@i!}% \mlmac@newcommand@i!% } \def\ocamlrenewcommand{% \let\mlmac@command=\renewcommand \let\mlmac@next=\relax %\@ifnextchar*{\mlmac@newcommand@i}{\mlmac@newcommand@i!}% \mlmac@newcommand@i!% } \def\mlmac@newcommand@i#1#2{% \ifx#1*% \def\mlmac@starchar{*}% \else \def\mlmac@starchar{}% \fi \def\mlmac@macname{#2}% \let\mlmac@oldbody=#2\relax \expandafter\def\expandafter\mlmac@cleaned@macname\expandafter{% \expandafter\string\mlmac@macname}% \@ifnextchar[{\mlmac@newcommand@ii}{\mlmac@newcommand@ii[]}%] } \def\mlmac@newcommand@ii[#1]{% \begingroup \count0=0 % \let\comma=,% \getlength@i#1\end % \xdef\mlmac@numargs{\number\count0}% \xdef\mlmac@argsstr{#1}% \endgroup \@ifnextchar[{\mlmac@newcommand@iii@opt} {\mlmac@newcommand@iii@no@opt}%] } \def\mlmac@newcommand@iii@opt[#1]{% \def\mlmac@defarg{#1}% \mlmac@haveargs } \def\mlmac@newcommand@iii@no@opt{% \let\mlmac@defarg=\relax \mlmac@haveargs } \newtoks\mlmac@ocamlcode \def\mlmac@haveargs{% \begingroup \let\do\@makeother\dospecials \catcode`\^^M=\active \newlinechar`\^^M \endlinechar=`\^^M \catcode`\{=1 \catcode`\}=2 \afterassignment\mlmac@havecode \global\mlmac@ocamlcode } {\catcode`\^^M=11\gdef\mlmac@sep{^^M}} \newcount\mlmac@argnum \def\mlmac@havecode{% \endgroup \edef\mlmac@define@sub{% \noexpand\mlmac@write@ocaml{DEF\mlmac@sep \mlmac@tag\mlmac@sep \mlmac@cleaned@macname\mlmac@sep \mlmac@tag\mlmac@sep \mlmac@argsstr\mlmac@sep \mlmac@tag\mlmac@sep \the\mlmac@ocamlcode }% }% \mlmac@define@sub \edef\mlmac@body{% USE\mlmac@sep \mlmac@tag\mlmac@sep \mlmac@cleaned@macname }% \let\mlmac@hash=\relax \mlmac@argnum=1% \loop \ifnum\mlmac@numargs<\mlmac@argnum \else \edef\mlmac@body{% \mlmac@body\mlmac@sep\mlmac@tag%\mlmac@sep \mlmac@hash\mlmac@hash\number\mlmac@argnum}% \advance\mlmac@argnum by 1% \repeat \let\mlmac@hash=##\relax \expandafter\let\mlmac@macname=\relax \ifx\mlmac@defarg\relax \edef\mlmac@define@command{% \noexpand\mlmac@command\mlmac@starchar{\mlmac@macname}% [\mlmac@numargs]{% \noexpand\mlmac@write@ocaml{\mlmac@body}% }% }% \else \edef\mlmac@define@command{% \noexpand\mlmac@command\mlmac@starchar{\mlmac@macname}% [\mlmac@numargs][\mlmac@defarg]{% \noexpand\mlmac@write@ocaml{\mlmac@body}% }% }% \fi \expandafter\let\mlmac@macname=\mlmac@oldbody \mlmac@define@command \mlmac@next } \def\ocamlexec{% \let\mlmac@next=\relax \begingroup \let\do\@makeother\dospecials \catcode`\^^M=\active \newlinechar`\^^M \endlinechar=`\^^M \catcode`\{=1 \catcode`\}=2 \afterassignment\mlmac@exec@havecode \global\mlmac@ocamlcode } {\catcode`\^^M=11\gdef\mlmac@sep{^^M}} \def\mlmac@exec@havecode{% \endgroup \edef\mlmac@exec{% \noexpand\mlmac@write@ocaml{EXEC\mlmac@sep \mlmac@tag\mlmac@sep \the\mlmac@ocamlcode }% }% \mlmac@exec \mlmac@next } \def\ocamlnewenvironment{% \let\mlmac@command=\newcommand \let\mlmac@next=\mlmac@end@environment %\@ifnextchar*{\mlmac@newenvironment@i}{\mlmac@newenvironment@i!}% \mlmac@newenvironment@i!% } \def\ocamlrenewenvironment{% \let\mlmac@command=\renewcommand \let\mlmac@next=\mlmac@end@environment %\@ifnextchar*{\mlmac@newenvironment@i}{\mlmac@newenvironment@i!}% \mlmac@newenvironment@i!% } \def\mlmac@newenvironment@i#1#2{% \ifx#1*% \def\mlmac@starchar{*}% \else \def\mlmac@starchar{}% \fi \def\mlmac@envname{#2}% \expandafter\def\expandafter\mlmac@macname\expandafter{\csname#2\endcsname}% \expandafter\let\expandafter\mlmac@oldbody\mlmac@macname\relax \expandafter\def\expandafter\mlmac@cleaned@macname\expandafter{% \expandafter\string\mlmac@macname}% \@ifnextchar[{\mlmac@newcommand@ii}{\mlmac@newcommand@ii[0]}%] } \def\mlmac@end@environment{% \expandafter\def\expandafter\mlmac@next\expandafter{\expandafter \let\csname end\mlmac@envname\endcsname=\mlmac@end@macro \let\mlmac@next=\relax }% \def\mlmac@macname{\mlmac@end@macro}% \expandafter\let\expandafter\mlmac@oldbody\csname end\mlmac@envname\endcsname \expandafter\def\expandafter\mlmac@cleaned@macname\expandafter{% \expandafter\string\mlmac@macname}% \@ifnextchar[{\mlmac@newcommand@ii}{\mlmac@newcommand@ii[0]}%] } \newif\ifmlmac@file@exists \newcommand{\mlmac@await@existence}[1]{% \loop \IfFileExists{#1}% {\mlmac@file@existstrue}% {\mlmac@file@existsfalse}% \ifmlmac@file@exists \else \repeat } \newwrite\mlmac@outfile \newcommand{\mlmac@write@ocaml}{% \begingroup \let\do\@makeother\dospecials \catcode`\^^M=\active \newlinechar`\^^M \endlinechar=`\^^M \catcode`\{=1 \catcode`\}=2 \mlmac@write@ocaml@i } \ifmlmac@have@ocamltex \newcommand{\mlmac@write@ocaml@i}[1]{% \immediate\openout\mlmac@outfile=\mlmac@tofile\relax \let\protect=\noexpand \def\begin{\noexpand\begin}% \def\end{\noexpand\end}% \immediate\write\mlmac@outfile{#1}% \immediate\closeout\mlmac@outfile \endgroup \immediate\openout\mlmac@outfile=\mlmac@toflag\relax \immediate\closeout\mlmac@outfile \mlmac@await@existence\mlmac@fromflag \immediate\openout\mlmac@outfile=\mlmac@tofile\relax \immediate\closeout\mlmac@outfile \mlmac@await@existence\mlmac@doneflag \input\mlmac@fromfile\relax } \else \newcommand{\mlmac@write@ocaml@i}[1]{\endgroup} \AtBeginDocument{% \renewcommand{\mlmac@write@ocaml@i}[1]{% \def\mlmac@show@placeholder##1##2\@empty{% \ifx##1D\relax \endgroup \else \endgroup \fbox{OCaml\TeX}% \fi }% \mlmac@show@placeholder#1\@empty }% } \fi \endinput %% %% End of file `ocamltex.sty'.