August 2, 2020
Over the course of several steps, a pair of Haskell
programs were developed to allow using the LaTeX commands \ref and \pageref
within Java comments to refer to external LaTeX documents. This page describes how to use these
two programs without discussing how they work internally – although they must be compiled
before they can be used. They compile as vanilla Haskell or the Windows executables are
available on github.
The first program pulls LaTeX \label references out of
.aux files. Save the Haskell source to getaux.hs,
and compile it. The compiled executable requires two arguments: the "aux database" file
name and the name of a LaTeX .aux file. The program extracts all of the
\label references from the given .aux file and adds them to the
given database file. So getaux can be used to aggregate the \label
values from multiple .aux files.
The "aux database" is nothing more than a simple flat file. The first time you run
getaux, you will need to create an empty file. The program will not create
a new file.
The second program uses the \label values stored
by getaux to allow \ref and \pageref to be
used in Java comments. Store the Haskell source code to replabels.hs and
compile it. The program takes two arguments: the name of an aux database file (generated
by getaux), and the name of a .java file. It replaces every
instance of \ref and \pageref with the corresponding label
value, and sends the result to stdout.
Since understanding the basics of LaTeX is a prerequisite to using these programs, there's
no point in belaboring the details. Both \ref and \pageref can be
used in Java comments, just as they would be from LaTeX source. In addition, replabels
accepts the \verb command, which also works as expected.