2
\$\begingroup\$

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>
\$\endgroup\$
2
  • \$\begingroup\$ Can’t comment specifically on the ant file but it seems like a lot of effort. Are you aware of the existence of latexmk which ships with all modern TeX distributions and which is a versatile build tool for TeX (requiring in most cases zero configuration)? \$\endgroup\$ Commented Jul 19, 2012 at 19:11
  • \$\begingroup\$ @KonradRudolph: Yes. But I need it on Windows, MacOS and Linux. And I fear that the configuration latexmk needs for this build process and the dependencies is also quite non-trivial. And I wanted to learn ant. :-) \$\endgroup\$ Commented Jul 19, 2012 at 20:17

1 Answer 1

2
\$\begingroup\$

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:

  1. <attribute name="basename" default="unknown" />
    

    Are you sure that you need the default attribute here? The macrodef documentation says the following:

    The attributes will be required attributes unless a default value has been set.

  2. 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?

  3. 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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Thanks; I've added a new version with macrodef to the question. \$\endgroup\$ Commented Jul 18, 2012 at 14:41
  • \$\begingroup\$ @MartinSchröder: Thanks for the feedback! I've updated the answer. \$\endgroup\$
    – palacsint
    Commented Jul 18, 2012 at 18:20
  • \$\begingroup\$ Thanks. I've updated the question with a new version with union and srcresources. That seems to be an area that's severly underdocumented in the online manual. :-( \$\endgroup\$ Commented Jul 19, 2012 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.