[XeTeX] changing output filename from the source

Ulrike Fischer news3 at nililand.de
Tue Jan 5 10:13:59 CET 2010


Am Tue, 5 Jan 2010 14:31:22 +1030 schrieb Will Robertson:


>>> How can I set the \jobname from within the TeX source?
>> 
>> 	\def\jobname{And now to something completely different!} ?
> 
> This is the way, but unfortunately only the aux files and so on will 
> use the new name. The name of the PDF file is (AFAIK) fixed when *TeX 
> is invoked.
> 
> The only possibility is
> 
>     xetex -jobname=bar foo.tex
> 
> but this cannot be done, obviously, within the TeX run.

With --shell-escape enabled you can call pdflatex again from the
document. Ulrich Diez sent this code some months ago in c.t.t.. It
will generate the files \jobname1.pdf to \jobname3.pdf. If you
remove the line with \expandafter\stop \jobname.pdf is generated too
(then you need the line with \def\conditionmacro to avoid errors).
It seems to works fine (I also tested it with xelatex). 

\documentclass{article}

\ifx\conditionmacro\undefined
  %\def\conditionmacro{0}
  \immediate\write18{%
    pdfLaTeX --jobname="\jobname1"
    \gdef\string\conditionmacro{1}\string\input\space\jobname
  }%
  \immediate\write18{%
    pdfLaTeX --jobname="\jobname2"
    \gdef\string\conditionmacro{2}\string\input\space\jobname
  }%
  \immediate\write18{%
    pdfLaTeX --jobname="\jobname3"
    \gdef\string\conditionmacro{3}\string\input\space\jobname
  }%
  \expandafter\stop
\fi

\begin{document}
\ifnum\conditionmacro=1 Condition is 1\fi
\ifnum\conditionmacro=2 Condition is 2\fi
\ifnum\conditionmacro=3 Condition is 3\fi

\verb|\conditionmacro| is \texttt{\meaning\conditionmacro}.
\end{document}

-- 
Ulrike Fischer 



More information about the XeTeX mailing list