[tcode] 01/03: Imported Upstream version 0.1.20080917
Andreas Tille
tille at debian.org
Fri Apr 18 23:00:47 UTC 2014
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository tcode.
commit f843ce79c9266d0f8ef42c1849da3141323c489d
Author: Andreas Tille <tille at debian.org>
Date: Sat Apr 19 00:49:12 2014 +0200
Imported Upstream version 0.1.20080917
---
PdfLatex.tex | 196 +++++++++++
README | 103 ++++++
Tcode.bat | 6 +
Tcode.sh | 22 ++
Tcoderc | 21 ++
Texjava.tex | 527 ++++++++++++++++++++++++++++
build.xml | 108 ++++++
lmac.sty | 193 ++++++++++
setl2hinit.pl | 71 ++++
tcode.bbl | 24 ++
tcode.jar | Bin 0 -> 6891 bytes
tcode.pdf | Bin 0 -> 165488 bytes
tcode.perl | 339 ++++++++++++++++++
tcode.properties | 3 +
tcode.sty | 214 ++++++++++++
tcode.tex | 1023 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
texjava.pl | 926 ++++++++++++++++++++++++++++++++++++++++++++++++
17 files changed, 3776 insertions(+)
diff --git a/PdfLatex.tex b/PdfLatex.tex
new file mode 100644
index 0000000..3ece40a
--- /dev/null
+++ b/PdfLatex.tex
@@ -0,0 +1,196 @@
+\defclass{PdfLatex}
+
+This task allows one to automate the PDF documentation generation.
+It uses pdf\LaTeX{} to convert the \LaTeX{} documentation into
+PDF. To avoid errors when using the \LaTeX{} {\tt hyperref}
+package, all {\tt .aux} files are first deleted. The pdf\LaTeX{}
+program is then called one time to make an initial run.
+BIB\TeX{} is called to generate to bibliography file, then
+pdf\LaTeX{} is called two more times to fix references
+and table of contents. It always runs pdf\LaTeX{} in
+\emph{nonstop} interaction mode, preventing it from
+blocking on errors. It is therefore recommended to sometimes
+run pdf\LaTeX{} manually to ensure that all documentation
+is free from syntax errors.
+This seems a lot of work, but it is necessary to get a fully-automated
+documentation building system.
+
+\paragraph{Supported attributes.}
+This task supports only one attribute.
+
+\noindent
+{\tt latexfile}
+
+\begin{tab}
+This gives the name of the file to be converted.
+\end{tab}
+
+\paragraph{Example.}
+
+As an example, this is the command used to produce
+the PDF file for the {\tt util} package.
+
+\begin{verbatim}
+ <pdflatex latexfile="src/umontreal/iro/lecuyer/util/guideutil.tex"/>
+\end{verbatim}
+
+\bigskip\hrule\bigskip
+
+\begin{code}
+package umontreal.iro.lecuyer.tcode;\begin{hide}
+
+import org.apache.tools.ant.util.*;
+import org.apache.tools.ant.*;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.Delete;
+import org.apache.tools.ant.taskdefs.LogStreamHandler;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.FileList;
+import org.apache.tools.ant.types.FileSet;
+import java.util.Enumeration;
+import java.util.Vector;
+import java.io.IOException;
+import java.io.FileReader;
+import java.io.BufferedReader;
+import java.io.File;\end{hide}
+
+public class PdfLatex extends Task\begin{hide} {
+ private File latexFile;\end{hide}
+
+ public File getLatexfile()\begin{hide} {
+ return latexFile;
+ }\end{hide}
+\end{code}
+\begin{tabb} Returns the name of the \LaTeX{} file to be processed.
+\end{tabb}
+\begin{code}
+
+ public void setLatexfile (File latexFile)\begin{hide} {
+ this.latexFile = latexFile;
+ }\end{hide}
+\end{code}
+\begin{tabb} Sets the name of the \LaTeX{} file to be processed.
+\end{tabb}
+\begin{code}
+
+ public void execute() throws BuildException\begin{hide} {
+ if (latexFile == null)
+ throw new BuildException ("No LaTeX file given", getLocation());
+ if (!latexFile.exists())
+ throw new BuildException ("Given LaTeX file " + latexFile.getAbsoluteFile() +
+ " does not exist", getLocation());
+ boolean mustrebuild = false;
+ GlobPatternMapper m = new GlobPatternMapper();
+ m.setFrom ("*.tex");
+ m.setTo ("*.pdf");
+ File pdfFile = new File (latexFile.getParentFile(), m.mapFileName (latexFile.getName())[0]);
+ if (latexFile.lastModified() > pdfFile.lastModified())
+ mustrebuild = true;
+ // Open the LaTeX file and check for \include's.
+ // If one \include'd file is more recent than the PDf,
+ // we rebuild the PDF.
+ final String INCCMD = "\\include";
+ try {
+ BufferedReader mainin = new BufferedReader (new FileReader (latexFile));
+ String li = null;
+ while ((li = mainin.readLine()) != null && !mustrebuild) {
+ String incarg = null;
+ int idx = li.indexOf ('%');
+ if (idx != -1)
+ // Strip off TeX comments
+ li = li.substring (0, idx);
+
+ idx = li.indexOf (INCCMD);
+ // Have an include command been found?
+ // Is it \include or something else, like \includex?
+ if (idx != -1 && !Character.isLetter (li.charAt (idx+INCCMD.length()))) {
+ for (idx = idx + INCCMD.length();
+ idx < li.length() && Character.isWhitespace (li.charAt (idx)); idx++);
+ if (idx == li.length())
+ log ("Could not find argument to \\include command", Project.MSG_WARN);
+ if (li.charAt (idx) == '{') {
+ int idx2 = idx + 1;
+ for (; idx2 < li.length() && li.charAt (idx2) != '}'; idx2++);
+ if (idx2 == li.length())
+ log ("Could not find matching brace for \\include command", Project.MSG_WARN);
+ else
+ incarg = li.substring (idx+1, idx2).trim();
+ }
+ else
+ incarg = li.substring (idx,idx+1);
+ }
+
+ // If an argument to include command could be found,
+ // locate the included file and check the date.
+ if (incarg != null) {
+ File texFile = new File (latexFile.getParentFile(), incarg + ".tex");
+ if (!texFile.exists())
+ log ("The included file " + texFile.getAbsolutePath() + " could not be found",
+ Project.MSG_WARN);
+ else if (texFile.lastModified() > pdfFile.lastModified())
+ mustrebuild = true;
+ }
+ }
+ mainin.close();
+ }
+ catch (IOException e) {
+ throw new BuildException ("Cannot open the input LaTeX file",
+ e, getLocation());
+ }
+
+ if (!mustrebuild)
+ return;
+
+ Execute exe = new Execute
+ (new LogStreamHandler
+ (this, Project.MSG_VERBOSE, Project.MSG_WARN));
+ exe.setAntRun (getProject());
+ exe.setWorkingDirectory (latexFile.getParentFile());
+ Delete del = new Delete();
+ del.setDir (latexFile.getParentFile());
+ del.setIncludes ("*.aux");
+ for (int i = 0; i < 3; i++) {
+ if (i == 0)
+ log ("Initial run of pdfLaTeX on " + latexFile.getAbsoluteFile());
+ else if (i == 1)
+ log ("Reference updating run of pdfLaTeX on " + latexFile.getAbsoluteFile());
+ else
+ log ("Updating toc run of pdfLaTeX on " + latexFile.getAbsoluteFile());
+ Commandline cmd = new Commandline();
+ cmd.setExecutable ("pdflatex");
+ cmd.createArgument().setValue ("-interaction");
+ cmd.createArgument().setValue ("nonstopmode");
+ cmd.createArgument().setFile (latexFile);
+ exe.setCommandline (cmd.getCommandline());
+ try {
+ exe.execute();
+ }
+ catch (IOException e) {
+ throw new BuildException ("Error executing pdfLaTeX", e, getLocation());
+ }
+ if (exe.getExitValue() != 0)
+ throw new BuildException ("Could not execute pdfLaTeX", getLocation());
+
+ if (i == 0) {
+ log ("Running bibTeX on " + latexFile.getAbsoluteFile());
+ cmd = new Commandline();
+ cmd.setExecutable ("bibtex");
+ m.setTo ("*");
+ cmd.createArgument().setFile
+ (new File (latexFile.getParentFile(), m.mapFileName (latexFile.getName())[0]));
+ exe.setCommandline (cmd.getCommandline());
+ try {
+ exe.execute();
+ }
+ catch (IOException e) {
+ throw new BuildException ("Error executing bibTeX", e, getLocation());
+ }
+ if (exe.getExitValue() != 0)
+ log ("Could not execute bibTeX");
+ }
+ }
+ }
+}\end{hide}
+\end{code}
+\begin{tabb} Executes the task.
+\end{tabb}
\ No newline at end of file
diff --git a/README b/README
new file mode 100644
index 0000000..ca46f81
--- /dev/null
+++ b/README
@@ -0,0 +1,103 @@
+TCode, Tools for documenting Java programs in LaTeX
+===================================================
+
+TCode Installation Manual
+=======================
+
+1. Requirements
+==================================
+
+To use texjava.pl, a Perl 5 interpreter is needed. To produce Javadoc
+HTML contents, LaTeX2HTML 2002-2-1 or later is needed. Under Windows,
+these two components have to be installed separately. A Java 2
+Software Development Kit (SDK) is required to take part of TCode. To
+use the Ant tasks, Apache Ant 1.5.3 or later is required. TCode
+assumes that Perl, LaTeX2HTML and JDK's bin directories are part of
+the PATH environment variable.
+
+2. Unpacking
+-------------
+Unpack the zip file to any location.
+
+Linux command :
+ unzip tcode-<DATE>.zip
+
+Under Microsoft Windows, WinZip can be used to extract the ZIP file.
+
+The created tcode subdirectory will contain the following files
+
+ build.xml - Ant build file to construct TCode
+ javatex.pl - Javatex Perl script
+ PdfLatex.tex - LaTeX source file for the PdfLatex Ant task
+ README - this file
+ tcode.jar - TCode JAR archive for Ant tasks
+ tcode.pdf - TCode PDF documentation
+ tcode.perl - TCode LaTeX2HTML extension
+ tcode.properties - User-customizable variables for build process
+ tcode.sty - TCode LaTeX package
+ tcode.tex - TCode LaTeX documentation
+ Tcoderc - TCode C-Shell initialization script
+ Tcode.bat - TCode Windows initialization script
+ Tcode.sh - TCode Bourne shell initialization script
+ Texjava.tex - LaTeX source file for the Texjava Ant task
+ texjava.pl - Texjava Perl script
+ setl2hinit.pl - LaTex2HTML Perl script
+
+3. Configuring the environment
+------------------------
+To use TCode, tcode.sty must be accessible to LaTeX and tcode.perl, to
+LaTeX2HTML. Scripts can be used to automatically configure the
+environment for TCode. The TCODEHOME environment variable must be set
+prior to using the script.
+
+Commands (for C-shell) :
+ setenv TCODEHOME <path to TCode>
+ source $TCODEHOME/Tcoderc
+
+Commands (for Bourne shell) :
+ export TCODEHOME=<path to TCode>
+ . $TCODEHOME/Tcode.sh
+
+Commands (for DOS/Windows) :
+ set TCODEHOME=<path to TCode>
+ call %TCODEHOME%\Tcode.bat
+
+Here, <path to TCode> must be replaced by the full absolute path to
+the unpacked tcode subdirectory. These commands should be added to the
+appropriate startup files for more convenience.
+
+These scripts define the texjava alias for more convenience. This
+alias simply calls texjava.pl using Perl. Under MS-DOS, the Tcode.bat
+script can be used but it does not define an alias to call texjava.pl
+becauses aliases are not supported.
+
+Read the documentation
+==================================
+The TCode full documentation is available in the tcode.pdf file. A
+PDF reader such as Adobe Acrobat Reader, kghostview or xpdf is needed.
+
+
+Building TCode
+==================================
+To rebuild the Ant tasks, a Java 2 compiler is required. To rebuild
+TCode, in the unpacked directory, type
+
+ ant lib
+
+This will recompile the Ant tasks and create tcode.jar.
+
+To recreate the document (this requires pdflatex, bibtex and the Pierre L'Écuyer's
+ bib files to be available), type
+
+ ant doc
+
+This will create tcode.pdf. If the documentation does not need or
+cannot be created, the tcode.properties file must be modified to
+comment the tcode.doc line. This will prevent Ant from trying to
+build the PDF file.
+
+To create the tcode distribution, use
+
+ ant dist
+
+This will create tcode.zip containing all the needed files.
diff --git a/Tcode.bat b/Tcode.bat
new file mode 100644
index 0000000..14eb32a
--- /dev/null
+++ b/Tcode.bat
@@ -0,0 +1,6 @@
+ at echo off
+
+set CLASSPATH=%TCODEHOME%\tcode.jar;%CLASSPATH%
+set TEXINPUTS=.:%TCODEHOME%:%TEXINPUTS%
+
+rem perl %TCODEHOME%\setl2hinit.pl %TCODEHOME%
diff --git a/Tcode.sh b/Tcode.sh
new file mode 100755
index 0000000..43700f8
--- /dev/null
+++ b/Tcode.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+if [ ! $TCODEHOME ]; then
+ echo "You must set TCODEHOME before calling this script."
+ exit
+fi
+
+alias texjava='perl $TCODEHOME/texjava.pl'
+
+if [ $CLASSPATH ]; then
+ export CLASSPATH=$TCODEHOME/tcode.jar:$CLASSPATH
+else
+ export CLASSPATH=$TCODEHOME/tcode.jar
+fi
+
+if [ $TEXINPUTS ]; then
+ export TEXINPUTS=.:${TCODEHOME}:$TEXINPUTS
+else
+ export TEXINPUTS=.:${TCODEHOME}:
+fi
+
+perl $TCODEHOME/setl2hinit.pl $TCODEHOME
diff --git a/Tcoderc b/Tcoderc
new file mode 100755
index 0000000..a39423f
--- /dev/null
+++ b/Tcoderc
@@ -0,0 +1,21 @@
+#!/bin/tcsh
+
+if ( ! $?TCODEHOME ) then
+ echo "You must set TCODEHOME before calling this script."
+ exit
+endif
+
+alias texjava 'perl $TCODEHOME/texjava.pl'
+if ( $?CLASSPATH ) then
+ setenv CLASSPATH $TCODEHOME/tcode.jar:$CLASSPATH
+else
+ setenv CLASSPATH $TCODEHOME/tcode.jar
+endif
+
+if ( $?TEXINPUTS ) then
+ setenv TEXINPUTS .:${TCODEHOME}:$TEXINPUTS
+else
+ setenv TEXINPUTS .:${TCODEHOME}:
+endif
+
+perl $TCODEHOME/setl2hinit.pl $TCODEHOME
diff --git a/Texjava.tex b/Texjava.tex
new file mode 100644
index 0000000..cf96da5
--- /dev/null
+++ b/Texjava.tex
@@ -0,0 +1,527 @@
+\defclass{Texjava}
+
+This Ant task invokes {\tt texjava.pl} to extract Java code from
+\LaTeX{} files. Given a list of files, it can invoke {\tt texjava.pl}
+once for each, creating Java file that can be processed
+with Ant. The {\tt Texjava} task checks for depencies, avoiding
+to run {\tt texjava.pl} for {\tt .tex} files with a more recent {\tt .java} file.
+It acts like a proxy to {\tt texjava.pl} so all of its options are supported by
+the task through attributes. It is possible to set default values
+for most of these attributes using system properties.
+See the documentation of {\tt texjava.pl} for more detailed information
+about the options.
+
+Note: For this class to work, the Perl interpreter must be in the PATH environment variable.
+
+\paragraph*{Supported system properties}
+The system properties allows one to set default attributes
+common to all {\tt texjava} task usage. It reduces
+the tedium of writing the {\tt texjava} calls and provides
+an easier way to modify parameters later.
+
+\noindent
+{\tt texjava.html}
+
+\noindent
+{\tt texjava.images}
+
+\noindent
+{\tt texjava.savelatex}
+
+\noindent
+{\tt texjava.htmloutdir}
+
+\noindent
+{\tt texjava.texjava}
+
+\begin{tab}
+This property specifies the path to the {\tt texjava.pl} file,
+including the name of the script. Since no assumption can
+be made about the current directory, it is recommended to
+give an absolute path or a path relative to one's project base
+directory.
+If the path is not specified, {\tt tcode/texjava.pl} will be assumed.
+This imply that one's project will have a {\tt tcode} directory
+containing {\tt texjava.pl}.
+\end{tab}
+
+\paragraph*{Available attributes.}
+Attributes are use to customize a single call to the
+{\tt texjava} task.
+They have precedence on system properties.
+
+\noindent
+{\tt html}
+
+\noindent
+{\tt images}
+
+\noindent
+{\tt savelatex}
+
+\noindent
+{\tt htmlonly}
+
+\noindent
+{\tt htmloutdir}
+
+\noindent
+{\tt master}
+
+\noindent
+{\tt texjava}
+
+\begin{tab}
+This specifies the path to the {\tt texjava.pl} script.
+\end{tab}
+
+\noindent
+{\tt overviewtopackage}
+
+\begin{tab}
+Normally, any {\tt .tex} file is mapped to a corresponding {\tt .java}
+for dependency checking and conversion. If {\tt htmlonly} is {\tt true},
+{\tt .tex} files will be mapped to {\tt .html} files. This attribute, if set
+to {\tt true}, will define a mapping from {\tt overview.tex} to
+{\tt package.html}. This allows one to generate package overviews
+without converting them every time.
+\end{tab}
+
+\paragraph*{Nested elements}
+
+Two nested elements are supported: file sets and file lists.
+These elements allows one to construct the list of {\tt .tex} files
+to be converted to {\tt .java} files.
+
+\noindent
+{\tt texfileset}
+
+\begin{tab}
+Corresponds to an Ant {\tt FileSet} element which should
+only contain {\tt .tex} files.
+A set can include files matching patterns.
+\end{tab}
+
+\noindent
+{\tt texfilelist}
+
+\begin{tab}
+Corresponds to an Ant {\tt FileList} element which should
+only contain {\tt .tex} files.
+When making a file list, one must specify the names of each
+individual files.
+\end{tab}
+
+\paragraph*{Example.}
+
+For example, the compile target of Probdist uses the task to
+create the Java files and compiles them.
+
+\begin{verbatim}
+<target name="probdist"
+ description="Compiles probability distribution package">
+ <texjava master="src/${pprobdist}/guideprobdist.tex">
+ <texfilelist dir="src/${pprobdist}"
+ files="DiscreteDistribution.tex,ContinuousDistribution.tex"/>
+ <texfileset dir="src/${pprobdist}" includes="*Dist.tex"/>
+ </texjava>
+ <javac srcdir="src" destdir="build" includes="${pprobdist}/*.java"/>
+ <texjava overviewtopackage="yes" html="yes" htmlonly="yes"
+ master=''src/${pprobdist}/guideprobdist.tex">
+ <texfilelist dir="src/${pprobdist}" files="overview.tex"/>
+ </texjava>
+</target>
+\end{verbatim}
+
+Here, the {\tt pprobdist} system property refers to the location of
+the Probdist package,
+i.e., {\tt umontreal/iro/lecuyer/probdist}. This will generate
+only the needed Java file and one is free to add classes
+ending with the {\tt Dist} suffix without modifying the build file.
+
+\bigskip\hrule\bigskip
+
+\begin{code}
+package umontreal.iro.lecuyer.tcode;\begin{hide}
+
+import org.apache.tools.ant.util.*;
+import org.apache.tools.ant.*;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.LogStreamHandler;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.FileList;
+import org.apache.tools.ant.types.FileSet;
+import java.util.Enumeration;
+import java.util.Vector;
+import java.io.IOException;
+import java.io.File;\end{hide}
+
+public class Texjava extends Task\begin{hide} {
+ // We want the task as Ant-friendly as possible, so
+ // use built-in file sets and file lists.
+ private Vector texFileSets = new Vector();
+ private Vector texFileLists = new Vector();
+ private File texjava; // Location of texjava.pl
+ private File masterFile = null;
+ private File htmloutdir = null;
+ private boolean html = false;
+ private boolean htmlset = false;
+ private boolean images = false;
+ private boolean imagesset = false;
+ private boolean savelatex = false;
+ private boolean savelatexset = false;
+
+ private boolean htmlonly = false;
+ private String htmltitle;
+ private boolean overviewtopackage = false;
+
+ private File[] texjavaList;
+
+ private Boolean getBoolProperty (String name) {
+ String val = getProject().getProperty (name);
+ if (val == null)
+ return null;
+ if (val.equalsIgnoreCase ("yes") || val.equalsIgnoreCase ("true") ||
+ val.equals ("1"))
+ return new Boolean (true);
+ else if (val.equalsIgnoreCase ("no") || val.equalsIgnoreCase ("false") ||
+ val.equals ("0"))
+ return new Boolean (false);
+ else
+ return null;
+ }\end{hide}
+
+ public boolean getHtml()\begin{hide} {
+ if (!htmlset) {
+ Boolean b = getBoolProperty ("texjava.html");
+ if (b != null) {
+ html = b.booleanValue();
+ htmlset = true;
+ }
+ }
+ return html;
+ }\end{hide}
+\end{code}
+\begin{tabb} Returns {\tt true} if the task generates HTML contents.
+\end{tabb}
+\begin{code}
+
+ public void setHtml (boolean html)\begin{hide} {
+ this.html = html;
+ htmlset = true;
+ }\end{hide}
+\end{code}
+\begin{tabb} If set to {\tt true}, HTML contents will be generated.
+\end{tabb}
+\begin{code}
+
+ public boolean getImages()\begin{hide} {
+ if (!imagesset) {
+ Boolean b = getBoolProperty ("texjava.images");
+ if (b != null) {
+ images = b.booleanValue();
+ imagesset = true;
+ }
+ }
+ return images;
+ }\end{hide}
+\end{code}
+\begin{tabb} Returns {\tt true} if the image generation is activated.
+\end{tabb}
+\begin{code}
+
+ public void setImages (boolean images)\begin{hide} {
+ this.images = images;
+ imagesset = true;
+ }\end{hide}
+\end{code}
+\begin{tabb} If set to {\tt true}, \latextohtml{} will generate
+ images when converting the documentation.
+\end{tabb}
+\begin{code}
+
+ public boolean getSavelatex()\begin{hide} {
+ if (!savelatexset) {
+ Boolean b = getBoolProperty ("texjava.savelatex");
+ if (b != null) {
+ html = b.booleanValue();
+ savelatexset = true;
+ }
+ }
+ return savelatex;
+ }\end{hide}
+\end{code}
+\begin{tabb} Returns {\tt true} if the \LaTeX{} contents
+ is saved to allow reverting to \LaTeX{} using \emph{javatex}.
+\end{tabb}
+\begin{code}
+
+ public void setSavelatex (boolean savelatex)\begin{hide} {
+ this.savelatex = savelatex;
+ savelatexset = true;
+ }\end{hide}
+\end{code}
+\begin{tabb} If set to {\tt true} the \LaTeX{} contents will
+ be saved in the produced Java file.
+\end{tabb}
+\begin{code}
+
+ public boolean getHtmlonly()\begin{hide} {
+ return htmlonly;
+ }\end{hide}
+\end{code}
+\begin{tabb} Returns {\tt true} if only HTML code is to be produced.
+\end{tabb}
+\begin{code}
+
+ public void setHtmlonly (boolean htmlonly)\begin{hide} {
+ this.htmlonly = htmlonly;
+ }\end{hide}
+\end{code}
+\begin{tabb} If set to {\tt true}, only HTML code will be produced.
+ No Java code and comments will appear.
+\end{tabb}
+\begin{code}
+
+ public boolean getOverviewtopackage()\begin{hide} {
+ return overviewtopackage;
+ }\end{hide}
+\end{code}
+\begin{tabb} Returns {\tt true} if {\tt package.html} will be
+ created from {\tt overview.tex}.
+\end{tabb}
+\begin{code}
+
+ public void setOverviewtopackage (boolean pack)\begin{hide} {
+ overviewtopackage = pack;
+ }\end{hide}
+\end{code}
+\begin{tabb} If set to {\tt true}, a file named {\tt overview.tex} will
+ be mapped to {\tt package.html} instead of {\tt overview.html}.
+\end{tabb}
+\begin{code}
+
+ public File getMaster()\begin{hide} {
+ return masterFile;
+ }\end{hide}
+\end{code}
+\begin{tabb} Gets the name of the master file.
+\end{tabb}
+\begin{code}
+
+ public void setMaster (File masterFile)\begin{hide} {
+ this.masterFile = masterFile;
+ }\end{hide}
+\end{code}
+\begin{tabb} Sets the name of the master file.
+\end{tabb}
+\begin{code}
+
+ public File getHtmloutdir()\begin{hide} {
+ if (htmloutdir == null)
+ htmloutdir = getProject().resolveFile (getProject().getProperty ("texjava.htmloutdir"));
+ return htmloutdir;
+ }\end{hide}
+\end{code}
+\begin{tabb} Gets the directory where the HTML files will be created.
+\end{tabb}
+\begin{code}
+
+ public void setHtmloutdir (File htmloutdir)\begin{hide} {
+ this.htmloutdir = htmloutdir;
+ }\end{hide}
+\end{code}
+\begin{tabb} Sets the directory where the HTML files will be created.
+\end{tabb}
+\begin{code}
+
+ public String getHtmltitle()\begin{hide} {
+ if (htmltitle == null)
+ htmltitle = "";
+ return htmltitle;
+ }\end{hide}
+\end{code}
+\begin{tabb} Gets the title of the HTML page.
+\end{tabb}
+\begin{code}
+
+ public void setHtmltitle (String title)\begin{hide} {
+ htmltitle = title;
+ }\end{hide}
+\end{code}
+\begin{tabb} Sets the title of the HTML page.
+\end{tabb}
+\begin{code}
+
+ public File getTexjava()\begin{hide} {
+ if (texjava == null) {
+ String val = getProject().getProperty ("texjava.texjava");
+ if (val != null)
+ texjava = getProject().resolveFile (val);
+ }
+ if (texjava == null)
+ texjava = new File (getProject().getBaseDir() + "/tcode", "texjava.pl");
+ return texjava;
+ }\end{hide}
+\end{code}
+\begin{tabb} Returns the path to {\tt texjava.pl}.
+\end{tabb}
+\begin{code}
+
+ public void setTexjava (File texjava)\begin{hide} {
+ this.texjava = texjava;
+ }\end{hide}
+\end{code}
+\begin{tabb} Sets the path to {\tt texjava.pl}.
+\end{tabb}
+\begin{code}
+
+ public void addTexfileset (FileSet fs)\begin{hide} {
+ texFileSets.addElement (fs);
+ }\end{hide}
+\end{code}
+\begin{tabb} Adds a set of {\tt .tex} files to be converted to {\tt .java} files.
+\end{tabb}
+\begin{code}
+
+ public void addTexfilelist (FileList fl)\begin{hide} {
+ texFileLists.addElement (fl);
+ }\end{hide}
+\end{code}
+\begin{tabb} Adds a list of {\tt .tex} files to be converted to {\tt .java} files.
+\end{tabb}
+\begin{code}
+
+ public void execute() throws BuildException\begin{hide} {
+ resetFileLists();
+
+ // Get all the files from the sets and lists and
+ // fill in texjavaList with the files that need
+ // to be processed.
+ Enumeration enumTexFileSets = texFileSets.elements();
+ while (enumTexFileSets.hasMoreElements()) {
+ FileSet fs = (FileSet)enumTexFileSets.nextElement();
+ DirectoryScanner ds = fs.getDirectoryScanner (getProject());
+ String[] files = ds.getIncludedFiles();
+ scanDir (fs.getDir (getProject()), files);
+ }
+ Enumeration enumTexFileLists = texFileLists.elements();
+ while (enumTexFileLists.hasMoreElements()) {
+ FileList fl = (FileList)enumTexFileLists.nextElement();
+ String[] files = fl.getFiles (getProject());
+ scanDir (fl.getDir (getProject()), files);
+ }
+
+ // Since texjava.pl can process one file at a time,
+ // we need to run it for every file.
+ GlobPatternMapper m = new GlobPatternMapper();
+ m.setFrom ("*.tex");
+ m.setTo (getHtmlonly() ? "*.html" : "*.java");
+ if (texjavaList.length > 0 && !overviewtopackage)
+ log ((htmlonly ? "Creating HTML contents from " :
+ "Extracting Java code from ") + texjavaList.length +
+ " TeX file" + (texjavaList.length == 1 ? "" : "s"));
+ for (int i = 0; i < texjavaList.length; i++) {
+ if (texjavaList[i] == null)
+ continue;
+ try {
+ log ("Processing " + texjavaList[i].getAbsolutePath());
+ Commandline cmd = new Commandline();
+ // This could be replaced by an absolute
+ // path to Perl interpreter which would have to
+ // be determined or specified at runtime.
+ cmd.setExecutable ("perl");
+ // The first argument must be the name of the script
+ cmd.createArgument().setFile (getTexjava());
+ if (masterFile != null) {
+ cmd.createArgument().setValue ("-master");
+ cmd.createArgument().setFile (masterFile);
+ }
+ cmd.createArgument().setValue (getHtml() ? "-html" : "-nohtml");
+ cmd.createArgument().setValue (getImages() ? "-images" : "-noimages");
+ cmd.createArgument().setValue (getSavelatex() ? "-savelatex" : "-nosavelatex");
+ if (getHtmloutdir() != null) {
+ cmd.createArgument().setValue ("-htmloutdir");
+ cmd.createArgument().setFile (htmloutdir);
+ }
+ if (getHtmlonly()) {
+ cmd.createArgument().setValue ("-htmlonly");
+ if (!getHtmltitle().equals ("")) {
+ cmd.createArgument().setValue ("-htmltitle");
+ cmd.createArgument().setValue (htmltitle);
+ }
+ }
+ // Pass the TeX file
+ cmd.createArgument().setFile (texjavaList[i]);
+ // The .tex file must be converted to .java file
+ String javaName = getOverviewtopackage()
+ && texjavaList[i].getName().equals ("overview.tex")
+ ? "package.html" :
+ m.mapFileName (texjavaList[i].getName())[0];
+ cmd.createArgument().setFile (new File (texjavaList[i].getParentFile(), javaName));
+
+ // We prefer to use Execute rather than JDK Runtime
+ // because Execute is designed to face
+ // portability issues and can redirect outputs
+ // into Ant.
+ Execute exe = new Execute
+ (new LogStreamHandler
+ (this, Project.MSG_VERBOSE, Project.MSG_WARN));
+ exe.setAntRun (getProject());
+ exe.setWorkingDirectory (getProject().getBaseDir());
+ exe.setCommandline (cmd.getCommandline());
+ exe.execute();
+ if (exe.getExitValue() != 0)
+ throw new BuildException
+ ("Error running texjava", getLocation());
+ }
+ catch (IOException e) {
+ throw new BuildException
+ ("Error running texjava", e, getLocation());
+ }
+ }
+ }\end{hide}
+\end{code}
+\begin{tabb} Executes the conversion task, using
+the Ant {\tt exec} task to invoke {\tt texjava.pl} on each {\tt .tex} file.
+\end{tabb}
+\begin{code}\begin{hide}
+
+ private void resetFileLists() {
+ texjavaList = new File[0];
+ }
+
+ /*
+ * Given a source directory and a list of .tex files,
+ * scans the corresponding .java files in srcDir
+ * to locate any outdated .java file that need to be
+ * regenerated from its .tex file.
+ */
+ private void scanDir (File srcDir, String[] files) {
+ GlobPatternMapper m = new GlobPatternMapper();
+ m.setFrom ("*.tex");
+ m.setTo (htmlonly ? "*.html" : "*.java");
+ SourceFileScanner sfs = new SourceFileScanner (this);
+ File[] newFiles = sfs.restrictAsFiles (files, srcDir, srcDir, m);
+ if (overviewtopackage) {
+ for (int i = 0; i < newFiles.length; i++) {
+ if (newFiles[i].getName().equals ("overview.tex")) {
+ long lastModifTex = newFiles[i].lastModified();
+ File packagehtml = new File (newFiles[i].getParent(),
+ "package.html");
+ long lastModifHtml = packagehtml.lastModified();
+ if (lastModifHtml >= lastModifTex)
+ newFiles[i] = null;
+ }
+ }
+ }
+
+ if (newFiles.length > 0) {
+ File[] newTexjavaList = new File[texjavaList.length + newFiles.length];
+ System.arraycopy (texjavaList, 0, newTexjavaList, 0, texjavaList.length);
+ System.arraycopy (newFiles, 0, newTexjavaList, texjavaList.length, newFiles.length);
+ texjavaList = newTexjavaList;
+ }
+ }
+}\end{hide}
+\end{code}
diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..61ffa1f
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,108 @@
+<project name="tcode" default="lib">
+<description>
+ Tools for documenting Java programs in LaTeX
+</description>
+
+<property file="tcode.properties"/>
+<property name="tcode.version" value="1.0 Beta"/>
+
+<target name="build" description="Builds the Ant tasks for TCode">
+ <mkdir dir="build"/>
+ <tstamp/>
+ <!-- Cannot use Texjava task because it is not constructed yet -->
+ <echo message="Building the Texjava task"/>
+ <exec executable="perl" failonerror="yes">
+ <arg file="${texjava.texjava}"/>
+ <arg value="-master"/>
+ <arg file="tcode.tex"/>
+ <arg value="-nohtml"/>
+ <arg file="Texjava.tex"/>
+ <arg file="Texjava.java"/>
+ </exec>
+ <!-- Normally, we should put Texjava.java in umontreal/iro/lecuyer/tcode
+ subdirectory for proper dependency checking.
+ Since there is only a few task, we can afford recompiling
+ them every time and unclutter the tree. -->
+ <javac srcdir="." destdir="build" includes="Texjava.java"/>
+ <echo message="Building the PdfLatex task"/>
+ <exec executable="perl" failonerror="yes">
+ <arg file="${texjava.texjava}"/>
+ <arg value="-master"/>
+ <arg file="tcode.tex"/>
+ <arg value="-nohtml"/>
+ <arg file="PdfLatex.tex"/>
+ <arg file="PdfLatex.java"/>
+ </exec>
+ <javac srcdir="." destdir="build" includes="PdfLatex.java"/>
+</target>
+
+<target name="lib" depends="build" description="Builds the tcode Ant tasks .jar file">
+ <manifest file="manifest">
+ <section name="umontreal.iro.lecuyer.tcode">
+ <attribute name="Specification-Title" value="Tools for documenting Java programs in Latex"/>
+ <attribute name="Specification-Version" value="${tcode.version}"/>
+ <attribute name="Specification-Vendor" value="DIRO of Université de Montréal"/>
+ <attribute name="Implementation-Title" value="TCode"/>
+ <attribute name="Implementation-Version" value="${tcode.version} ${TODAY}"/>
+ <attribute name="Implementation-Vendor" value="DIRO of Université de Montréal"/>
+ </section>
+ </manifest>
+ <jar jarfile="tcode.jar" basedir="build" manifest="manifest"/>
+ <delete file="manifest"/>
+</target>
+
+<target name="doc" if="tcode.doc"
+ description="Creates the PDF documentation for TCode. This target requires LaTeX and the Pierre L'Ecuyer's .sty files to be installed.">
+ <delete>
+ <fileset dir="." includes="*.aux"/>
+ </delete>
+ <exec executable="pdflatex">
+ <arg value="-interaction"/>
+ <arg value="nonstopmode"/>
+ <arg file="tcode.tex"/>
+ </exec>
+<!--
+ <exec executable="bibtex">
+ <arg value="tcode"/>
+ </exec>
+ <exec executable="pdflatex">
+ <arg value="-interaction"/>
+ <arg value="nonstopmode"/>
+ <arg file="tcode.tex"/>
+ </exec>
+-->
+ <exec executable="pdflatex">
+ <arg value="-interaction"/>
+ <arg value="nonstopmode"/>
+ <arg file="tcode.tex"/>
+ </exec>
+</target>
+
+<target name="dist" depends="build,doc" description="Creates the TCode distribution">
+ <zip destfile="tcode-${DSTAMP}.zip">
+ <zipfileset dir="." prefix="tcode" includes="*.tex,*.pdf,*.sty,tcode.bbl"/>
+ <zipfileset dir="." prefix="tcode" includes="setl2hinit.pl,texjava.pl,javatex.pl,*.perl"/>
+ <zipfileset dir="." prefix="tcode" includes="tcode.jar"/>
+ <zipfileset dir="." prefix="tcode" includes="Tcoderc" filemode="755"/>
+ <zipfileset dir="." prefix="tcode" includes="Tcode.sh" filemode="755"/>
+ <zipfileset dir="." prefix="tcode" includes="Tcode.bat"/>
+ <zipfileset dir="." prefix="tcode" includes="tcode.properties,build.xml,README"/>
+ </zip>
+</target>
+
+<target name="cleanbuild" description="Cleans the build directory">
+ <delete dir="build"/>
+</target>
+
+<target name="cleanlib" description="Cleans the library tcode.jar">
+ <delete file="tcode.jar"/>
+</target>
+
+<target name="cleandoc" description="Cleans the documentation">
+ <delete>
+ <fileset dir="." includes="*.aux"/>
+ <fileset dir="." includes="*.toc,*.blg,*.dvi,*.log,*.out"/>
+ </delete>
+</target>
+
+</project>
diff --git a/lmac.sty b/lmac.sty
new file mode 100644
index 0000000..1b12ba6
--- /dev/null
+++ b/lmac.sty
@@ -0,0 +1,193 @@
+% Macros pour usage avec LATEX. (Pierre L'Ecuyer).
+
+\def\?{\discretionary{}{}{}} % Same as \- but does not print the - sign
+ % (useful to hyphenate in math mode).
+\def\From {From }
+\def\mod{{\rm\ mod\ }} % Modulo.
+\def\MOD{{\rm\ MOD\ }}
+\def\div{{\rm\ div\ }} % Division entiere.
+\def\DIV{{\rm\ DIV\ }}
+\def\var{{\rm var }} % Variance.
+\def\Var{{\rm Var }}
+\def\Cov{{\rm Cov }}
+\def\MSE{{\rm MSE }}
+\def\arg{{\rm\ arg}} % Argument.
+\def\Re{{\rm I\kern-0.2em R}} % Ensemble des nombres reels.
+% \def\Re{{\mathbb{R}} % Ensemble des nombres reels.
+\def\R{\Re}
+\def\d{{\rm d}} % Pour les derivees (parfois).
+\def\B{{\rm I\kern-0.2em B}}
+\def\F{{\rm I\kern-0.2em F}}
+\def\FF{{\rm I\kern-0.1em F}}
+\def\N{{\rm I\kern-0.2em N}} % Ensemble des nombres naturels.
+\def\Z{{\sf Z\kern-0.4em Z}} % Ensemble des nombres entiers.
+% \def\B{{\mathbb{B}}
+% \def\F{{\mathbb{F}}
+% \def\FF{\mathbb{F}}
+% \def\N{{\mathbb{N}} % Ensemble des nombres naturels.
+% \def\Z{\mathbb{Z} % Ensemble des nombres entiers.
+\def\Fbar{\overline F} % F avec une barre au dessus.
+\def\square{\vrule height6pt width5pt depth1pt}
+ % Petit rectangle noir pour terminer une preuve de theoreme, etc.
+\def\eqdef {\buildrel \rm def \over =} % Egal par definition.
+\def\eqas {\buildrel \rm a.s. \over =} % Egal a.s.
+\def\eqps {\buildrel \rm p.s. \over =} % Egal p.s.
+\def\toas {\buildrel \rm a.s. \over \to} % ---> a.s.
+\def\tops {\buildrel \rm p.s. \over \to} % ---> p.s.
+\def\_{{\tt\char'137}} % Signe _ ("souligne").
+\def\bs{{\tt\char'134}} % Signe \
+\def\tttilde{{\tt\char'176}} % Signe ~
+\def\<{$\langle$} % Signe <
+\def\>{$\rangle$} % Signe >
+\def\q{$\kern1.4em$} % Space for indentation in slides and programs.
+
+\def\version {\begin{flushright} \it Draft Version: \today \end{flushright}}
+\def\workingpaper {\begin{flushright} \it WORKING PAPER. \end{flushright}}
+\def\submitted#1 {\begin{flushright} \it SUBMITTED TO: #1.\end{flushright}}
+
+\def\adrmaison {\begin {verse}
+ Pierre L'Ecuyer\\
+ 45 Hampton Gardens\\ Pointe Claire (Qu\'e.) \\ H9S 5B8\\ CANADA \\
+ T\'el.: (514) 426-4029 \end {verse}}
+\def\adrum {\begin {verse}
+ Professeur Pierre L'Ecuyer\\
+ D\'epartement d'I.R.O., Universit\'e de Montr\'eal\\
+ C.P.\ 6128, Succ.\ Centre-Ville, Montr\'eal, H3C 3J7\\ CANADA \\
+ T\'el. : (514) 343-2143 \hspace{1in}
+ FAX : (514) 343-5834\\
+ e-mail : {\tt lecuyer at IRO.UMontreal.ca}\\
+ url : {\tt www.iro.umontreal.ca/$\sim$lecuyer} \end {verse}}
+%
+\def\adrsalzburg {\begin {verse}
+ Professor Pierre L'Ecuyer\\
+ Institut f\"ur Mathematik\\ Universit\"at Salzburg\\
+ Hellbrunnerstrasse 34, A-5020 Salzburg, AUSTRIA \end {verse}}
+\def\adrncsu {\begin {verse}
+ Professor Pierre L'Ecuyer\\
+ Department of Industrial Engineering\\
+ North Carolina State University\\ Box 7906\\
+ Raleigh, North Carolina 27695-7906, U.S.A. \\
+ e-mail : {\tt lecuyer at IRO.UMontreal.ca}\\
+ url : {\tt www.iro.umontreal.ca/$\sim$lecuyer} \end {verse}}
+%
+\def\adrum0 {\begin {verse}
+ Professeur Pierre L'Ecuyer\\
+ D\'epartement d'I.R.O.\\ Universit\'e de Montr\'eal\\
+ C.P.\ 6128, Succ.\ Centre-Ville\\ Montr\'eal, H3C 3J7\\ CANADA
+ \end {verse}}
+
+% Redefinition du macro pour les ``footnotes''.
+\catcode`\@=11
+\def\ninepoint{\def\rm{\fam0\ninerm}
+ \textfont0=\ninerm\normalbaselineskip=11pt
+ \setbox\strutbox=\hbox{\vrule height8pt depth 3pt width0pt}%
+ \normalbaselines\rm}
+\def\vfootnote#1{\insert\footins\bgroup\ninepoint
+ \interlinepenalty 100
+ \leftskip=0pt \rightskip=0pt \spaceskip=0pt \xspaceskip=0pt
+ \splittopskip=\ht\strutbox \floatingpenalty = 20000
+ \splitmaxdepth=\dp\strutbox
+ \item{#1}\footstrut\futurelet\next\fo at t}
+
+% Macros pour inserer des bouts de code (programmes).
+% Faire \code ... \endcode
+{\obeyspaces\gdef {\ }}
+\def\setverbatim{\def\par{\leavevmode\endgraf}
+ \parskip=0pt\parindent=0pt\obeylines\obeyspaces }
+\chardef\other=12
+\def\ttverbatim{\setverbatim\tt \catcode`\~=\other
+ \catcode`\{=\other \catcode`\}=\other \catcode`\_=\other
+ \catcode`\^=\other \catcode`\$=\other \catcode`\%=\other
+ \catcode`\#=\other \catcode`\&=\other \baselineskip=11pt
+ }
+ % Reproduit tel quel ce qui est ecrit, en caracteres \tt.
+ % On doit faire \begingroup\ttverbatim .... \endgroup
+\def\smallttverbatim{\ttverbatim\small\tt}
+\def\code {\vfil\vfilneg\vbox\bgroup\ttverbatim}
+\def\longcode {\vfil\vfilneg\bgroup\ttverbatim}
+\def\smallc {\small\tt\baselineskip=9.5pt}
+\def\footc {\footnotesize\tt\baselineskip=9.0pt}
+\def\smallcode {\code\smallc}
+\let\endcode=\egroup
+\let\vcode=\code
+\let\endvcode=\egroup
+
+% Definition d'un module ou d'une classe.
+\def\ps at nomark {\def\leftmark{} \def\rightmark{}}
+\def\defmodule#1 {\addcontentsline{toc}{subsection}{#1} \markboth{#1}{#1}
+ \centerline {\LARGE\bf #1}\bigskip \thispagestyle{nomark}}
+\def\defclass#1 {\addcontentsline{toc}{subsection}{#1} \markboth{#1}{#1}
+ \centerline {\LARGE\bf #1}\bigskip \thispagestyle{nomark}}
+% Lorsqu'on veut cacher certaines choses a l'usager, faire \hide ... \endhide
+\newif\iffull\fullfalse
+\def\hide{\iffull}
+\let\endhide=\fi
+
+\def\parup{\nobreak\vskip -2pt\nobreak}
+
+\def\tab{\small\dimen9=\parindent\parindent=0pt%
+ \advance\leftskip by 1.5em\parup}
+\def\tabb{\small\dimen9=\parindent\parindent=0pt%
+ \advance\leftskip by 3.0em\parup}
+\def\tabbb{\small\dimen9=\parindent\parindent=0pt%
+ \advance\leftskip by 4.5em\parup}
+\def\endtab{\vskip 0.01pt\advance\leftskip by -1.5em\normalsize%
+ \parindent=\dimen9}
+\def\endtabb{\vskip 0.01pt\advance\leftskip by -3.0em\normalsize%
+ \parindent=\dimen9}
+\def\endtabbb{\vskip 0.01pt\advance\leftskip by -4.5em\normalsize%
+ \parindent=\dimen9}
+
+% Pour mettre quelque chose dans une boite double.
+\def\boxit#1{\vbox{\hrule height1pt
+ \hbox{\vrule width1pt\kern3pt
+ \vbox{\kern3pt#1\kern3pt
+ }\kern3pt\vrule width1pt
+ }\hrule height1pt }}
+\def\boxr#1{\hfil\vbox{\hrule height1pt
+ \hbox{\vrule width1pt\kern3pt
+ \vbox{#1}\hfil
+ \kern3pt\vrule width1pt
+ }\hrule height1pt }}
+
+% Synonymes plus courts pour \begin{equation}, \begin{eqnarray}, etc.
+\def\eq{\equation} \def\endeq{\endequation}
+\def\eqs{\eqnarray} \def\endeqs{\endeqnarray}
+\def\eqsn{\begin {eqnarray*}} \def\endeqsn{\end{eqnarray*}}
+
+% Proof avec boite alignee a droite a la fin.
+\newenvironment{myproof}{{\em Proof.}}{\hspace*{\fill}$\Box$}
+% \newenvironment{proof}{{\em Proof.}}{\hspace*{\fill}$\Box$}
+
+% Macros (avec switch) pour faire apparaitre les noms des labels dans les eqs.
+% Utiliser \eqlabel au lieu de \label. Doit laisser un espace apres le }
+% Pour que les etiquettes apparaissent, faire \seeeqlabelstrue au debut.
+\newif\ifseeeqlabels\seeeqlabelsfalse
+\newbox\eqlab \setbox\eqlab=\hbox {}
+\def\eqlabel#1 {\global\setbox\eqlab=\hbox
+ {\ifseeeqlabels {\rm (#1)} \else {} \fi } \label{#1} }
+\def\@eqnnum {{\rm \box\eqlab \setbox\eqlab=\hbox {} (\theequation)}}
+
+% Comme ci-haut pour \eqlabel, mais pour les noms des autres labels
+% (Theoremes, Propositions, etc.).
+% Utiliser \vislabel au lieu de \label.
+% Pour que les etiquettes apparaissent, faire \seevislabelstrue au debut.
+\newif\ifseevislabels\seevislabelsfalse
+\def\vislabel#1 {\ifseevislabels {\ \em (#1).\ } \else {} \fi \label{#1} }
+
+% Pour mettre des remarques temporaires.
+\newif\ifREM\REMfalse
+\def\REM#1 {\ifREM \begin{quote} \small\em #1 \end{quote} \else {\null} \fi }
+
+% Pour avoir "running head" et no. de page en haut de page, faire \mytwoheads
+% Si on veut la date en haut de chaque page, on fait aussi \dateheadtrue
+\newif\ifdatehead\dateheadfalse
+\def\mytwoheads {\pagestyle{headings}
+ \topmargin=-0.4in\headheight=0.2in\headsep=0.4in
+ \oddsidemargin=0.2in\evensidemargin=0in
+ \def\@evenhead {{\large\bf\thepage}\quad\leftmark\hfil
+ \ifdatehead\small\it\today\fi}% Left heading
+ \def\@oddhead {\ifdatehead{\small\it\kern-1em\today}\fi\hfil
+ \rightmark\quad\large\bf\thepage}}% Right heading
+
+\catcode`\@=12
diff --git a/setl2hinit.pl b/setl2hinit.pl
new file mode 100644
index 0000000..30eb7e5
--- /dev/null
+++ b/setl2hinit.pl
@@ -0,0 +1,71 @@
+#!/bin/perl
+
+# This script manage the ~/.latex2html-init LATEX2HTMLSTYLES variable.
+# Its first argument must be a path that will be looked for in the LATEX2HTMLSTYLES
+# variable. If the path is absent, it will be added.
+
+use File::Spec;
+
+if ($^O eq 'MSWin32' || $^O =~ /dos|win/) {
+ $pathsep = ';';
+}
+else {
+ $pathsep = ':';
+}
+
+
+if (@ARGV != 1) {
+ print "Usage: perl setl2hinit.pl <directory to be added to LATEX2HTMLSTYLES variable>\n";
+ exit 1;
+}
+$ARGV[0] = File::Spec->canonpath ($ARGV[0]);
+
+die "$ARGV[0] directory does not exist" if !-x $ARGV[0];
+die "HOME environment variable not set" if !$ENV{'HOME'};
+
+$l2hinit = File::Spec->catfile ($ENV{'HOME'}, '.latex2html-init');
+
+if (!-r $l2hinit) {
+ # Create the file if it does not exist yet.
+ open L2H, ">$l2hinit" or die "Cannot create $l2hinit";
+ print L2H '$LATEX2HTMLSTYLES .= "' . quotepath ($pathsep . $ARGV[0]) . "\";\n";
+ printf L2H "\n1;\n";
+ close L2H;
+ exit 0;
+}
+
+# Read the file (and the LATEX2HTMLSTYLES variable)
+require ($l2hinit);
+
+ at p = split /$pathsep/, $LATEX2HTMLSTYLES;
+foreach my $dir (@p) {
+ $dir = File::Spec->canonpath ($dir);
+ if ($dir eq $ARGV[0]) {
+ # The path was found; nothing to be done
+ exit 0;
+ }
+}
+
+# Since the directory was not found, it must be added.
+# However, the rest of the file must not be altered.
+# The safest way to do it is to add a new line to the init file.
+
+open L2H, "<$l2hinit" or die "Cannot read $l2hinit";
+$contents = join "", <L2H>;
+close L2H;
+
+$contents =~ s/\s*1;\s*$//;
+$contents .= "\n\$LATEX2HTMLSTYLES .= \"" . quotepath ($pathsep . $ARGV[0])
+ . "\";\n\n1;\n";
+
+open L2H, ">$l2hinit" or die "Cannot write to $l2hinit";
+print L2H $contents;
+close L2H;
+
+sub quotepath {
+ # Quotes the backslashes in paths
+ my $p = shift;
+
+ $p =~ s/\\/\\\\/go;
+ return $p;
+}
diff --git a/tcode.bbl b/tcode.bbl
new file mode 100644
index 0000000..ce7b70f
--- /dev/null
+++ b/tcode.bbl
@@ -0,0 +1,24 @@
+\begin{thebibliography}{1}
+
+\bibitem{iACT03a}
+ActiveState.
+\newblock {\em {ASPN}: Reference---ActivePerl Docs}, 2003.
+\newblock Available online at
+ \url{http://aspn.activestate.com/ASPN/Reference/Products/ASPNTOC-ACTIVEPERL}.
+
+\bibitem{iFLA99a}
+D.~Flanagan.
+\newblock {\em {J}ava in a Nutshell}.
+\newblock O'Reilly, Sebastopol, CA, third edition, 1999.
+
+\bibitem{iGOO99a}
+M.~Goossens and S.~Rahtz.
+\newblock {\em The \LaTeX{} Web Companion}.
+\newblock Addison-Wesley, 1999.
+
+\bibitem{iKNU94a}
+D.~E. Knuth and S.~Levy.
+\newblock {\em The {CWEB} System of Structured Documentation}.
+\newblock Addison-Wesley, Reading, MA, 1994.
+
+\end{thebibliography}
diff --git a/tcode.jar b/tcode.jar
new file mode 100644
index 0000000..5d9d1c4
Binary files /dev/null and b/tcode.jar differ
diff --git a/tcode.pdf b/tcode.pdf
new file mode 100644
index 0000000..2764173
Binary files /dev/null and b/tcode.pdf differ
diff --git a/tcode.perl b/tcode.perl
new file mode 100644
index 0000000..aaf2d57
--- /dev/null
+++ b/tcode.perl
@@ -0,0 +1,339 @@
+# comes from alltt
+if ($alltt_rx) {
+ $alltt_rx = 'vcode'."|$alltt_rx";
+ $alltt_rx =~ s/\|{2,}/\|/g; $alltt_rx =~ s/\|$//g;
+} else {
+ $alltt_rx = 'vcode';
+}
+
+# everything here is inspired from other .perl files
+# in the styles subdirectory of latex2html.
+# There is no official documentation on how to implement
+# new commands, except the ones that need to be ignored
+# or passed to LaTeX to generate images.
+
+&do_require_package ('alltt');
+
+sub do_math_cmd_R {
+ ('', '\\Re');
+}
+
+sub do_cmd_class {
+ local($_) = @_;
+ my $arg;
+
+ $arg = &missing_braces unless (
+ (s/$next_pair_pr_rx/$arg = $2;''/eo)
+ ||(s/$next_pair_rx/$arg = $2;''/eo));
+
+ join ('', "{\@link $arg}", $_);
+}
+
+sub do_cmd_externalclass {
+ local($_) = @_;
+ my ($package, $class);
+
+ $package = &missing_braces unless (
+ (s/$next_pair_pr_rx/$package = $2;''/eo)
+ ||(s/$next_pair_rx/$package = $2;''/eo));
+
+ $class = &missing_braces unless (
+ (s/$next_pair_pr_rx/$class = $2;''/eo)
+ ||(s/$next_pair_rx/$class = $2;''/eo));
+
+ join ('', "{\@link $package.$class $class}", $_);
+}
+
+sub do_cmd_method {
+ local($_) = @_;
+ my ($method,$signature);
+
+ $method = &missing_braces unless (
+ (s/$next_pair_pr_rx/$method = $2;''/eo)
+ ||(s/$next_pair_rx/$method = $2;''/eo));
+
+ $signature = &missing_braces unless (
+ (s/$next_pair_pr_rx/$signature = $2;''/eo)
+ ||(s/$next_pair_rx/$signature = $2;''/eo));
+
+ $signature = "($signature)" if (length ($signature) > 0);
+ join ('', "{\@link #$method$signature $method}", $_);
+}
+
+sub do_cmd_externalmethod {
+ local($_) = @_;
+ my ($package, $class, $method, $signature);
+
+ $package = &missing_braces unless (
+ (s/$next_pair_pr_rx/$package = $2;''/eo)
+ ||(s/$next_pair_rx/$package = $2;''/eo));
+
+ $class = &missing_braces unless (
+ (s/$next_pair_pr_rx/$class = $2;''/eo)
+ ||(s/$next_pair_rx/$class = $2;''/eo));
+
+ $method = &missing_braces unless (
+ (s/$next_pair_pr_rx/$method = $2;''/eo)
+ ||(s/$next_pair_rx/$method = $2;''/eo));
+
+ $signature = &missing_braces unless (
+ (s/$next_pair_pr_rx/$signature = $2;''/eo)
+ ||(s/$next_pair_rx/$signature = $2;''/eo));
+
+ $package .= '.' if (length($package) > 0);
+ $signature = "($signature)" if (length ($signature) > 0);
+ join ('', "{\@link $package$class#$method$signature $method}", $_);
+}
+
+sub do_cmd_clsexternalmethod {
+ local($_) = @_;
+ my ($package, $class, $method, $signature);
+
+ $package = &missing_braces unless (
+ (s/$next_pair_pr_rx/$package = $2;''/eo)
+ ||(s/$next_pair_rx/$package = $2;''/eo));
+
+ $class = &missing_braces unless (
+ (s/$next_pair_pr_rx/$class = $2;''/eo)
+ ||(s/$next_pair_rx/$class = $2;''/eo));
+
+ $method = &missing_braces unless (
+ (s/$next_pair_pr_rx/$method = $2;''/eo)
+ ||(s/$next_pair_rx/$method = $2;''/eo));
+
+ $signature = &missing_braces unless (
+ (s/$next_pair_pr_rx/$signature = $2;''/eo)
+ ||(s/$next_pair_rx/$signature = $2;''/eo));
+
+ $package .= '.' if (length($package) > 0);
+ $signature = "($signature)" if (length ($signature) > 0);
+ join ('', "{\@link $package$class#$method$signature $class.$method}", $_);
+}
+
+sub do_cmd_param {
+ local($_) = @_;
+ my ($arg, $desc);
+
+ $arg = &missing_braces unless (
+ (s/$next_pair_pr_rx/$arg = $2;''/eo)
+ ||(s/$next_pair_rx/$arg = $2;''/eo));
+
+ $desc = &missing_braces unless (
+ (s/$next_pair_pr_rx/$desc = $2;''/eo)
+ ||(s/$next_pair_rx/$desc = $2;''/eo));
+
+ join ('', "\@param $arg $desc\n", $_);
+}
+
+sub do_cmd_blocktag {
+ local($_) = @_;
+ my ($arg, $desc);
+
+ $tagname = &missing_braces unless (
+ (s/$next_pair_pr_rx/$arg = $2;''/eo)
+ ||(s/$next_pair_rx/$arg = $2;''/eo));
+
+ $desc = &missing_braces unless (
+ (s/$next_pair_pr_rx/$desc = $2;''/eo)
+ ||(s/$next_pair_rx/$desc = $2;''/eo));
+
+ join ('', "$tagname $desc\n", $_);
+}
+
+sub do_cmd_return {
+ local($_) = @_;
+ my $text;
+ $text = &missing_braces unless (
+ (s/$next_pair_pr_rx/$text = $2;''/eo)
+ ||(s/$next_pair_rx/$text = $2;''/eo));
+
+ join ('', "\@return $text", $_);
+}
+
+sub do_cmd_exception {
+ local($_) = @_;
+ my ($arg, $desc);
+
+ $arg = &missing_braces unless (
+ (s/$next_pair_pr_rx/$arg = $2;''/eo)
+ ||(s/$next_pair_rx/$arg = $2;''/eo));
+
+ $desc = &missing_braces unless (
+ (s/$next_pair_pr_rx/$desc = $2;''/eo)
+ ||(s/$next_pair_rx/$desc = $2;''/eo));
+
+ join ('', "\@exception $arg $desc\n", $_);
+}
+
+# Some problems arise with math commands
+# Some symbols must not be
+# displayed as a Unicode char
+# because they cause display problems
+# with some browsers.
+%custom_math_tr = (
+ 'lfloor', 'floor(',
+ 'rfloor', ')',
+ 'lceil', 'ceil(',
+ 'rceil', ')',
+ 'approx', ' =~ ',
+ 'var', 'var',
+ 'Var', 'Var',
+ 'le', ' <= ',
+ 'leq', ' <= ',
+ 'ge', ' >= ',
+ 'geq', ' >= ',
+ 'to', ' -> ',
+ 'htmax', 'max',
+ 'htmin', 'min',
+ 'htinf', 'inf',
+ 'htsup', 'sup',
+ 'htint', '∫',
+ 'htsum', '∑',
+ 'htprod', '∏',
+ 'htlim', 'lim'
+);
+
+foreach my $mathcmd (keys %custom_math_tr) {
+ eval ("sub do_math_cmd_$mathcmd {\n ('$custom_math_tr{$mathcmd}', \@_);\n}");
+}
+
+sub do_math_cmd_bar {
+ $arg = &missing_braces unless (
+ (s/$next_pair_pr_rx/$arg = $2;''/eo)
+ ||(s/$next_pair_rx/$arg = $2;''/eo));
+
+ ("bar($arg)", @_);
+}
+
+sub do_math_cmd_overline {
+ $arg = &missing_braces unless (
+ (s/$next_pair_pr_rx/$arg = $2;''/eo)
+ ||(s/$next_pair_rx/$arg = $2;''/eo));
+
+ ("bar($arg)", @_);
+}
+
+sub do_math_cmd_hat {
+ $arg = &missing_braces unless (
+ (s/$next_pair_pr_rx/$arg = $2;''/eo)
+ ||(s/$next_pair_rx/$arg = $2;''/eo));
+
+ ("hat($arg)", @_);
+}
+
+# Inspired from math.pl
+sub do_math_cmd_sqrt {
+ local($_) = @_;
+ local($n) = &get_next_optional_argument;
+ local($surd) = &get_next_token();
+ $n ? ("($surd)<SUP>1/$n</SUP>", $_) : ("($surd)<SUP>1/2</SUP>", $_);
+}
+
+sub do_env_hide {
+ "";
+}
+
+sub do_env_detailed {
+ "";
+}
+
+sub do_env_vcode {
+ # Comes from alltt.perl
+
+ local ($_) = @_;
+ local($closures,$reopens,$alltt_start,$alltt_end, at open_block_tags);
+
+ if ($HTML_VERSION > 3.0) {
+ if ($USING_STYLES) {
+ $env_id .= ' CLASS="vcode"' unless ($env_id =~/CLASS=/);
+ $env_style{'vcode'} = " " unless ($env_style{'vcode'});
+ }
+ $alltt_start = "\n<DIV$env_id ALIGN=\"LEFT\">\n";
+ $alltt_end = "\n</DIV>\n";
+ $env_id = '';
+ } else {
+ $alltt_start = "<P ALIGN=\"LEFT\">";
+ $alltt_end = "</P>";
+ }
+
+
+ # get the tag-strings for all open tags
+ local(@keep_open_tags) = @$open_tags_R;
+ ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
+
+ # get the tags for text-level tags only
+ $open_tags_R = [ @keep_open_tags ];
+ local($local_closures, $local_reopens);
+ ($local_closures, $local_reopens, at open_block_tags) = &preserve_open_block_tags
+ if (@$open_tags_R);
+
+ $open_tags_R = [ @open_block_tags ];
+
+ do {
+ local($open_tags_R) = [ @open_block_tags ];
+ local(@save_open_tags) = ();
+
+ # preserve the possibility for hiding
+ s/\\(begin|end)$O(\d+)${C}hide$O\2$C/<$1_hide>/go;
+
+ # This will prevent braces from being interpreted as
+ # arguments, allowing us to display them.
+ # This thing comes from latex2html main script, sub
+ # revert_to_raw_tex.
+ while (s/$O\s*\d+\s*$C/\{/o) { s/$&/\}/;}
+ while (s/$O\s*\d+\s*$C/\{/o) { s/$&/\}/;} #repeat this.
+ # The same for processed markers ...
+ while ( s/$OP\s*\d+\s*$CP/\{/o ) { s/$&/\}/; }
+ while ( s/$OP\s*\d+\s*$CP/\{/o ) { s/$&/\}/;} #repeat this.
+
+ # Environments have to be ignored here.
+ s/\\(begin|end)//g;
+ # Some commands have {} has argument, remove that.
+ s/(\\(?:[a-zA-Z]+|[^a-zA-Z])\s*)\{\}/$1/g;
+
+ local($cnt) = ++$global{'max_id'};
+
+ # put back the hide environments.
+ s/<(begin|end)_hide>/\\$1$O$cnt${C}hide$O$cnt$C/g;
+ $cnt = ++$global{'max_id'};
+
+ # This comes from alltt
+ $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
+ , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
+
+
+ $_ = &translate_environments($_);
+ $_ = &translate_commands($_) if (/\\/);
+
+ # preserve space-runs, using
+ while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
+ s/(<BR>) /$1;SPMnbsp;/g;
+
+#RRM: using <PRE> tags doesn't allow images, etc.
+# $_ = &revert_to_raw_tex($_);
+# &mark_string; # ???
+# s/\\([{}])/$1/g; # ???
+# s/<\/?\w+>//g; # no nested tags allowed
+# join('', $closures,"<PRE$env_id>$_</PRE>", $reopens);
+# s/<P>//g;
+# join('', $closures,"<PRE$env_id>", $_, &balance_tags(), '</PRE>', $reopens);
+
+ $_ = join('', $closures, $alltt_start , $local_reopens
+ , $_
+ , &balance_tags() #, $local_closures
+ , $alltt_end, $reopens);
+ undef $open_tags_R; undef @save_open_tags;
+ };
+
+ $open_tags_R = [ @keep_open_tags ];
+ $_;
+}
+
+&ignore_commands ("tab\ntabb\ntabbb\nendtab\nendtabb\nendtabbb\nhrule\n"
+ . "cite # [] # {}\n"
+ . "eqlabel # {}\n"
+ . "ref # {}\n"
+ . "defclass # {}\n"
+ . "defmodule # {}");
+
+1;
diff --git a/tcode.properties b/tcode.properties
new file mode 100644
index 0000000..8fe4ecc
--- /dev/null
+++ b/tcode.properties
@@ -0,0 +1,3 @@
+tcode.doc
+
+texjava.texjava = texjava.pl
diff --git a/tcode.sty b/tcode.sty
new file mode 100644
index 0000000..2d6ca6d
--- /dev/null
+++ b/tcode.sty
@@ -0,0 +1,214 @@
+\RequirePackage{html}
+\RequirePackage{alltt}
+\ProvidesPackage{tcode}
+ [2003/08/01 TCode]
+
+\latex{
+\newcommand{\param}[2]{\paragraph{\texttt{#1}: }#2}
+\newcommand{\blocktag}[2]{\paragraph{\texttt{#1}: }#2}
+\newcommand{\return}[1]{\paragraph{\textbf{Returns} }#1}
+\newcommand{\exception}[2]{\paragraph{\texttt{#1}: }#2}
+\def\bs{\char92}
+\newcommand{\htsum}{\sum}
+\newcommand{\htint}{\int}
+\newcommand{\htprod}{\prod}
+}
+
+%\def\defmodule#1 {\addcontentsline{toc}{subsection}{#1} \markboth{#1}{#1}
+% \centerline {\LARGE\bf #1}\bigskip \thispagestyle{nomark}}
+\def\defclass#1 {\section*{\centerline {\LARGE\bf #1}}\bigskip
+ \markboth{#1}{#1}\thispagestyle{nomark}
+ \addcontentsline{toc}{subsection}{#1}}
+\let\defmodule=\defclass
+
+\newcommand{\guisec}[1]{\vspace{20pt}
+\noindent\hrulefill\hspace{10pt}{\bf #1}\hspace{10pt}\hrulefill
+\vspace{10pt}\nopagebreak}
+
+\newif\ifdetailed\detailedtrue
+\def\detailed{\begingroup\setbox0=\vbox\bgroup\smallskip}
+\def\enddetailed{\egroup\ifdetailed\unvbox0\fi\endgroup}
+
+\def\citep{\@ifnextchar [{\@tempswatrue\@citexp}{\@tempswafalse\@citexp[]}}
+
+
+{\obeyspaces\gdef {\ }}
+\def\setverbatim{\def\par{\leavevmode\endgraf}
+ \parskip=0pt\parindent=0pt\obeylines\obeyspaces }
+\chardef\other=12
+\def\ttverbatim{\setverbatim\tt
+ \catcode`~=\other
+ \catcode`\{=\other \catcode`\}=\other \catcode`\_=\other
+ \catcode`\^=\other \catcode`\$=\other \catcode`\%=\other
+ \catcode`\#=\other \catcode`\&=\other \baselineskip=11pt
+ }
+ % Reproduit tel quel ce qui est ecrit, en caracteres \tt.
+ % On doit faire \begingroup\ttverbatim .... \endgroup
+\def\smallttverbatim{\ttverbatim\small\tt}
+\def\code {\vfil\vfilneg\vbox\bgroup\ttverbatim}
+\def\longcode {\vfil\vfilneg\bgroup\ttverbatim}
+\def\smallc {\small\tt\baselineskip=9.5pt}
+\def\footc {\footnotesize\tt\baselineskip=9.0pt}
+\def\smallcode {\code\smallc}
+\let\endcode=\egroup
+\let\endlongcode=\egroup
+\let\vcode=\code
+\let\endvcode=\egroup
+
+
+% \latex{\def\bs{\char92}}
+% \html{\def\bs{\rawhtml\\endrawhtml}}
+
+
+% Changes @ into an ordinary character.
+\makeatletter
+
+%\def\latexonly{}
+%\def\endlatexonly{}
+
+% We define a TeX command that takes anything as an argument.
+% But the argument must be followed by some predetermined string.
+% Strongly inspired from the LaTeX verbatim environment
+% Some catcodes must be changed to allow \, { and } inside
+% that string. Without any change, this would be processed as a
+% control sequence instead of a normal string.
+% Here, the group is not a macro and the tokens are
+% processed, so the catcode changes have immediate effect.
+\begingroup \catcode `|=0 \catcode `[= 1
+\catcode`]=2 \catcode `\{=12 \catcode `\}=12
+\catcode`\\=12 |gdef|@xhideenv#1\end{hide}[|end[hide]]
+|gdef|@xhide#1\endhide[|endhide]
+|endgroup
+
+% This command activates the verbatim mode that will allow
+% the command defined above to take paragraphs as its argument, not
+% only one line of text as in usual cases. The catcode of
+% every special character, including escape, is changed to other
+% so no LaTeX command will be processed. The commands following
+% the \let\do line has effect even if \ is redefined because
+% the \@hide command's definition was tokenized before the catcodes
+% change.
+\def\@hide{\ttverbatim
+ \let\do\@makeother \dospecials
+%\obeylines
+ \everypar \expandafter{\the\everypar \unpenalty}%
+\@vobeyspaces
+}
+
+% To make an environment that hides its contents, we put
+% the contents into box0 instead of the outer vertical list.
+% If full is set to true, the boxing will be undone and
+% the contents, moved to the outer vertical list.
+% The outer grouping allows the box to be local to the
+% environments. With boxes like that, nesting is allowed.
+\newif\ifhide\hidetrue
+\def\hide{\begingroup\setbox0=\vbox\bgroup\smallskip}
+% \def\endhide{\egroup\iffull\unvbox0\fi\endgroup}
+\def\endhide{\egroup\ifhide\else\unvbox0\fi\endgroup}
+% perhaps \iffull ...\fi --> \ifhide\else ... \fi
+
+
+% Here, we use a different strategy because no command processing
+% must occur. First, verbatim mode is enabled and a special
+% command is called. This command takes one argument and
+% must be followed by \end{htmlonly}. The argument, which is the
+% contents of the environment, will be discarded without processing.
+% This technique is strongly inspired from the LaTeX verbatim
+% environment.
+%\def\htmlonly{\begingroup\@hide \@xhtmlonly}
+%\def\endhtmlonly{\endgroup}
+
+% When tokenizing the definition of code command,
+% TeX must know that { and } can be part of a TeX command,
+% [ and ] must become group delimiters.
+% These changes will apply to a group defined here, not
+% for the content inside the code environment.
+% Inside the code command, we must redefine the catcode.
+% When the macro is expanded, it will execute the catcode tokens,
+% changing again { and } to make them ``letters''.
+\begingroup
+\catcode`\{=11
+\catcode`\}=11
+\catcode`\[=1
+\catcode`\]=2
+\gdef\@code[\ttverbatim
+\let\@xh=\@xhide
+\def\hide[\bgroup
+ \let\do\@makeother \dospecials
+ \everypar \expandafter[\the\everypar \unpenalty]%
+ \@vobeyspaces \@xh]
+\def\endhide[\egroup\let\@xh=\@xhide]
+\catcode`\{=11
+\catcode`\}=11
+\def\begin{hide}[\let\@xh=\@xhideenv
+\begin[hide]]
+]
+\gdef\code[\vfil\vfilneg\vbox\bgroup\@code
+\def\end{code}[\end[code]]]
+\gdef\longcode[\vfil\vfilneg\bgroup\@code
+\def\end{longcode}[\end[longcode]]]
+\gdef\smallcode[\code\smallc
+\def\end{smallcode}[\end[smallcode]]]
+\gdef\vcode[\code
+\def\end{vcode}[\end[vcode]]]
+\gdef\longvcode[\longcode
+\def\end{longvcode}[\end[longvcode]]]
+\endgroup
+\def\endcode{\egroup}
+\def\endlongcode{\egroup}
+\def\endsmallcode{\egroup}
+\def\endvcode{\egroup}
+\def\endlongvcode{\egroup}
+
+%% This is adapted from \boxedverbatim in moreverb.sty
+\def\boxedverbatiminput#1{%
+ \def\verbatim at processline{%
+ {\setbox1=\hbox{\the\verbatim at line}%
+ \hsize=\wd0 \the\verbatim at line\par}}%
+ \@minipagetrue%%%DPC%%%
+ \@tempswatrue%%%DPC%%%
+ \setbox0=\vbox\bgroup \verbatiminput{#1}\egroup
+ \centerline{\fbox{\box0}}%
+}
+
+\makeatother
+
+\def\parup{\nobreak\vskip -2pt\nobreak}
+\def\tab{\begingroup\small\parindent=0pt%
+ \advance\leftskip by 1.5em\parup}
+\def\tabb{\begingroup\small\parindent=0pt%
+ \advance\leftskip by 3.0em\parup}
+\def\tabbb{\begingroup\small\parindent=0pt%
+ \advance\leftskip by 4.5em\parup}
+\def\endtab{\vskip 0.01pt\advance\leftskip by -1.5em\normalsize%
+ \endgroup}
+\def\endtabb{\vskip 0.01pt\advance\leftskip by -3.0em\normalsize%
+ \endgroup}
+\def\endtabbb{\vskip 0.01pt\advance\leftskip by -4.5em\normalsize%
+ \endgroup}
+
+% The class and externalclass macros could be merged if it was
+% possible to react differently if an optional argument is absent.
+% TeX, unfortunately, does not support overloading of macros.
+% class could have an optional argument for the package.
+% If it is specified, we format \texttt{package.class}.
+% If not, we format \texttt{class}. To have that work,
+% we would have to force the user to append a period after
+% the package name (\class[package.]{class}).
+\def\class#1{\texttt{#1}}
+\def\externalclass#1#2{\texttt{#2}}
+
+% The same type of problem happens here.
+% Signature could be turned into an optional argument,
+% but it would have to go at the beginning of the method,
+% which is not intuitive. (e.g. \method[double]{density})
+\def\method#1#2{\texttt{#1}}
+% We have to choose whether the name of the class will be prepended
+% before the name of the method. This increases the quantity
+% of long typed-text names that result in overfull hboxe.
+% In Javadoc, since the name is an hyperlink, the class name is
+% less a necessity. So in general, it is not required. One can
+% prepend it manually before the \externalmethod if needed.
+\def\externalmethod#1#2#3#4{\texttt{#3}}
+\def\clsexternalmethod#1#2#3#4{\texttt{#2}\discretionary{}{}{}\texttt{.#3}}
+\def\unmoved{\relax}
diff --git a/tcode.tex b/tcode.tex
new file mode 100644
index 0000000..faf689c
--- /dev/null
+++ b/tcode.tex
@@ -0,0 +1,1023 @@
+\documentclass[12pt]{article}
+\usepackage{lmac}
+\usepackage{alltt}
+\usepackage{html}
+\usepackage{tcode}
+
+\mytwoheads
+\dateheadtrue
+\tolerance=500
+\textwidth=6.5in
+\textheight=9.5in
+\parskip = 3pt
+
+\newif\ifnotes\notestrue
+% \notesfalse %% Uncomment this line to hide footnotes. <----
+%
+\def\boxnote#1#2{\ifnotes\fbox{\footnote{\ }}\ \footnotetext{ From #1: #2}\fi}
+\def\pierre#1{\boxnote{Pierre}{#1}}
+\def\hpierre#1{}
+\def\richard#1{\boxnote{Richard}{#1}}
+\def\hrichard#1{}
+\def\eric#1{\boxnote{\'Eric}{#1}}
+\def\heric#1{}
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{document}
+
+\begin{titlepage}
+
+\null\vfill
+\begin {center}
+{\Large\bf TCode} \\[20pt]
+{\Large\bf User Guide } \\[20pt]
+{\Large\bf Tools for documenting Java programs in \LaTeX }\\[15pt]
+ Version: \today \\
+\vfill\vfill
+\end {center}
+
+\vfill
+This document describes facilities that help writing Java classes,
+together with detailed documentation of their application programming
+interface (API), in a single \LaTeX{} file.
+The \LaTeX{} package {\tt tcode} offers special commands and
+environments for typesetting API documentation and user guides.
+It permits one to display certain parts of the code (e.g., method headers),
+hide others (e.g., method bodies and private variables),
+and explain the methods, variables, etc., in a uniform format.
+Although it is targeted to that language,
+it works not only for Java, but also for other programming languages
+such as C, C++, etc.
+\LaTeX\ will produce the documentation as a {\tt .dvi}, {\tt .ps},
+or {\tt .pdf} file.
+
+A Perl script called \emph{texjava} produces a
+{\tt .java} file by extracting the code form the {\tt .tex} file.
+With the help of \latextohtml{}, \emph{texjava} also transforms some
+of the documentation into Javadoc
+format, so that the \emph{javadoc} program can later produce HTML
+documentation from the {\tt .java} file.
+Another Perl script called \emph{javatex} does the reverse transformation,
+recovering the {\tt .tex} file from the {\tt .java} file.
+\vfill
+\end{titlepage}
+
+%\pagenumbering{roman}
+%\tableofcontents
+%\pagenumbering{arabic}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\section{Introduction}
+\label{sec:intro}
+
+\emph{Javadoc} is the standard Java tool for generating API documentation
+\cite{iFLA99a}.
+Its output is in HTML format.
+However, HTML is very limited on certain aspects such as
+displaying mathematical expressions, complex tables, etc.
+Good modern typesetting systems such as \TeX{} and \LaTeX{} offer
+much better quality, flexibility, and precision than HTML
+for producing detailed and nice-looking documentation \cite{iGOO99a}.
+\LaTeX{} is certainly a tool of choice for API documentation of
+mathematically-oriented software. On the other hand, for Java libraries,
+standard online HTML documentation based on Javadoc is almost a necessity.
+
+With the tools described here, one can program a Java class and
+document its API in great detail, in a single \LaTeX{} file.
+The \LaTeX{} program produces a nicely-typeset version of the
+documentation, while a Perl script called \emph{texjava}, helped by
+\latextohtml{} \cite{iGOO99a}, produces a {\tt .java} file, which can
+be compiled into a {\tt .class} file and can also be used by javadoc
+to produce HTML documentation.
+The {\tt .java} file produced by \emph{texjava} can be retransformed
+(to a certain extent) into a \LaTeX{} file by the Perl script \emph{javatex}.
+
+The \LaTeX{} package {\tt tcode} defines special commands and
+environments for typesetting API documentation in a uniform format,
+and selectively displaying or hiding (from the API documentation or
+user's guide) pieces of Java code.
+This \LaTeX{} class file can also be used for
+other programming languages such as C, C++, etc.
+In this document, we assume that the target language is Java.
+
+These tools are rudimentary and much simpler, for example, than the
+CWEB system of documentation \cite{iKNU94a}, also based on \TeX{}.
+
+Section~\ref{sec:layout} explains how \LaTeX{} files should be organized
+for using these tools, describes the main commands, and give an example.
+Section~\ref{sec:texjava} shows how to run \emph{texjava}.
+Sections~\ref{sec:javatex} and \ref{sec:javatex2}
+tell about \emph{javatex} and how to run it.
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\section{Layout of the \LaTeX{} files}
+\label{sec:layout}
+
+A \LaTeX{} document using the {\tt tcode} \LaTeX{} package to describe
+a Java package (or set of packages) normally has a single master file,
+with several secondary {\tt .tex} files, which are loaded via
+\verb!\include{ }! commands in the master file.
+There should be one secondary {\tt .tex} file for each {\tt .java}
+file that we want to have (typically, this is one file for each Java
+class or interface in the package). The master file may contain
+other material and include additional files as well.
+\LaTeX{} or pdf\LaTeX{} will process the master file to produce the
+detailed documentation, which will usually end up as a {\tt .pdf} file.
+The {\tt .tex} files that implement Java classes are transformed one by one
+into the corresponding {\tt .java} files (or {\tt .c}, {\tt .cpp}, etc.,
+in the case of other languages) by the Perl script {\tt texjava.pl}
+helped by the \latextohtml{} program, which basically extracts the code
+and formats additional information for \emph{javadoc}. Since the
+script can process only one {\tt .tex} file at a time, one may
+create a Makefile
+% or an Ant project using the {\tt Texjava} task
+to automate the generation process
+when dealing with many files.
+
+%%%%%%%%%%%% tcode package
+\paragraph*{The {\tt tcode} package.}
+To use the commands of the {\tt tcode} \LaTeX{} package, this one
+must be imported via the command
+
+\verb!\usepackage{tcode}!
+
+\noindent
+This command will locate and load {\tt tcode.sty}, so this file must be
+accessible in a directory pointed to by the {\tt TEXINPUTS} environment
+variable. The {\tt tcode} package requires the {\tt html} and {\tt alltt}
+packages which should also be locatable through the {\tt TEXINPUTS}
+environment variable.
+
+%%%%%%%%%%%%%% code
+\paragraph*{The code environment.}
+The basic construct for identifying programming code in the \LaTeX{}
+files is the {\tt code} environment.
+Everything between \verb!\begin{code}! and \verb!\end{code}!,
+with the exception of \LaTeX{} commands,
+is displayed in special verbatim mode, with a typewriter font, by \LaTeX{}
+and is treated as Java code (copied into the {\tt .java} file)
+by \emph{texjava}. The Perl script disallows nesting of
+{\tt code} environments. The
+\verb!\end{code}! command should always be placed alone at the beginning of a line.
+A document is therefore composed of an alternance of
+text blocks and code blocks, starting and ending with a text block.
+
+%% longcode
+The contents of a {\tt code} environment is actually treated as a ``box''
+by \LaTeX{}, which means that
+% it cannot be split on two pages (just like a figure or table).
+all the code it contains will appear on the same document page. This
+is what we expect when documenting methods, because we wish
+a multi-line signature not to span on two pages.
+However, if the code is too long to fit
+in the page, \LaTeX{} will issue an ``overfull vbox'' warning and
+the code will not appear entirely on the resulting document.
+The {\tt longcode} environment is convenient for displaying long blocks
+of code; it behaves just as the {\tt code} environment,
+except that it allows the code to span over two or more pages.
+
+%% smallcode
+
+%% vcode
+There are situations where one would like to have some code displayed
+in the documentation, but not have it in the {\tt .java} file
+(e.g., when giving programming examples in the documentation).
+The {\tt vcode} and {\tt longvcode} environments do that:
+\LaTeX{} treats them just like the {\tt code} and {\tt longcode}
+environments, but \emph{texjava} does not copy the code into the {\tt .java} file.
+However, it will appear as typed text in the HTML documentation.
+
+The following character strings should never appear inside programming
+code (e.g., in a litteral string or in a comment), because they will be
+interpreted as active \LaTeX{} commands:
+\verb!\hide!, \verb!\endhide!, \verb!\code!, \verb!\endcode!,
+\verb!\begin{hide}!, \verb!\end{hide}!, \verb!\begin{code}!,
+\verb!\end{code}!. If one needs to use such a string, one must
+separate it in two parts, as in the following example:
+{\tt String s = "\bs\bs" + "begin{code}";}.
+
+
+%%%%%%%%%%%%% hide
+\paragraph*{The hide environment.}
+Normally, we do not want all the code to be displayed in the API
+documentation. For example, the private fields, methods, and classes,
+as well as the method implementations, should be hidden.
+The {\tt hide} environment permits one to easily hide
+parts of the code and text from the \LaTeX{} documentation:
+Everything between \verb!\begin{hide}! and \verb!\end{hide}!
+is simply not shown in the document produced by \LaTeX{}.
+This environment can be applied to a block of text as well as to a block
+of code (i.e., inside the code environment).
+Nesting is allowed, but not inside the code environment.
+For example, one may place a whole set of methods together with their
+descriptions in a {\tt hide} environment, to remove them from the
+documentation, while part of the code of each method may already be
+in a {\tt hide} environment (inside the {\tt code} environment).
+In this case, the outer {\tt hide} environment must begin and end
+\emph{outside} any {\tt code} environment.
+
+The {\tt hide} environment has no effect on the code extracted
+by \emph{texjava} in the sense that all hidden code goes to the
+{\tt .java} file anyway.
+However, the hidden documentation will not appear in the HTML conversion
+produced by Javadoc.
+
+%%%%%%%%%%%% \hidefalse
+\paragraph*{No hiding.}
+In case one wishes a documentation that contains all the code,
+including the method implementations and other private material,
+one can simply turn OFF the hiding mechanism of the {\tt hide}
+environment with the command \verb!\hidefalse!.
+It can be turned ON again with the command \verb!\hidetrue!.
+However, turning the hide mechanism OFF will get \LaTeX\ to
+parse hidden contents to display it. It will then react to backslashes
+in the hidden code and try to interpret control sequences.
+For example, if some hidden code contains
+
+{\tt System.out.println ("This is a string,\bs nAnd another one.");}
+
+\noindent
+it must remain hidden
+otherwise \LaTeX\ will complain about the invalid control sequence {\tt\bs n}.
+
+%%%%%%%%%%%% \detailedtrue
+\paragraph*{Detailed contents.}
+The {\tt detailed} environment is convenient for producing two versions
+of the documentation, one more detailed than the other.
+It comes with a switch that can be turned ON by the command
+{\tt\bs detailedtrue} and turned OFF by the command {\tt\bs detailedfalse}.
+Everything inside the {\tt detailed} environment is ignored by \LaTeX{}
+when the switch is turned OFF, otherwise it is included normally.
+By default, the switch is turned ON. When creating the HTML
+version, the {\tt detailed} environment is ignored, meaning
+that the HTML document will never be detailed.
+
+
+%%%%%%%%%%%%%
+\paragraph*{Restrictions due to \latextohtml.}
+
+The \emph{texjava} script calls the \latextohtml{} utility to convert
+the documentation in the {\tt .tex} file to HTML format in the {\tt .java}
+file. It generates HTML 4.0 code using Unicode for mathematical symbols.
+This utility processes standard \LaTeX{} commands,
+but not user-defined commands/macros and commands/macros
+found in external packages.
+Adding support for new packages implies writing Perl code intended
+for processing the different commands provided by these packages
+\cite{iGOO99a}.
+This operation is complex and requires a good understanding of the
+\latextohtml{} conversion process (which is yet undocumented at the time
+of this writing).
+
+The contents intended for HTML conversion should therefore be as simple as
+possible and should contain only standard \LaTeX{} commands and environments.
+Unknown environments and mathematics are translated to images using \LaTeX{}
+(called by \latextohtml{}).
+However, image creation is time consuming and should be avoided by
+restricting usage of the math mode and complex environments to
+\emph{\LaTeX-only} subblocks (see below).
+Sometimes, images may mysteriously appear with a gray background.
+If \LaTeX{} generates an error when making an image,
+it will skip it, \latextohtml{} will not notice that, and
+subsequent images may have the wrong number.
+The {\tt equation} and {\tt eqnarray} environments are converted
+to their star forms because problems arise with equation numbers.
+The {\tt ref} and {\tt cite} commands are also ignored because reference
+collecting accross several independent runs of \latextohtml{} causes problems.
+
+Except for the {\tt hide} environment, no other environment should
+span more than one documentation block, i.e.,
+should not contain a {\tt code} environment.
+% each environment must begin and end in the same text block.
+Departure from that rule could prevent \latextohtml{} from writing
+the markers separating the blocks (i.e., the fields and methods),
+and empty documentation blocks
+could then appear for subsequent fields and methods.
+% In the interest of speed,
+The script calls \latextohtml{} only once for the \LaTeX\ file given to it,
+%% only for the master file and not for each {\tt .tex} file? No.
+so any modification of the \LaTeX\ parameters in one text block
+could have an impact on the subsequent blocks.
+
+%%%%%%%%%%%%%
+\paragraph*{{\LaTeX-only} and {HTML-only} parts.}
+
+Certain parts of the {\tt .tex} files can be intended only for \LaTeX{},
+others only for the HTML file.
+This can be specified by the usual commands and environments
+available in the {\tt html} package (e.g., the {\tt latexonly},
+{\tt htmlonly}, and {\tt rawhtml} environments).
+
+Everything inside a {\tt latexonly} environment is ignored by \latextohtml{}.
+This is a good place for complex mathematical expressions and tables,
+for example.
+On the other hand, everything inside a {\tt htmlonly} or {\tt rawhtml}
+environment is ignored by \LaTeX{}.
+Material inside a {\tt rawhtml} environment is assumed to be HTML code,
+which is copied directly to the {\tt .java} file and eventually the
+{\tt .html} file, whereas material inside the {\tt htmlonly} environment
+is translated into HTML by \latextohtml{}.
+
+
+%%%%%%%%%%%%% \defclass
+\paragraph*{Header of a class or module.}
+The command \verb!\defclass{!\emph{classname}\verb!}!
+can be used to start the documentation of a Java class or interface.
+The command places its argument on a line by itself, centered,
+in a large font. It also adds a corresponding entry to the table of
+contents and modifies the page headings to contain the class name.
+The command \verb!\defmodule{!\emph{name}\verb!}!
+has exactly the same effect.
+
+The first block of text is considered as a class or file documentation
+block. In the {\tt .java} file, it will be inserted as a
+doc comment for \emph{javadoc}, at the beginning of the class definition.
+For this reason, the first block of code processed by \emph{texjava}
+must contain the Java class definition.
+
+%%%%%%%%%%%%%
+\paragraph*{Subsequent blocks of code and text.}
+After the first block of code (i.e., {\tt code} or {\tt longcode}
+environment), there is an alternance of a block of text, a block of code,
+a block of text, etc. For each such block of code, the text that follows
+it immediately is assumed to be its corresponding \LaTeX{} documentation.
+Therefore, \emph{texjava} will insert this text as a (javadoc)
+\emph{doc comment} for the last field or method appearing in this block
+of code (and not in a {\tt hide} environment).
+
+When a class has many documented methods, it may be convenient to
+partition them into different groups in the \LaTeX{} documentation,
+with a descriptive header above each group.
+The command \verb!\guisec{!\emph{header}\verb!}! outputs such a header,
+centered horizontally, with horizontal lines on each side.
+It should not be placed inside a {\tt code} environment and should
+always be alone in its own paragraph.
+A text block that contains this command will be splitted in two parts.
+The contents preceeding the section will be inserted as usual whereas
+the sectioning command and all the following contents will be
+inserted \emph{after} the previous code block.
+With the \verb!\unmoved! command, one can achieve the
+same effect of a sectioning command without displaying anything.
+Note that \emph{javadoc} will always ignore this
+\verb!\guisec! and any other sectioning commands,
+so it cannot be used to regroup class
+members in the HTML documentation.
+
+
+%%%%%%%%%%%%% tab, tabb, tabbb
+\paragraph*{Indenting documentation.}
+The environments {\tt tab}, {\tt tabb}, and {\tt tabbb}
+have been defined to indent the documentation and put it in a smaller font.
+These environments are normally used to describe fields and methods,
+they are ignored by \latextohtml{},
+and produce the following results:
+
+\begin{tab}
+This is a text indented with {\tt tab}.
+\end{tab}
+
+\begin{tabb}
+This text is more indented because it is in a {\tt tabb} environment.
+\end{tabb}
+
+\begin{tabbb}
+This text is still more indented because it is in a {\tt tabbb}
+environment.
+\end{tabbb}
+
+
+%%%%%%%%%%%%% Doc-comment tags
+\paragraph*{Doc-comment tags for javadoc.}
+%
+The following \LaTeX{} commands are mapped by \emph{texjava}
+to the corresponding \emph{javadoc} doc-comment tags
+% (obtained by replacing the character ``\verb!\!'' by ``\verb!@!''),
+which are used to encode specific information about classes,
+fields, methods, etc. (see \cite[chapter 7]{iFLA99a}).
+These doc comments will also appear in the \LaTeX{} documentation.
+For doc comments that are to appear only in the java and HTML files,
+one can use the \emph{javadoc} tags directly
+(provided that \emph{texjava} is called with the {\tt -nosavelatex} option).
+
+The \LaTeX{} commands \verb!\param!, \verb!\return!, etc.,
+are mapped to the doc-comment tags \verb!@param!, \verb!@return!, etc.
+These commands should be placed at the end of the method documentation,
+in the same order as they are described below.
+% \LaTeX{} will not reorder them and \emph{javadoc} will place them at
+% the end of the documentation for each method.
+The available commands and their descriptions are:
+
+\noindent
+\verb!\param{!\emph{param-name}\verb!}{!\emph{description}\verb!}!
+
+\begin{tab}
+Gives a description for the parameter \emph{param-name} of the current
+method. This parameter name must be a single word whereas the description
+is usually a short sentence. Such a description should appear for every
+method parameter.
+\end{tab}
+
+\noindent
+\verb!\return{!\emph{description}\verb!}!
+
+\begin{tab}
+Describes, in one or more sentences, what is returned by the current method.
+This should appear for every method returning values.
+\end{tab}
+
+\noindent
+\verb!\exception{!\emph{class-name}\verb!}{!\emph{description}\verb!}!
+
+\begin{tab}
+Gives the class name of an exception raised by Java when the situation
+described by the sentence in the second argument occurs.
+\end{tab}
+
+\noindent
+\verb!\class{!\emph{class-name}\verb!}!
+
+\begin{tab}
+Indicates the name of a class. This is formatted in typed text
+in the \LaTeX\ document and converted to
+an hyperlink in the HTML document.
+
+Example: \verb!See class \class{GofStat} for more information!\\
+ \verb!Use \class{java.util.List} to store the data.!
+\end{tab}
+
+\noindent
+\verb!\externalclass{!\emph{package}\verb!}{!\emph{class-name}\verb!}!
+
+\begin{tab}
+Indicates the fully qualified name of a class. This is formatted in typed text
+in the \LaTeX\ document, and converted to
+an hyperlink in the HTML document.
+This macro can be useful if one does not want the fully
+qualified package name to appear in the \LaTeX\ and HTML document
+whereas it is sometimes necessary for Javadoc to hyperlink to the class.
+If one wants to have the full package name, he can write
+the full qualified name as the argument of the {\tt class} command.
+
+Example: \verb!The \externalclass{umontreal.iro.lecuyer.util}{Num}! will
+ show {\tt Num} as a label whereas
+ \verb!\externalclass{umontreal.iro.lecuyer}{util.Num}! will show {\tt util.Num}.
+\end{tab}
+
+\noindent
+\verb!\method{!\emph{method-name}\verb!}{!\emph{signature}\verb!}!
+
+\begin{tab}
+Indicates the name of a method in the current class.
+This is formatted in typed text
+in the \LaTeX\ document, and
+converted to an hyperlink in HTML.
+If the signature is empty, Javadoc will link to the first method with
+that name. The signature will never be shown in the link labels.
+If one wants to show the signatures, he must write it in parentheses
+after the method name.
+One can also use \verb!\method! and the following \verb!\externalmethod!
+to link to fields. In this case, the signature argument will be empty.
+
+Examples: \verb!\method{density}{}! and \verb!\method{density}{double}!
+ will generate the {\tt density} label
+ whereas \verb!\method{density(double)}{}! will generate {\tt density(double)}.
+\end{tab}
+
+\noindent
+\verb!\externalmethod{!\emph{package}\verb!}{!\emph{class-name}\verb!}{!\emph{method-name}\verb!}{!\emph{signature}\verb!}!
+
+\begin{tab}
+Indicates the name of a method in another class.
+This is formatted in typed text
+in the \LaTeX\ document, and
+converted to an hyperlink in HTML.
+The package name, class name and the signature will not appear in the label name.
+
+Example: \verb!\externalmethod{umontreal.iro.lecuyer.gof}{GofStat}{andersonDarling}{}!
+ will typeset {\tt andersonDarling}
+\end{tab}
+
+\noindent
+\verb!\clsexternalmethod{!\emph{package}\verb!}{!\emph{class-name}\verb!}{!\emph{method-name}\verb!}{!\emph{signature}\verb!}!
+
+\begin{tab}
+This is the same as \verb!\externalmethod! except that the class name
+is prepended. Since this macro can generate long strings in typed text
+which can easily result in overful boxes, a discretionary hyphen
+is added between class name and method name.
+
+Example:\\
+ \verb!\clsexternalmethod{umontreal.iro.lecuyer.gof}{GofStat}{andersonDarling}{}!
+ will be formated {\tt GofStat.andersonDarling}\\
+\verb!\clsexternalmethod{umontreal.iro.lecuyer}{gof.GofStat}{andersonDarling}{}!
+ will format {\tt gof.GofStat.andersonDarling}
+\end{tab}
+
+%%%%%%%%%%%%%
+\paragraph*{An example.}
+
+\begin{verbatim}
+\defclass{Complex}
+
+This class allows one to work with complex numbers of
+the form $a + bi$, where $a$ is the \emph{real} part of
+the number, \emph{b} is the imaginary part and
+$i=\sqrt{-1}$.
+
+\bigskip\hrule\bigskip
+
+\begin{code}
+
+public class Complex\begin{hide} {
+ private double realPart;
+ private double imagPart;\end{hide}
+
+ public Complex (double realPart, double imagPart)\begin{hide} {
+ this.realPart = realPart;
+ this.imagPart = imagPart;
+ }\end{hide}
+\end{code}
+\begin{tabb} Constructs a new {\tt Complex} number.
+\param{realPart}{The real part corresponding to $a$}
+\param{imagPart}{The imaginary part corresponding to $b$}
+\end{tabb}
+\begin{code}
+
+ public Complex add (Complex c)\begin{hide} {
+ realPart += c.realPart;
+ imagPart += c.realPart;
+ return this;
+ }\end{hide}
+\end{code}
+\begin{tabb} Adds two complex numbers.
+ \param{c}{The complex number to add to this one.}
+ \return{This object, allowing to perform more than one operation
+ on a single line of code.}
+\end{tabb}
+\begin{code}
+
+ // other methods...
+
+ public String toString()\begin{hide} {
+ return "(" + realPart + " + " + imagPart + "i)";
+ }
+}\end{hide}
+\end{code}
+\begin{tabb} Converts the number to a {\tt String} of
+ the form {\tt a + bi}.
+\end{tabb}
+\end{verbatim}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\section{Running Texjava}
+\label{sec:texjava}
+
+The Perl script {\tt texjava.pl} converts \LaTeX{} documents into
+Java code with javadoc-style comments.
+Everything inside a {\tt code} or {\tt longcode} environment is
+considered as Java code.
+% The script also works for other languages such as C, C++, etc.
+Since \LaTeX{} has a better error-detection scheme than \emph{texjava}
+and \latextohtml, it is a good idea to compile the documents
+first with \LaTeX{}, before using \emph{texjava}.
+
+The \LaTeX{} commands defined in the {\tt tcode} package are implemented
+for \latextohtml{} in the {\tt tcode.perl} file. This file should
+therefore be accessible to \latextohtml{}, i.e., it should be in a
+directory known by the {\tt\$LATEX2HTMLSTYLES} environment variable.
+See \cite[page 99]{iGOO99a} for details about this.
+The script has been tested on Perl~5.8.0 but it should
+work with any version~5 Perl interpreter. Under non-Unix operating
+systems, such as Microsoft Windows, it is necessary to install
+a Perl distribution, such as ActivePerl \cite{iACT03a}, before using {\tt texjava.pl}.
+For Linux environments using C-Shell, {\tt Tcoderc} shell script
+can be used to set the environment. It needs the environment
+variable {\tt TCODEHOME} to be set. It sets the {\tt TEXINPUTS}
+variable, creates {\tt .latex2html-init} if it does not already exist, and
+defines a {\tt texjava} alias to allow running {\tt texjava.pl} more
+easily.
+
+The following command runs the script:
+
+\noindent
+{\tt perl texjava.pl $[$-(no)images$]$ $[$-(no)html$]$ $[$-(no)savelatex$]$
+ $[$-htmloutdir {\rm\em dir\/}$]$\\
+ $[$-master {\rm\em masterfile\/}$]$ $[$-htmlonly$]$
+ $[$-htmltitle {\rm\em title\/}$]$}
+ \emph{infile} $[$\emph{outfile}$]$
+
+Here, {\tt texjava.pl} has to be replaced by a path to
+the script if it is not executed in the {\tt tcode} directory.
+Its arguments and options are as follows:
+
+\noindent
+\emph{infile}
+
+\begin{tab}
+The name of the input file, which should have the {\tt .tex} extension.
+If the extension is not given and no file with
+such a name exists, {\tt .tex} is appended to the file name.
+The input file is parsed but not modified.
+\end{tab}
+
+\noindent
+\emph{outfile}
+
+\begin{tab}
+The name of the output file.
+Normally, it should be a program file, e.g., with the {\tt .java} extension.
+If no extension is specified, {\tt .java} is assumed. When using the HTML
+option, {\tt .html} is used.
+If no output file is given, the name of the input file is taken,
+with a {\tt .java} or {\tt .html} extension. The file will be created
+or replaced in the same directory as the input file.
+If \emph{outfile} already exists, it will be replaced without notice,
+otherwise the file will be created.
+If \emph{infile} and \emph{outfile} are the same, an error will occur.
+\end{tab}
+
+\noindent
+{\tt -(no)images}
+
+\begin{tab}
+A switch to enable or disable image generation by \latextohtml{}.
+With the {\tt -images} option,
+images are generated and stored in the HTML output directory.
+They are copied into a subdirectory corresponding to the package
+of the Java file.
+With the {\tt -noimages} option, the conversion can be much faster,
+but no images (e.g., complicated mathematical formulas)
+will appear in the HTML file and if it does not already exist,
+the HTML output directory will not be created. Images will
+be replaced by placeholders in the generated files.
+Default value: {\tt -noimages}.
+\end{tab}
+
+\noindent
+{\tt -(no)html}
+
+\begin{tab}
+With the {\tt -html} option, \latextohtml{} is invoked to convert
+from \LaTeX{} to HTML.
+With the {\tt -nohtml} option, \latextohtml{} is not called, so the
+script can run faster, but no HTML conversion of the \LaTeX{}
+documentation is produced. This can be useful for environments which
+do not have \latextohtml{} installed.
+The \LaTeX{} contents is nevertheless saved as HTML doc comments in the
+Java code if {\tt -savelatex} is passed.
+Default value: {\tt -nohtml}.
+\end{tab}
+
+\noindent
+{\tt -(no)savelatex}
+
+\begin{tab}
+With the {\tt -savelatex} option, the script will save \LaTeX{} contents
+into Java doc comments, using special encoding.
+This results in rather ugly Java files,
+but permits one to recover the original \LaTeX{} file (at least to
+some extent) from the {\tt .java} file.
+The {\tt -nosavelatex} option unclutters the
+output file, but prevents reverting to \LaTeX.
+The combination {\tt -nohtml -nosavelatex} disables insertion in the output
+file of all doc comments generated from the \LaTeX{} source.
+Default value: {\tt -nosavelatex}.
+\end{tab}
+
+\noindent
+{\tt -htmloutdir }\emph{dir}
+
+\begin{tab}
+Specifies where the HTML output will be placed when \emph{Javadoc} processes
+the Java files. This will indicate to {\tt texjava.pl} where to put
+the image files generated by \latextohtml. If not specified, the
+images will be copied into an {\tt html} subdirectory of the output
+directory where the Java file is created. This option has no effet if
+the {\tt -html} option is not given. The HTML output directory is
+automatically created unless it already exists or the {\tt -noimages}
+option is specified. It is never emptied or removed by {\tt texjava.pl}.
+\end{tab}
+
+\noindent
+{\tt -master }\emph{masterfile}
+
+\begin{tab}
+The name of a master \LaTeX\ file for the \emph{infile} file.
+This file should compile successfully with the command {\tt latex master}.
+Usually, it will contain the \verb!\begin{document}! command and include
+the \emph{infile} file. Its preamble may contain macros used in \emph{infile}.
+The script will read only the preamble, i.e., everything before
+\verb!\begin{document}!. This preamble is used when constructing
+the document intended for \latextohtml{} processing.
+If no master file is specified, it is assumed that \emph{infile} itself is
+the master file.
+Forgetting to specify the master file when it is needed could prevent
+some required packages from being loaded into \latextohtml{} and generate
+unwanted additional images in the HTML file.
+\end{tab}
+
+\noindent
+{\tt -htmlonly}
+
+\begin{tab}
+Indicates that the script only has to convert a \LaTeX\ document
+to HTML, not processing Java code blocks. This option is useful
+to convert overviews into {\tt package.html} files.
+It is simpler and better than calling \latextohtml\ directly because
+{\tt texjava.pl} passes a bunch of options to \latextohtml\
+and transforms the {\tt .tex} and {\tt .html} contents
+to avoid some images from math formulas.
+\end{tab}
+
+\noindent
+{\tt -htmltitle }\emph{title}
+
+\begin{tab}
+When using HTML-only mode, allows to give a title to the generated
+HTML file. This title will be placed in the {\tt TITLE} element of {\tt HEAD}.
+If one wants to have a title containing spaces, it must be surrounded
+by quotation marks for the shell to pass it as one argument
+to the script. If no title is given, an empty string will be used
+as the title for the HTML document.
+\end{tab}
+
+%%%%%%%%%%%%
+\paragraph*{Examples.}
+
+To extract {\it Java} code from the \LaTeX\ file {\tt Event.tex},
+assuming that the master file is {\tt guide.tex},
+and place the result in the file {\tt Event.java}, one can use:
+
+%\noindent
+{\tt perl texjava.pl \ -master guide.tex \ Event.tex}
+
+\noindent
+which will create the {\tt Event.java} file and, if needed,
+a {\tt html} subdirectory that will contain images.
+To generate the \emph{javadoc} documentation (in HTML), one can use
+a command of the form:
+
+%\noindent
+{\tt javadoc -d html} \ \emph{javafilesorpackages} \ {\tt Event.java} \ \emph{javafilesorpackages}
+
+As another example, to extract the {\it C} code from the \LaTeX{}
+file {\tt chrono.tex} and place it in the header file {\tt chrono.h},
+assuming that the preamble is in {\tt guide.tex}, one can use:
+
+%\noindent
+{\tt perl texjava.pl \ -master guide.tex \ chrono.tex \ chrono.h}
+
+Here, one must not forget to specify the target name otherwise
+{\tt chrono.java} would be created instead of {\tt chrono.h}.
+
+%%%%%%%%%%%%
+\paragraph*{Restrictions, limitations, and special cases.}
+
+\begin{itemize}
+\item
+Due to the structure of the {\tt code} environment, every
+\LaTeX\ command taking no argument will be interpreted.
+Braces delimiting arguments
+will however display as contents in the code. This cannot be avoided
+because \LaTeX\ must interpret {\tt\bs begin} and {\tt\bs end}
+to support contents hiding and {\tt code} environment termination.
+\item
+If a package declaration is found before the class declaration in a
+given Java file, the script will place generated image files in an
+appropriate subdirectory of the HTML output directory. For exemple,
+if one writes the line {\tt package a.b.c;} in its Java program, {\tt
+ texjava.pl} will copy the images into a subdirectory named {\tt
+ a/b/c}. This reflects the Javadoc generated structure and allows
+proper image retrieval by the browser.
+
+\item
+Althought the script allows white spaces within commands
+(e.g., \verb!\begin {code}!), it can cause problems to \LaTeX.
+Such spaces must be avoided in commands controling the {\tt hide}
+environment inside a {\tt code} environment, and in the \verb!\end{code}!
+command.
+
+\item
+When hiding method bodies, one must add at least one space
+between \verb!\begin{hide}! and the open brace. If one
+writes
+
+\verb!\begin{hide}{!
+
+\noindent\LaTeX{} will treat the rest of the
+file as an argument to the {\tt hide} environment and an error will occur.
+
+\item
+The method bodies should always be hidden, otherwise, the
+insertion point of the documentation may be incorrectly computed.
+
+\item
+The first sentence of a doc comment is used by \emph{javadoc} as a
+\emph{brief} (a one-sentence summary)
+of the corresponding class, interface, field, or method.
+The first sentence of a \LaTeX{} documentation block which is to be
+converted to a doc comment should therefore be short and simple.
+It should not contain special commands, mathematical formulas, etc.,
+and should not be in a {\tt latexonly} environment.
+If a formatting problem arises with a too complicated first sentence,
+the script will simply insert a period on a single line (to represent
+an empty brief). This artefact will appear in the \emph{javadoc}
+documentation, but it will prevent badly formated HTML on
+the rest of the concerned page.
+
+\item
+With the {\tt -savelatex} option, the strings {\tt /*HIDE*/},
+{\tt /*ENDHIDE*/}, and {\tt /**} will be converted to
+{\tt /* HIDE */}, {\tt /* ENDHIDE */}, and {\tt /* *} everywhere.
+This implies in particular that \emph{javadoc} comments already in
+the code will be ignored!
+
+\item
+If a {\tt package}, {\tt class} or {\tt interface} keyword is found in a long comment
+before the Java class or interface declaration,
+and if there is no star preceeding the keyword on the line,
+the script will get confused about where to insert the class
+documentation or will put images at the wrong place.
+
+\item
+Problems may arise for Java because of the saved \LaTeX{} contents.
+If a text block contains a \LaTeX{} command starting with {\tt u}, e.g.,
+{\tt\bs unitlength}, it will be replaced, in the comments,
+by {\tt\bs @unitlength}. When reverting to \LaTeX, this substitution
+will be undone by \emph{javatex}, so one has to worry about it only
+when modifying the (hidden) saved \LaTeX\ contents directly in the
+{\tt .java} file before reverting to \LaTeX{}.
+
+\item
+If no {\tt code} or {\tt longcode} environment is found in the input file,
+the output file will contain only a single doc comment.
+
+\item
+The script uses HTML 4.0 with Unicode for mathematical symbols.
+For the symbols to be displayed correctly, one should use a recent
+version of major browsers.
+
+\item
+To perform the conversion, a recent
+version of \latextohtml{} is required. Version 2002 (1.62) does
+not convert greek letters to Unicode properly unless we use
+MathML which is not compatible with major browsers, whereas version
+2002-2-1 (1.70) works properly.
+\end{itemize}
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\section{The Javatex Script}
+\label{sec:javatex}
+
+{\bf Warning}: This script is experimental and not very reliable,
+so one should use it with care. It is strongly recommended to make
+a backup copy of the original \LaTeX{} file before using it.
+The script assumes that the code intended for conversion is
+syntactically correct and can be compiled without errors.
+
+The Perl script {\tt javatex.pl} can convert Java source files to
+\LaTeX{} documents. The {\tt .java} source files may have been
+produced by \emph{texjava}, but not necessarily.
+% (It also works for C or C++ source files.)
+For example, one may want to use a special editor for Java programs
+to edit the Java file and encode the \LaTeX{} documentation in it by hand,
+in the same format as it would have been saved by \emph{texjava}.
+
+The Java source file intended for conversion should normally contain
+Java doc comments, of the form {\tt /**} \emph{comments} {\tt */},
+where \emph{comments} can be any (multi-line) text.
+The contents of these comments is converted into \LaTeX{} documentation
+blocks for classes, interfaces, fields, and methods.
+Other types of comments in the code are simply ignored and preserved
+intact into code blocks.
+
+The contents of HTML commented blocks of the form \verb#<!--LATEX ... -->#
+will be inserted directly into the \LaTeX{} document.
+This construct allows hiding \LaTeX{} code inside Java doc comments.
+Note that a doc comment should never begin with such an
+HTML comment, otherwise \emph{javadoc} could get mixed up and
+produce badly-formatted documentation. If a block contains only
+\LaTeX\ code, it can be entered as a comment of the form
+{\tt /*LATEX ... */} rather than as a doc comment, in order to avoid
+confusion of \emph{javadoc}.
+
+The {\tt /*HIDE*/} \dots {\tt /*ENDHIDE*/} constructs found in the
+code are converted respectively to \verb!\begin{hide}! \dots
+\verb!\end{hide}! constructs.
+
+The {\tt /*CODE*/}, {\tt /*SMALLCODE*/}, and {\tt /*LONGCODE*/}
+constructs are converted to the {\tt code}, {\tt smallcode}, and
+{\tt longcode} environments.
+
+All java doc-comment markers {\tt /**} and {\tt */} will be removed,
+since these doc comments are converted to \LaTeX{} documentation.
+Any star at the beginning of a line in a doc comment will also be
+removed to follow Java doc-comment formatting conventions.
+Doc comment are considered converted from \emph{texjava} and
+should contain some special indications.
+Since HTML to \LaTeX{} conversion is not supported,
+unmarked text in comments is simply discarded.
+
+The first doc comment is considered as the class or interface documentation
+and will appear at the top of the resulting document.
+In the code, it should be placed on the top of the class or interface
+declaration.
+A block of code containing the code before the class documentation and
+until a new doc-comment block appears will be converted to a \LaTeX{}
+code block. Any subsequent block of comments will be inserted as \LaTeX{}
+contents after the declaration or body following the documentation.
+A declaration is detected by the presence of a semicolon (;) on a line.
+An end of body is detected when a balanced set of opening and closing
+brackets is found.
+
+The tab characters will be replaced by individual spaces,
+in order to be correctly displayed by \LaTeX.
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\section{Running Javatex}
+\label{sec:javatex2}
+
+As for {\tt texjava.pl}, the script requires a Perl 5 interpreter to
+be installed but \latextohtml{} is not necessary for {\tt javatex.pl}.
+The following command runs the script:
+
+%\noindent
+{\tt perl javatex.pl $[$-tabsize {\rm\em i\/}$]$}
+ \emph{infile} \ \emph{outfile}\\
+
+Here, {\tt javatex.pl} has to be replaced by a path to
+the script if it is not executed in the {\tt tcode} directory.
+Its arguments and option are as follows:
+
+\noindent
+\emph{infile}
+
+\begin{tab}
+The name of the input file, which should have the {\tt .java} extension.
+The input file is parsed but not modified.
+\end{tab}
+
+\noindent
+\emph{outfile}
+
+\begin{tab}
+The name of the output file, which should have the {\tt .tex} extension.
+If \emph{outfile} already exists, it will be replaced without notice,
+otherwise the file will be created in the working directory.
+If \emph{infile} and \emph{outfile} are the same, an error will occur.
+\end{tab}
+
+
+\noindent
+{\tt -tabsize }\emph{i}
+
+\begin{tab}
+By using the {\tt -tabsize }\emph{i} option, where \emph{i} is a non-negative
+integer, one can specify the number of spaces that corresponds to a tab
+character. The default value is 8.
+\end{tab}
+
+%%%%%%%%%%%%%%
+\paragraph*{Example:}
+
+To extract the \LaTeX{} code from the Java file {\tt Chrono.java}
+and place it in file {\tt Chrono.tex}, one can use:
+
+% \noindent
+{\tt perl javatex.pl \ Chrono.java \ Chrono.tex}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\section{Ant tasks}
+
+Apache Ant is becoming the de facto build system for Java applications.
+An XML build file instructs Ant how to build the Java package in a portable
+way. Unfortunately, Ant is not a scripting language and can only deal
+with plain {\tt .java} file. It could be possible to call {\tt texjava.pl}
+manually using the Ant built-in {\tt exec} task, but this would fastly
+because tedious and no dependency checking would be performed at all.
+On each build cycle, every {\tt .tex} file would be turned into a {\tt .java}
+and recompiled, since it would be freshly created, into a new {\tt .class} file.
+However, it is possible to extend Ant using user-defined
+tasks. TCode provides some Ant tasks to work with the \LaTeX{} files.
+The {\tt texjava} task allows one to process a batch of {\tt .tex} files
+into {\tt texjava.pl}, producing output {\tt .java} files. The {\tt pdflate}
+task allows one to construct, using pdf\LaTeX, the PDF documentation
+for a package. To use these tasks, one must include {\tt tcode.jar} in
+the CLASSPATH environment variable and declare the use tasks in
+the {\tt build.xml} file, using the {\tt taskdef} task. For example, to use
+{\tt texjava} task, one must write, in the {\tt project} section of {\tt build.xml},
+
+\noindent\verb!<taskdef name="texjava" classname=''umontreal.iro.lecuyer.tcode.Texjava"/>!
+
+\include{Texjava}
+\include{PdfLatex}
+
+\bibliographystyle{plain}
+\bibliography{ift} % Dans texmac.
+
+\end{document}
diff --git a/texjava.pl b/texjava.pl
new file mode 100644
index 0000000..54871c5
--- /dev/null
+++ b/texjava.pl
@@ -0,0 +1,926 @@
+#!/usr/bin/perl
+
+# Extracts the code from LaTeX documents and outputs the documentation
+# into Javadoc-style comments.
+#
+# Author: Eric Buist
+# Summer 2002 and 2003
+
+# The script parses its command-line arguments, reads the input
+# file and slices it into code blocks and text block. The contents
+# is inserted into a list of block and the text blocks' indices
+# are saved. All the text blocks are then merged together in order
+# to initiate a single run of LaTeX2HTML. The converted contents
+# is then parsed and distributed to the text blocks, which then
+# are transformed into Javadoc-style comments. The list of block
+# if finally merged and printed to the output file.
+
+use Cwd;
+use Getopt::Long;
+use File::Path; # To delete the temp directory
+use File::Spec; # Portability when using pathnames
+use strict;
+
+# success: used to indicate whether the ouput file has to be deleted
+# preamble: contains the preamble of the master LaTeX file
+# tempDir: contains the path of the temporary directory
+# outDir: directory where the output file will be
+# htmlOutDir: directory where the Javadoc HTML will go, used to put generated images
+# at the right place.
+# blockList: list of all code and text blocks
+# commentIndices: indices of all the text blocks into blockList
+# convertedComments: result of the LaTeX2HTML conversion split into chunks
+# classDocIndex: index, in blockList, of the class doc block
+# html: indicates if we perform the LaTeX to HTML conversion.
+# nocode: indicates if we convert a text-only file to HTML.
+# oldCurDir: stores the current directory when the script starts.
+# texDir: directory where the processed TeX file is.
+# masterFile: name of the master file, if any
+# htmlonlyTitle: Title of the HTML document in htmlonly mode.
+use vars qw($success $preamble $tempDir $outDir $htmlOutDir $classDocIndex
+ @blockList @commentIndices @convertedComments
+ $images $html $savelatex $htmlonly $oldCurDir
+ $texDir $masterFile $htmlonlyTitle);
+
+# Initialization
+
+$oldCurDir = getcwd;
+my $TEXTMODE = 0;
+my $CODEMODE = 1;
+# Commands initiating a code block.
+# vcode is not there because it only indicate a code snippet
+# included in the documentation.
+my $CODECMDS = "code|smallcode|longcode";
+$tempDir = "";
+
+$success = 1;
+
+$images = ''; # default: no image generation
+$html = ''; # default: produces no html
+$savelatex = ''; # default: no saving for latex
+$htmlonly = ''; # default: convert a LaTeX file to Java
+$htmlonlyTitle = '';
+$htmlOutDir = ''; # default: empty string, will be replaced by $outDir/html
+$masterFile = undef;
+# Check the arguments
+if (!GetOptions ('images!' => \$images,
+ 'html!' => \$html,
+ 'savelatex!' => \$savelatex,
+ 'htmlonly' => \$htmlonly,
+ 'htmltitle=s' => \$htmlonlyTitle,
+ 'htmloutdir=s' => \$htmlOutDir,
+ 'master=s' => \$masterFile) ||
+ (@ARGV < 1 || @ARGV > 2)) {
+ print "usage: perl texjava.pl [-(no)images] [-(no)html] "
+ . "[-(no)savelatex] [-(no)htmlonly] [-htmltitle title] [-htmloutdir dir] "
+ . "[-master master] <fin> [<fout>]\n";
+ exit 1;
+}
+
+# If no extension specified and the file does not exist, append .tex
+$ARGV[0] .= ".tex" if $ARGV[0] !~ /\..*$/ && !-e $ARGV[0];
+
+# If the out file is not given, strip the extension and append .java
+if (!defined ($ARGV[1])) {
+ $ARGV[1] = $ARGV[0];
+ $ARGV[1] =~ s/\..*$//;
+ $ARGV[1] .= $htmlonly ? ".html" : ".java";
+}
+else {
+ # apppend .java or .html if necessary
+ $ARGV[1] .= ($htmlonly ? ".html" : ".java") if $ARGV[1] !~ /\..*$/;
+}
+
+$masterFile .= ".tex" if defined ($masterFile) && $masterFile !~ /\..*$/ && !-e $masterFile;
+
+die ("filenames must be different") if $ARGV[0] eq $ARGV[1];
+
+# Determine the directory where fout will be created or overwritten.
+# Convert to absolute path first, then strip the file name
+# We use library function for portability purposes, some
+# tasks could be done with regexps if UNIX was assumed.
+$outDir = File::Spec->rel2abs ($ARGV[1])
+ if !File::Spec->file_name_is_absolute ($ARGV[1]);
+my ($vol, $dir, $file) = File::Spec->splitpath ($outDir);
+$outDir = File::Spec->catpath ($vol, $dir, "");
+
+($vol, $dir, $file) = File::Spec->splitpath ($ARGV[0]);
+$texDir = File::Spec->catpath ($vol, $dir, "");
+
+# If htmlOutDir is empty, set it with a default value.
+$htmlOutDir = File::Spec->catdir ($outDir, "html") if $htmlOutDir eq '';
+
+# Open the master file pointed to by the third argument, if
+# it is specified, and put its LaTeX preamble into the preamble
+# variable.
+$preamble = "";
+if (defined $masterFile) {
+ open MASTERFILE, $masterFile or die "cannot open $masterFile";
+ $preamble = join ("", <MASTERFILE>);
+ close MASTERFILE;
+
+ # We do not want all the document, only the preamble.
+ $preamble =~ s/\\begin\s*\{document\}.*$//s;
+}
+
+# Open the input and output files
+# Opening the out file now allows us to save work
+# if it cannot be opened later on.
+open (FIN, "<$ARGV[0]") or die ("cannot open input file $ARGV[0]");
+
+$success = 0; # We have an outfile to be deleted in case of errors
+ at blockList = ();
+ at commentIndices = ();
+
+# Initialize the block parser to text mode, unhidden
+# and with an empty current block.
+my $currentBlockMode = $TEXTMODE; # the mode of the currently parsed block
+my $hideCount = 0; # number of open hide environments
+my $currentBlock = ""; # currently parsed block
+my $lastCodeBlock = ""; # the last parsed code block
+my $classDocPrinted = 0; # 1 if first block of text printed
+my $classDocBlock = ""; # first block of text, class documentation
+my $codeCmd = "CODE"; # command used to initiate the code block
+
+if ($htmlonly) {
+ # We convert the entire LaTeX file to HTML.
+ my $contents = join ('', <FIN>);
+ push @blockList, $contents;
+ push @commentIndices, 0;
+}
+else {
+ while (<FIN>) {
+ # Reads the file line by line and splits it into blocks
+ # delimited by code environments.
+
+ my $li = $_; # use a named variable instead of the default $_
+
+ while (length ($li) > 0) {
+ # The loop allows processing more than one command
+ # per line. Commands are order-sensitive.
+
+ if ($currentBlockMode == $CODEMODE &&
+ $li =~ /^\/\*(\*+)/) {
+ # A Javadoc-style comment is either in the code, or in
+ # a literal string. Since this kind of things does not
+ # occur in strings very often, we can transform it
+ # a little bit. It will have the form /* * instead of /**.
+ $currentBlock .= "/* $1";
+ $li = $';
+ } elsif ($currentBlockMode == $CODEMODE &&
+ $li =~ /^\/\*($CODECMDS|hide|endhide)\*\//io) {
+ # The same thing as the previous condition.
+ $currentBlock .= "/* $1 */";
+ $li = $';
+ } elsif ($li =~ /^\\($CODECMDS)(?![a-zA-Z])/o ||
+ $li =~ /^\\begin\s*\{\s*($CODECMDS)\s*\}/o) {
+ # We have to look ahead for a non-alphanumeric character
+ # to end the code command. Without this check,
+ # some custom user commands (e.g., codebox) may
+ # be processed as a code command.
+
+ # Print an error message, ($. being the line number),
+ # and exit the script if we already are in code mode.
+ die ("l.$.: $li: \\begin{code} inside " .
+ "\\begin{code} not permitted")
+ if $currentBlockMode == $CODEMODE;
+
+ # hide/endhide balancing
+ # This is necessary to prevent
+ # LaTeX"HTML from skipping HTML comments
+ # marking the parts.
+ # We use a special environment that does not exist instead
+ # of the hide environment.
+ # Before calling LaTeX2HTML, we will convert that
+ # to hide and we will be able to remove these @hide's
+ # to prevent them from appearing into the comment LaTeX
+ # copy of the documentation.
+ # for (my $i = 0; $i < $hideCount; $i++) {
+ # $currentBlock .= "\\end{\@hide}";
+ # }
+
+ my $cmd = $1; # save the used code command
+ $li = $'; # save the part after \code for the next block.
+
+ if ($classDocBlock eq "") {
+ # When the first \code command is encountered,
+ # currentBlock is the first block of text and
+ # is considered the class
+ # documentation block. This block
+ # will be inserted in the first code block
+ # just on top of the class declaration.
+ $classDocBlock = $currentBlock;
+
+ # classDocBlock must not be empty or we will
+ # never output anything.
+ $classDocBlock = " " if $classDocBlock eq "";
+ } else {
+ # The current block is a text block because code
+ # mode and text mode alternates. So we have
+ # to process this text block and the last code block
+ # in order to save the result to the block list.
+ &processBlocks ($currentBlock, $lastCodeBlock,
+ $classDocPrinted ? "" : $classDocBlock);
+ $classDocPrinted = 1;
+ }
+
+ # If the command initiating the code block changes,
+ # we add a marker in the code file.
+ $cmd =~ tr/a-z/A-Z/;
+ $currentBlock = $cmd ne $codeCmd && $savelatex
+ ? "/*$cmd*/" : "";
+ $codeCmd = $cmd;
+ $currentBlockMode = $CODEMODE;
+ } elsif ($li =~ /^\\end($CODECMDS)(?![a-zA-Z])/o ||
+ $li =~ /^\\end\{($CODECMDS)\}/o) {
+ die ("l.$.: $li: \\end{code} without corresponding "
+ . "\\begin{code} found")
+ if $currentBlockMode == $TEXTMODE;
+
+ # Save the code block for future processing
+ $lastCodeBlock = $currentBlock;
+
+ $li = $'; # save the part after \endcode for the next block
+
+ # a new text block starts
+ $currentBlock = "";
+ # for (my $i = 0; $i < $hideCount; $i++) {
+ # $currentBlock .= "\\begin{\@hide}";
+ # }
+ $currentBlockMode = $TEXTMODE;
+ } elsif ($li =~ /^\\hide(?![a-zA-Z])/ ||
+ $li =~ /^\\begin\s*\{\s*hide\s*\}/) {
+ $hideCount++;
+
+ # We were not in hide mode before \hide, so save to block
+ $currentBlock .= "\\begin{hide}"
+ if $currentBlockMode == $TEXTMODE;
+ $currentBlock .= "/*HIDE*/" if $currentBlockMode == $CODEMODE;
+ $li = $'; # allow further processing of the line
+ } elsif ($li =~ /^\\endhide(?![a-zA-Z])/ ||
+ $li =~ /^\\end\s*\{\s*hide\s*\}/) {
+ die ("l.$.: $li: \\end{hide} found without a \\begin{hide}")
+ if !$hideCount;
+
+ $currentBlock .= "\\end{hide}" if $currentBlockMode == $TEXTMODE;
+ $currentBlock .= "/*ENDHIDE*/" if $currentBlockMode == $CODEMODE;
+ $hideCount--;
+ $li = $';
+ } elsif ($currentBlockMode == $TEXTMODE && $li =~ /^%/) {
+ # LaTeX comment found, stop processing this line.
+ $currentBlock .= $li;
+ $li = "";
+ } else {
+ # Reads only one character
+ $currentBlock .= substr ($li, 0, 1);
+ $li = substr ($li, 1);
+ }
+ } # End while for reading the line
+ } # End while for reading FIN
+
+
+ # Final balancing checkup
+ die ("missing \\end{code}") if $currentBlockMode == $CODEMODE;
+ die ("missing \\end{hide}") if $hideCount;
+
+ # We are now in unhidden text mode and there is
+ # a last unprocessed text block and code block. At worst,
+ # both of these blocks would be empty.
+ &processBlocks ($currentBlock, $lastCodeBlock,
+ $classDocPrinted ? "" : $classDocBlock);
+}
+
+if ($html) {
+ # Convert all the text blocks into HTML
+
+ if ($images) {
+ if (!-d $htmlOutDir) {
+ mkpath ($htmlOutDir, 0, 0755);
+ }
+ if (!-x $htmlOutDir) {
+ die ("Cannot access $htmlOutDir");
+ }
+ }
+ &createTempDir;
+
+ &latexToHtml;
+}
+
+if (!$htmlonly) {
+ # Transform the text blocks into Java comments incorporating
+ # the HTML conversion and the original commented LaTeX contents.
+ for (my $i = 0; $i < @commentIndices; $i++) {
+ my $ind = $commentIndices[$i];
+ $blockList[$ind] = &processTextBlock ($blockList[$ind],
+ $convertedComments[$ind],
+ $ind == $classDocIndex);
+ }
+
+ # Post-procesing on the code blocks
+ my $oldInd = -1;
+ for (my $i = 0; $i <= @commentIndices; $i++) {
+ my $ind = $i == @commentIndices ? @blockList : $commentIndices[$i];
+ for (my $j = $oldInd + 1; $j < $ind; $j++) {
+ my $hiderx = '\/\*HIDE\*\/';
+ # my $hidetxt = '/*HIDE*/';
+ my $endHiderx = '\/\*ENDHIDE\*\/';
+ # my $endHidetxt = '/*ENDHIDE*/';
+
+ # Remove implicit hiding markers
+ # $blockList[$j] =~
+ # s/$hiderx(\s*\{[\s\S]*?\})\s*$endHiderx/
+ # &countBraces ($1) == 0 ? $1 : "$hidetxt$1$endHidetxt"/geo
+ # if $ind != $classDocIndex + 1;
+
+ # Remove every hide markers if the LaTeX contents is not saved.
+ $blockList[$j] =~ s/$hiderx|$endHiderx//go if !$savelatex;
+ }
+ $oldInd = $ind;
+ }
+}
+else {
+ $convertedComments[0] =~ s/^(\s*<P>|\s*<[BH]R>)*//gio;
+ $convertedComments[0] =~ s/(<P>\s*|<[BH]R>\s*)*$//gio;
+ $blockList[0] = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"
+ . "<HTML>\n<HEAD>\n<TITLE>$htmlonlyTitle</TITLE>\n"
+ . "</HEAD>\n<BODY>\n"
+ . $convertedComments[0]
+ . "</BODY>\n</HTML>\n";
+}
+
+# Write the output file by merging every blocks
+open (FOUT, ">$ARGV[1]") or die ("cannot open output file $ARGV[1]");
+print FOUT join ("", @blockList);
+close FOUT;
+
+$success = 1;
+
+# We are done, the END sub will be called automatically.
+
+sub END {
+ # Close the two files.
+ # Remove the output file if there was an errors.
+
+ close FIN;
+ &deleteTempDir;
+}
+
+
+###################################################################
+
+
+# sub countBraces {
+# # Count the number of braces into txt.
+# # Returns the difference between the number of opening and closing
+# # braces.
+
+# my $txt = shift;
+
+# my $nob = $txt =~ tr/\{/\{/;
+# my $ncb = $txt =~ tr/\}/\}/;
+
+# return $nob - $ncb;
+# }
+
+sub createTempDir {
+ # Looks for a temporary directory and creates a subdir in it.
+
+ my @tempTry = ();
+
+ if (exists $ENV{"TEMP"}) {
+ push @tempTry, $ENV{"TEMP"};
+ }
+ elsif (exists $ENV{"TMP"}) {
+ push @tempTry, $ENV{"TMP"};
+ }
+ elsif (exists $ENV{"TMPDIR"}) {
+ push @tempTry, $ENV{"TMPDIR"};
+ }
+ push @tempTry, "/tmp";
+ push @tempTry, $outDir;
+ push @tempTry, ".";
+
+ foreach my $tmp (@tempTry) {
+ # We create a temporary subdirectory by appending
+ # the current process ID to texjava.
+ $tempDir = File::Spec->catfile ($tmp, "texjava$$");
+ return if mkdir ($tempDir, 0755);
+ }
+ $tempDir = "";
+ die "cannot create temporary subdirectory";
+}
+
+sub deleteTempDir {
+ # Deletes the created temporary subdirectory.
+
+ if (length ($tempDir) > 0) {
+ # We cannot die because die has already been called.
+ print "cannot delete $tempDir\n" if !rmtree ([$tempDir], 0, 1);
+ }
+}
+
+sub findLastDeclaration {
+ # Looks for the last visible C/C++/Java function
+ # or variable declaration into a code block.
+ # Returns the position of the beginning of
+ # the line of declaration, where one
+ # can insert comments.
+ # -1 is returned if no declaration is found.
+
+ my $codeBlock = shift; # @_ contains the sub's arguments
+
+ # Split using /*HIDE*/, /*ENDHIDE*/
+ my @subBlocks = split /(\/\*(?:END)?HIDE\*\/)/, $codeBlock;
+ my $hideCount = 0; # We are in an hidden code subBlock
+ my $fnPos = -1; # Pos of last seen declaration
+ my $spos = 0; # Position of beginning sbl into textBlock
+ foreach my $sbl (@subBlocks) {
+ if ($sbl eq "/*HIDE*/") {
+ $hideCount++;
+ }
+ elsif ($sbl eq "/*ENDHIDE*/") {
+ $hideCount--;
+ }
+ elsif (!$hideCount) {
+ # We are supposing that comments are always hidden
+ # or at least there are no comments at the end of
+ # the unhidden parts of code blocks. Under this assumption,
+ # we can look for the last declaration by looking for
+ # the last non-empty code line containing no more
+ # closing parentheses than opening parentheses.
+
+ my @lines = split /(\n+)/, $sbl; # split into lines
+ my $oldFnPos = $fnPos;
+ my $lpos = 0;
+ for (my $l = 0; $l < @lines && $fnPos == $oldFnPos; $l++) {
+ my $li = $lines[$l];
+ if ($li =~ /\S/) {
+ $fnPos = $lpos + $spos;
+ }
+ $lpos += length ($li);
+ }
+
+# my $lpos = length ($sbl); # position, into sbl, of the line
+
+# # n represents the number of open parentheses.
+# # If there are more closed parentheses than open
+# # parentheses, n is negative.
+# my $n = 0;
+# my $oldFnPos = $fnPos;
+# for (my $i = @lines - 1; $i >= 0 && $oldFnPos == $fnPos; $i--) {
+# my $li = $lines[$i];
+# $lpos -= length ($li);
+# if ($li =~ /\S/) {
+# # We have a non-blank line.
+# # Calculate the number of opening and closins parentheses
+
+# my $nop = $li =~ tr/\(/\(/;
+# my $ncp = $li =~ tr/\)/\)/;
+# $n = $n + $nop - $ncp;
+# $fnPos = $lpos + $spos if $n == 0;
+# }
+# }
+ }
+ $spos += length ($sbl);
+ }
+ return $fnPos;
+}
+
+sub processBlocks {
+ # Processes a block of text and a block of code.
+ # The block of text will be processed and inserted at the top
+ # of the last visible function in the block of code.
+ # If a non-empty class documentation block is passed, it will also
+ # be processed and inserted just on top of a class declaration,
+ # or at the top of the code block if no class declaration is found.
+
+ my ($textBlock, $codeBlock, $classDocBlock) = @_;
+ my $atBottom = "";
+
+ # If no declaration is found, the best place to insert
+ # the block is at its original location in the LaTeX file,
+ # so we put it at the end of the code block.
+ my $insPos = &findLastDeclaration ($codeBlock);
+ if ($insPos == -1) {
+ # No declaration found, everything goes at bottom.
+ $atBottom = $textBlock;
+ $textBlock = "";
+ }
+ if ($textBlock =~ /(\\(sub)*section\*?|\\guisec|\\unmoved)(?![a-zA-Z])/) {
+ # If a sectioning command is found, the text block must be splitted.
+ # The part following the section (maybe a summary description)
+ # will not be moved whereas the part preceeding it (method description)
+ # will be moved.
+ my $p = length $`;
+ $atBottom = substr ($textBlock, $p);
+ $textBlock = $`;
+ }
+ if ($atBottom ne "") {
+ $atBottom = "% UNMOVED\n$atBottom";
+ }
+
+ if ($classDocBlock ne "") {
+ # If the class documentation is already printed,
+ # the empty string will be received and we won't enter
+ # here.
+
+ # Find the insertion point of the classDoc block.
+ # We find the beginning of the first line containing
+ # an uncommented class keyword. If that cannot be found,
+ # for instance in a C program, 0 will be kept.
+ # The class declaration line is recognized by its keyword
+ # class or interface not preceeded by any end-of-line
+ # or comment characters.
+ my $docPos = 0;
+ $docPos = pos ($codeBlock) - length ($&)
+ if $codeBlock =~ /^[^\*\/\n]*?(?:class|interface)/mg;
+
+ # The first code block can also specify a package name
+ # which must be taken into account for proper placement
+ # of generated images, if any.
+ if ($codeBlock =~ /^[^\*\/\n]*?package\s*(.*?);/m) {
+ my $packageName = $1;
+ # Convert the package name into a path.
+ # We must replace the periods with the platform-specific
+ # path delimiter.
+ my @packageParts = split /\./, $packageName;
+ $htmlOutDir = File::Spec->catdir ($htmlOutDir, @packageParts);
+ }
+
+ # Insert the class documentation into the code block
+ if ($docPos <= $insPos) {
+ push @blockList, substr ($codeBlock, 0, $docPos);
+ push @blockList, $classDocBlock;
+ push @commentIndices, $#blockList;
+ $classDocIndex = $#blockList;
+ if ($textBlock ne "") {
+ push @blockList, substr ($codeBlock, $docPos, $insPos - $docPos);
+ push @blockList, $textBlock;
+ push @commentIndices, $#blockList;
+ push @blockList, substr ($codeBlock, $insPos);
+ }
+ else {
+ push @blockList, substr ($codeBlock, $docPos);
+ }
+ }
+ else {
+ if ($textBlock ne "") {
+ push @blockList, substr ($codeBlock, 0, $insPos);
+ push @blockList, $textBlock;
+ push @commentIndices, $#blockList;
+ push @blockList, substr ($codeBlock, $insPos, $docPos - $insPos);
+ }
+ else {
+ push @blockList, substr ($codeBlock, 0, $docPos);
+ }
+ push @blockList, $classDocBlock;
+ push @commentIndices, $#blockList;
+ $classDocIndex = $#blockList;
+ push @blockList, substr ($codeBlock, $docPos);
+ }
+ }
+ else {
+ if ($textBlock ne "") {
+ push @blockList, substr ($codeBlock, 0, $insPos);
+ push @blockList, $textBlock;
+ push @commentIndices, $#blockList;
+ push @blockList, substr ($codeBlock, $insPos);
+ }
+ else {
+ push @blockList, $codeBlock;
+ }
+ }
+ if ($atBottom ne "") {
+ push @blockList, $atBottom;
+ push @commentIndices, $#blockList;
+ }
+}
+
+sub processTextBlock {
+ # Format the text block to get Java comments
+ # If isClassDoc is nonzero, less indentation is made
+ # for the comments.
+
+ my ($latexBlock, $htmlBlock, $isClassDoc) = @_;
+ my $latexonly = 0;
+
+ # Remove the uselesse <P> tags at beginning and end of the block
+ $htmlBlock =~ s/^(\s*<P>|\s*<[BH]R>)*//gio;
+ $htmlBlock =~ s/(<P>\s*|<[BH]R>\s*)*$//gio;
+
+ # If the LaTeX block was empty, we insert no comments
+ # at all.
+ return "" if $latexBlock =~ /^\s*(% UNMOVED)?\s*$/;
+ return "" if !$html && !$savelatex;
+
+ # Normally, a sectioning block of text documents no
+ # functions. If that happens, a dot is used to prevent
+ # the insertion of HTML comments into the brief.
+ $latexonly = 1
+ if $latexBlock =~ /(\\(sub)*section\*?|\\guisec)(?![a-zA-Z])/;
+
+ # Since comments disturb Javadoc if they appear inside the
+ # brief, the best way to avoid problems is by removing
+ # them completely. However, we must keep the LaTeX contents
+ # inside HTML comments.
+ $htmlBlock =~ s/<!--[\s\S]*?-->//g;
+
+ # We isolate the brief and check that there are no
+ # tables or div in it.
+ my $brief = $htmlBlock =~ /^([^.]*)\./ ? $1 : $htmlBlock;
+ $htmlBlock = ".\n$htmlBlock" if $brief =~ /<DIV|<TABLE|IMG/i;
+
+ $latexBlock = "" if !$savelatex;
+
+ # We must not have an HTML comment ending inside the
+ # LaTeX-only block, --{}> will output the same as -->
+ # in LaTeX, without the confusion to HTML.
+ # */ must also be transformed to prevent
+ # an incorrect comment ending, even in the HTML file.
+ $latexBlock =~ s/<!--/<!{}--/g;
+ $latexBlock =~ s/-->/--{}>/g;
+ $latexBlock =~ s/\*\//\*{}\//g;
+ $htmlBlock =~ s/\*\//\*<!-- -->\//g;
+
+ # When Java reads \u, it expects to get a unicode
+ # character. Unfortunately, some LaTeX commands
+ # start by \u. They will get replaced by \@u.
+ # \@u already in the document will become \@ u, which
+ # is normally equivalent since @ is a non-letter.
+ $latexBlock =~ s/\\@([uU])/\\@ \1/g;
+ $latexBlock =~ s/\\([uU])/\\@\1/g;
+
+ # Now we are ready to return a formatted block
+ # We must avoid HTML comments into the brief or
+ # Javadoc will not format the documentation properly.
+ $latexonly = 1 if $htmlBlock =~ /^(\s|<P>|<BR>)*$/i;
+ my $blk = $latexonly ? "" : $htmlBlock;
+ if ($latexBlock =~ /\S/) {
+ $blk .= "<!--LATEX\n" if !$latexonly;
+ $blk .= $latexBlock;
+ $blk .= "-->" if !$latexonly;
+ $blk .= "\n";
+ }
+
+ # Comment the Javadoc HTML code inside the output code.
+ # Something is inserted only if the converted
+ # text block contains at least one non-blank line.
+ if ($blk =~ /\S/) {
+ $blk =~ s/^\s+//;
+ if ($isClassDoc) {
+ $blk = $latexonly ? "/*LATEX\n$blk" : "/**\n$blk";
+ $blk =~ s/\n(?=.)/\n * /gs;
+ $blk .= " */\n";
+ }
+ else {
+ $blk = $latexonly ? " /*LATEX\n$blk" : " /**\n$blk";
+ $blk =~ s/\n(?=.)/\n * /gs;
+ $blk .= " */\n";
+ }
+ }
+ return $blk;
+}
+
+sub latexToHtml {
+ # Gathers all the text blocks into a single LaTeX document
+ # and pass them to LaTeX2HTML.
+ # Using a temporary directory avoids garbage created by
+ # LaTeX2HTML to appear into the html subdirectory.
+
+ @convertedComments = ();
+
+ my $texFile = "";
+
+ # Gather and merge the comments to form the core of the TeX file.
+ for (my $i = 0; $i < @commentIndices; $i++) {
+ my $ind = $commentIndices[$i];
+
+ # Some commands need to be converted to environments in order
+ # for LaTeX2HTML to treat them properly.
+ # These changes have an impact on the LaTeX contents
+ # printed into the Javadoc comments, so it will remain
+ # when reverting to LaTeX.
+ $blockList[$ind] =~ s/\s*\\(tab+)\s*(?![a-zA-Z])/\n\\begin\{$1\}\n/g;
+ $blockList[$ind] =~ s/\s*\\end(tab+)\s*(?![a-zA-Z])/\n\\end\{$1\}\n/g;
+ $blockList[$ind] =~ s/\s*\\vcode\s*(?![a-zA-Z])/\n\\begin\{vcode\}\n/g;
+ $blockList[$ind] =~ s/\s*\\endvcode\s*(?![a-zA-Z])/\n\\end\{vcode\}\n/g;
+ $blockList[$ind] =~ s/\s*\\ifdetailed([^a-zA-Z][\s\S]*?)\s*\\fi\s*/
+ \n\\begin{detailed}$1\n\\end{detailed}\n/g;
+
+ # Some modifications must not have impact on the LaTeX contents
+ # printed into comments and stay local to documentation
+ # blocks to prevent an error from altering all the contents
+ # and markers delimiting the blocks.
+ my $blk = $blockList[$ind];
+ $blk =~ s/\\iffalse[^a-zA-Z][\s\S]*?\\fi//g;
+
+ # The extra begin and end hides that we added during block
+ # parsing are converted to real hide environments
+ # instructions whereas they are removed in the LaTeX
+ # contents intended for appearing in the Javadoc.
+ # This does not work anymore since blocks are sometimes splitted
+ # a second time
+ # $blk =~ s/\\(begin|end)\{\@hide\}/\\$1\{hide\}/g;
+ # $blockList[$ind] =~ s/\\(begin|end)\{\@hide\}//g;
+
+ # Track all beginnings and endings of hide environment.
+ # To ensure proper processing by LaTeX2HTML, the hide
+ # environments must be balanced in each individual
+ # block of text.
+ my $hideCount = 0;
+ while ($blk =~ /\\((begin|end))\{hide\}/g) {
+ my $b = $1;
+ if ($b eq "begin") {
+ $hideCount++;
+ }
+ else {
+ $hideCount--;
+ }
+ }
+ if ($hideCount > 0) {
+ for (my $i = 0; $i < $hideCount; $i++) {
+ $blk .= "\n\\end{hide}";
+ }
+ }
+ elsif ($hideCount < 0) {
+ for (my $i = 0; $i < -$hideCount; $i++) {
+ $blk = "\\begin{hide}\n$blk";
+ }
+ }
+
+ # Same issue for detailed environment
+ my $detailedCount = 0;
+ while ($blk =~ /\\((begin|end))\{detailed\}/g) {
+ my $b = $1;
+ if ($b eq "begin") {
+ $detailedCount++;
+ }
+ else {
+ $detailedCount--;
+ }
+ }
+ if ($detailedCount > 0) {
+ for (my $i = 0; $i < $detailedCount; $i++) {
+ $blk .= "\n\\end{detailed}";
+ }
+ }
+ elsif ($detailedCount < 0) {
+ for (my $i = 0; $i < -$detailedCount; $i++) {
+ $blk = "\\begin{detailed}\n$blk";
+ }
+ }
+
+ # Append the block with a special marker.
+ $texFile .= "\\begin{rawhtml}\n<!--TEXJAVA:$ind -->\n" .
+ "\\end{rawhtml}\n$blk\n";
+ }
+
+ # LaTeX2HTML has difficulty when handling user-defined commands.
+ # Some cannot be easily implemented into the Perl language during
+ # the processing. This is mainly due to the complexity
+ # of LaTeX2HTML and lack of documentation about its
+ # its internal processing.
+ $texFile =~ s/\\eq(?![a-zA-Z])/\\[/g;
+ $texFile =~ s/\\endeq(?![a-zA-Z])/\\]/g;
+ $texFile =~ s/\\eqs(?![a-zA-Z])/\\begin{eqnarray*}/g;
+ $texFile =~ s/\\endeqs(?![a-zA-Z])/\\end{eqnarray*}/g;
+ $texFile =~ s/\\eqsn(?![a-zA-Z])/\\begin{eqnarray*}/g;
+ $texFile =~ s/\\endeqsn(?![a-zA-Z])/\\end{eqnarray*}/g;
+ $texFile =~ s/\\(begin|end)\s*\{\s*equation\s*\}/\\$1\{displaymath\}/g;
+ $texFile =~ s/\\(begin|end)\s*\{\s*eqnarray\s*\}/\\$1\{eqnarray*\}/g;
+
+ $texFile =~ s/\\left\.?(?![a-zA-Z])//g;
+ $texFile =~ s/\\right\.?(?![a-zA-Z])//g;
+ $texFile =~ s/\\mathcal(?![a-zA-Z])//g;
+
+ $texFile =~ s/\\min(?![a-zA-Z])/\\htmin/g;
+ $texFile =~ s/\\max(?![a-zA-Z])/\\htmax/g;
+ $texFile =~ s/\\inf(?![a-zA-Z])/\\htinf/g;
+ $texFile =~ s/\\sup(?![a-zA-Z])/\\htsup/g;
+ $texFile =~ s/\\int(?![a-zA-Z])/\\htint/g;
+ $texFile =~ s/\\sum(?![a-zA-Z])/\\htsum/g;
+ $texFile =~ s/\\prod(?![a-zA-Z])/\\htprod/g;
+ $texFile =~ s/\\lim(?![a-zA-Z])/\\htlim/g;
+ # References in parentheses are common (e.g. equation numbers)
+ # and L2H will only ignore the \ref command, leaving () in HTML!
+ $texFile =~ s/\s*\(\\ref\{.*?\}\)//g;
+ # A similar problem happens with \cite. Discarding \cite
+ # can leave spaces before a word and the sentence-ending period.
+ $texFile =~ s/\s*\\cite(?![a-zA-Z])/\\cite/g;
+
+ # The \unmoved command is useless and can even disturb LaTeX2HTML
+ # in some cases. So we must remove it from the TeX file passed to L2H.
+ $texFile =~ s/\\unmoved(?![a-zA-Z])//g;
+
+ # The created TeX file will have the same name as the input file
+ # less the .tex extension.
+ my $prefix = $ARGV[0];
+ $prefix =~ s/\.tex$//i;
+ my($vol,$dir,$fn) = File::Spec->splitpath ($prefix);
+ $prefix = $fn;
+
+ my $texFileName = File::Spec->catfile ($tempDir, "$prefix.tex");
+
+ # Since LaTeX2HTML needs a file, we must create a
+ # standalone LaTeX document.
+ open (TEXFILE, ">$texFileName") or die "cannot create $texFileName";
+ my $selfMaster = $preamble eq "";
+ if (!$selfMaster) {
+ print TEXFILE $preamble;
+ print TEXFILE "\n\\begin{document}\n";
+ }
+ print TEXFILE $texFile;
+ if (!$selfMaster) {
+ print TEXFILE "\n\\end{document}\n";
+ }
+ close TEXFILE;
+
+ # Construct a command line and call LaTeX2HTML
+ my $cmdLine = "latex2html -split 0 -link 0 -nonavigation -nofootnode " .
+ "-prefix $prefix -nosubdir -nomath -tmp \"$tempDir\" " .
+ "-noinfo -noauto_link -noaddress " .
+ ($images ? "-white " : "-nolatex -noimages ") .
+ "-html_version 4.1,math,unicode \"$texFileName\"";
+ # We cd to the directory where the TeX file is to allow
+ # L2H to find .aux files.
+ chdir ($texDir);
+ system ($cmdLine) == 0 or
+ die "could not execute latex2html successfully";
+ chdir ($oldCurDir);
+
+ # Now, we have a bunch of files created by LaTeX2HTML.
+ # Since splitting is disabled, we should have only one
+ # HTML file but some images may have been created.
+ # We need to get back the HTML contents but also
+ # to copy the images.
+ opendir (TMPDIR, $tempDir) or die "cannot open directory $tempDir";
+ my $fn = readdir (TMPDIR);
+ my $htmlFile = undef;
+ while (defined ($fn)) {
+ next if $fn eq "." || $fn eq "..";
+ my $ffn = File::Spec->catfile ($tempDir, $fn);
+ next if -d ($ffn) || !-r ($ffn);
+ if (!defined ($htmlFile) &&
+ $ffn =~ /\.html?$/) {
+ # The found file is readable, have an HTML extension
+ # and no HTML file were previously found.
+ # There should be only one HTML file
+ open HTML, $ffn or die "cannot open $ffn";
+ $htmlFile = join ("", <HTML>); # Reads the file in one step
+ close HTML;
+ $htmlFile =~ s/<BODY.*?>(.*)<\/BODY>//is; # Only keep the body
+ $htmlFile = $1;
+ # Current browsers don't display { and }
+ # properly and LaTeX2HTML outputs these sequences
+ # when the Unicode extension is activated.
+ $htmlFile =~ s/{/\{/g;
+ $htmlFile =~ s/}/\}/g;
+ # Sometimes, latex2html with the math extension
+ # creates bad constructs such as &alpha#alpha;.
+ # Only keep α.
+ $htmlFile =~ s/&([a-zA-Z]+)\#.*?;/&\1;/g;
+ # Some versions of LaTeX2HTML write mathend at each math expression.
+ # The marker appears when the LaTeX file has some complications like
+ # multine section titles, and maybe other multine commands!
+ $htmlFile =~ s/\n?<tex2html_verbatim_mark>mathend000\#//g;
+ }
+ elsif ($images && $ffn =~ /\.(png|gif)$/) {
+ # The found file is readable and is a GIF or PNG image.
+ # All the images will simply be copied into the
+ # html subdir of the outdir.
+ open IMGIN, $ffn or die "cannot open $fn";
+ open IMGOUT, ">" . File::Spec->catfile ($htmlOutDir, $fn)
+ or die "cannot create $fn";
+ print IMGOUT join ("", <IMGIN>);
+ close IMGOUT;
+ close IMGIN;
+ }
+ } continue {
+ $fn = readdir (TMPDIR);
+ }
+ closedir TMPDIR;
+ # This should never happen
+ die "could not find the HTML output file" if !defined ($htmlFile);
+
+ # Now, we have the converted LaTeX into the htmlFile variable.
+ # We must split its contents and put the parts into corresponding
+ # comment blocks.
+ my @htmlFileParts = split /(<!--TEXJAVA:\d+\s*-->)/, $htmlFile;
+ my $currentInd = -1;
+ foreach my $sbl (@htmlFileParts) {
+ if ($sbl =~ /^<!--TEXJAVA:(\d+)\s*-->$/) {
+ $currentInd = $1;
+ }
+ elsif ($currentInd != -1 ||
+ ($selfMaster && @htmlFileParts == 1)) {
+ $currentInd = 0 if $currentInd == -1;
+ # Sometimes, converted LaTeX blocks contain images
+ # with alternative text containing LaTeX code.
+ # We will assume that \u is never used in the converted
+ # HTML, see processTextBlock for more information
+ # about this thrick.
+ $sbl =~ s/\\([uU])/\\@ \1/g;
+ $convertedComments[$currentInd] .= $sbl;
+ }
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/tcode.git
More information about the pkg-java-commits
mailing list