Here is an ant script for generating TeX code and documentation for one LaTeX class and one LaTeX package. It is my first larger ant script: I welcome suggestions for improvements.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="customer TeX code" default="main">
<description>Buildscript for the LaTeX classes and packages</description>
<property name="foo" value="foo" />
<property name="bar" value="bar" />
<!-- target: init -->
<target name="init" description="initialize properties">
<condition property="foo.uptodate">
<and>
<available file="${foo}.cls" />
<available file="${foo}.drv" />
<available file="${foo}.pdf" />
<uptodate property="foo.cls.uptodate" targetfile="${foo}.cls">
<srcfiles file="${foo}.dtx" />
<srcfiles file="${foo}.ins" />
</uptodate>
<uptodate property="foo.drv.uptodate" targetfile="${foo}.drv">
<srcfiles file="${foo}.dtx" />
<srcfiles file="${foo}.ins" />
</uptodate>
<uptodate property="foo.pdf.uptodate" targetfile="${foo}.pdf">
<srcfiles file="${foo}.dtx" />
<srcfiles file="${foo}.ins" />
</uptodate>
</and>
</condition>
<condition property="bar.uptodate">
<and>
<available file="${bar}.sty" />
<available file="${bar}.drv" />
<available file="${bar}.pdf" />
<uptodate property="bar.sty.uptodate" targetfile="${bar}.sty">
<srcfiles file="${bar}.dtx" />
<srcfiles file="${bar}.ins" />
</uptodate>
<uptodate property="bar.drv.uptodate" targetfile="${bar}.drv">
<srcfiles file="${bar}.dtx" />
<srcfiles file="${bar}.ins" />
</uptodate>
<uptodate property="bar.pdf.uptodate" targetfile="${bar}.pdf">
<srcfiles file="${bar}.dtx" />
<srcfiles file="${bar}.ins" />
</uptodate>
</and>
</condition>
</target>
<!-- target: foo -->
<target name="foo" unless="foo.uptodate" depends="init" description="builds all files for the foo class">
<exec executable="latex" failonerror="true">
<arg value="${foo}.ins" />
</exec>
<exec executable="lualatex" failonerror="true">
<arg value="-draftmode" />
<arg value="${foo}.drv" />
</exec>
<parallel>
<exec executable="makeindex" failonerror="true">
<arg value="-s" />
<arg value="gind.ist" />
<arg value="-t" />
<arg value="${foo}.ind.ilg" />
<arg value="${foo}.idx" />
</exec>
<exec executable="makeindex" failonerror="true">
<arg value="-s" />
<arg value="gglo.ist" />
<arg value="-t" />
<arg value="${foo}.gls.ilg" />
<arg value="-o" />
<arg value="${foo}.gls" />
<arg value="${foo}.glo" />
</exec>
</parallel>
<exec executable="lualatex" failonerror="true">
<arg value="-draftmode" />
<arg value="${foo}.drv" />
</exec>
<exec executable="lualatex" failonerror="true">
<arg value="${foo}.drv" />
</exec>
</target>
<!-- target: bar -->
<target name="bar" unless="bar.uptodate" depends="init" description="builds all files for the bar package">
<exec executable="latex" failonerror="true">
<arg value="${bar}.ins" />
</exec>
<exec executable="lualatex" failonerror="true">
<arg value="-draftmode" />
<arg value="${bar}.drv" />
</exec>
<parallel>
<exec executable="makeindex" failonerror="true">
<arg value="-s" />
<arg value="gind.ist" />
<arg value="-t" />
<arg value="${bar}.ind.ilg" />
<arg value="${bar}.idx" />
</exec>
<exec executable="makeindex" failonerror="true">
<arg value="-s" />
<arg value="gglo.ist" />
<arg value="-t" />
<arg value="${bar}.gls.ilg" />
<arg value="-o" />
<arg value="${bar}.gls" />
<arg value="${bar}.glo" />
</exec>
</parallel>
<exec executable="lualatex" failonerror="true">
<arg value="-draftmode" />
<arg value="${bar}.drv" />
</exec>
<exec executable="lualatex" failonerror="true">
<arg value="${bar}.drv" />
</exec>
</target>
<!-- target: main -->
<target name="main" depends="foo, bar" description="default target" />
</project>
1 Answer 1
The bar
and foo
targets (as well as the conditions on foo.uptodate
and bar.uptodate
) seems really similar to each other. I'd try to remove this duplication with a presetdef
or a macrodef
Reply for the edit:
Nice to see that the macrodef
works :-). A few other ideas:
-
<attribute name="basename" default="unknown" />
Are you sure that you need the
default
attribute here? Themacrodef
documentation says the following:The attributes will be required attributes unless a default value has been set.
I'd create a list for
<srcfiles file="@{basename}.dtx" /> <srcfiles file="@{basename}.ins" />
Here is an example: Ant: using Filelist as Fileset in Uptodate?
After this I guess the three
uptodate
tag could be replaced with only one which uses a composite or a chained mapper but I'm not too familiar with these.
-
1\$\begingroup\$ Thanks; I've added a new version with
macrodef
to the question. \$\endgroup\$Martin Schröder– Martin Schröder2012年07月18日 14:41:57 +00:00Commented Jul 18, 2012 at 14:41 -
\$\begingroup\$ @MartinSchröder: Thanks for the feedback! I've updated the answer. \$\endgroup\$palacsint– palacsint2012年07月18日 18:20:08 +00:00Commented Jul 18, 2012 at 18:20
-
\$\begingroup\$ Thanks. I've updated the question with a new version with
union
andsrcresources
. That seems to be an area that's severly underdocumented in the online manual.:-(
\$\endgroup\$Martin Schröder– Martin Schröder2012年07月19日 10:05:04 +00:00Commented Jul 19, 2012 at 10:05
latexmk
which ships with all modern TeX distributions and which is a versatile build tool for TeX (requiring in most cases zero configuration)? \$\endgroup\$:-)
\$\endgroup\$