I'm hoping there's something along the lines of:
\renewcommand{\outputfilename}{outfilename}
I know I can do
pdflatex -jobname="outfilename" filename.tex
but unless I can automate this, it's no better than renaming the output
after generating it.
I'm happy to use latexmk if that helps.
I would think it is easiest to simply rename after pdflatex, the output
file if more or less opened when LaTeX starts compiling, so changing it
from within the document is useless.
latexmk does know the -jobname option (latexmk --help)
/daleif
In case \write18 is enabled, you can do something like
------------------- begin of minimal example -------------------
\newcommand{\outputfilename}{outfilename} %%
\RequirePackage{ifpdf}
\csname @ifundefined\endcsname{savedjobname}{%
\immediate\write18{%
\ifpdf pdf\fi latex -jobname=\outputfilename\space
\global\let\string\savedjobname\string\jobname
\gdef\string\jobname{\jobname}%
\string\input\space\jobname.tex
}%
\stop
}{}%
%%
\documentclass{article}
% ...etc...
\begin{document}
% ...etc...
test test
% ...etc...
\end{document}
-------------------- end of minimal example --------------------
Ulrich
When I save this example as test.tex and run pdflatex on it, I get:
This is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010)
\write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang,
nohyphenation, ge
rman-x-2009-06-19, ngerman-x-2009-06-19, ancientgreek, ibycus, arabic,
armenian
, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danish,
dutch, u
kenglish, usenglishmax, esperanto, estonian, farsi, finnish, french,
galician,
german, ngerman, swissgerman, monogreek, greek, hungarian, icelandic,
assamese,
bengali, gujarati, hindi, kannada, malayalam, marathi, oriya, panjabi,
tamil,
telugu, indonesian, interlingua, irish, italian, kurmanji, lao, latin,
latvian,
lithuanian, mongolian, mongolianlmc, bokmal, nynorsk, polish,
portuguese, roma
nian, russian, sanskrit, serbian, slovak, slovenian, spanish, swedish,
turkish,
turkmen, ukrainian, uppersorbian, welsh, loaded.
(/usr/local/texlive/2010/texmf-dist/tex/generic/oberdiek/ifpdf.sty)This
is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010)
restricted \write18 enabled.
entering extended mode
! I can't find file `global'.
<*> global
let savedjobnamejobnamegdef jobname{test}input test.tex
(Press Enter to retry, or Control-D to exit)
Please type another input file name:
Does it actually compile for you?
It does.
But while you use TeX Live 2010, I tested under
MiKTeX 2.4 and MiKTeX 2.9 before posting.
Besides this I don't know what "restricted" in
"restricted \write18" might do to a \write18-call.
| restricted \write18 enabled.
| entering extended mode
What confuses me is that there are no backslashes
in the error-message
| ! I can't find file `global'.
| <*> global
| let savedjobnamejobnamegdef jobname{test}input test.tex
.
Another confusing aspect is that your TeX seems to
prompt <*> instead of <**> at the start of the TeX-run,
because TeXbook's Chapter 6 (Running TeX) clearly
states:
[..]
| You might wonder why the first prompt was '**', while the
| subsequent ones are'*'; the reason is simply that the first
| thing you type to TeX is slightly different from the rest:
| If the first character of your response to '**' is not a
| backslash, TeX automatically inserts '\input'. Thus you
| can usually run TeX by merely naming your input file.
| (Previous TeX systems required you to start by typing
| '\input story' instead of 'story', and you can still do that;
| but most TeX users prefer to put all their commands
| into a file instead of typing them online, so TeX now
| spares then the nuisance of starting out with \input each
| time.) Recall that in Experiment 1 you typed '\relax';
| that started with a backslash, so \input was not implied.
[..]
Are you sure that backslashes are written correctly to
console/shell with your TeX-distribution/platform and
read back correctly from the console/shell with your
TeX-distribution/platform and interpreted correctly?
Probably \escapechar is not 92 (backslash) with your
platform. In case the integer-parameter \escapechar
has e.g. a non-positive value, TeX won't write backslashes
when unexpanded writing names of control-sequences
(Due to \string, there is unexpanded writing of names of
control-sequences.) Probably there is some codepage-
issue with your console/shell?
When copy-pasting the example - did you ensure to have
displayed the posting in "original format"?
Probably you need to wrap the jobname in quotes.
So instead of
| -\jobname=\outputfilename\space
you could try
-\jobname="\outputfilename"\space
or
-\jobname=\string"\outputfilename\string"\space
:
------------------- begin of minimal example -------------------
\newcommand{\outputfilename}{outfilename} %%
\RequirePackage{ifpdf}
\csname @ifundefined\endcsname{savedjobname}{%
\immediate\write18{%
\ifpdf pdf\fi latex -jobname=\string"\outputfilename\string"\space
\relax\global\let\string\savedjobname\string\jobname
What you're saying sounds reasonable, but I don't have any
idea where to look in my TeX setup for what could be
controlling that. Wrapping the outputfilename in quotes
hardly changed the result. (Now it complains that relax
is an unknown command.)
Where do the complaints come from?
Do they come from TeX?
Or do they come from the shell/coonsole?
Ulrich
They come from TeX. Here's the output now:
! I can't find file `relax'.
<*> relax
> Probably you need to wrap the jobname in quotes.
>
> So instead of
> | -\jobname=\outputfilename\space
> you could try
> -\jobname="\outputfilename"\space
> or
> -\jobname=\string"\outputfilename\string"\space
Single quotes are the better choice, double quotes
do not stop the special interpretation of the backslash
in the shell command line (most shells in unix).
--
Heiko Oberdiek
> Single quotes are the better choice, double quotes
> do not stop the special interpretation of the backslash
> in the shell command line (most shells in unix).
Do you have a pointer where I can learn more about
that special interpretation of the backslash
in the shell command line of most shells in unix?
Ulrich
Manual pages of the shells, e.g.:
http://linux.die.net/man/1/bash
See section "Quoting".
--
Heiko Oberdiek
Thanks.
Ulrich
> They come from TeX. Here's the output now:
[...]
> ! I can't find file `relax'.
> <*> relax
Seems the shell removes the backslashes.
Heiko provided a link to the bash manpages
( http://linux.die.net/man/1/bash ) .
There you can read:
| Quoting
[...]
| There are three quoting mechanisms: the escape character,
| single quotes, and double quotes.
|
| A non-quoted backslash (\) is the escape character.
| It preserves the literal value of the next character that follows,
| with the exception of <newline>. If a \<newline> pair appears,
| and the backslash is not itself quoted, the \<newline> is
| treated as a line continuation (that is, it is removed from the
| input stream and effectively ignored).
|
| Enclosing characters in single quotes preserves the literal
| value of each character within the quotes. A single quote
| may not occur between single quotes, even when
| preceded by a backslash.
|
| Enclosing characters in double quotes preserves the literal
| value of all characters within the quotes, with the exception
| of $, ', \, and, when history expansion is enabled, !. The
| characters $ and ' retain their special meaning within
| double quotes. The backslash retains its special meaning
| only when followed by one of the following characters:
| $, ', ", \, or <newline>. A double quote may be quoted
| within double quotes by preceding it with a backslash.
| If enabled, history expansion will be performed unless
| an ! appearing in double quotes is escaped using a
| backslash. The backslash preceding the ! is not removed.
|
| The special parameters * and @ have special meaning
| when in double quotes (see PARAMETERS below).
|
| Words of the form $'string' are treated specially. The word
| expands to string, with backslash-escaped characters
| replaced as specified by the ANSI C standard.
| Backslash escape sequences, if present, are decoded as
| follows:
[...]
| \\ backslash
So you may need to double backslashes for your \write18-call:
Ulrich
------------------- begin of minimal example -------------------
\newcommand{\outputfilename}{outfilename} %%
\csname @ifundefined\endcsname{savedjobname}{%
\RequirePackage{ifpdf}%
%% For Unix-Shells:
\edef\bs{\csname @firstoftwo\expandafter\endcsname\string\ .}%
%% For MiKTeX / M$-Shell:
%\let\bs=\empty
\immediate\write18{%
\ifpdf pdf\fi latex -jobname=\string'\outputfilename\string'\space
\bs\relax\bs\global\bs\let\bs\string\savedjobname\bs\string\jobname
\bs\gdef\bs\string\jobname{\jobname}%
\bs\string\input\space\jobname.tex
> \edef\bs{\csname @firstoftwo\expandafter\endcsname\string\ .}%
\let\bs\@backslashchar % defined in LaTeX kernel
--
Heiko Oberdiek
Thanks for pointing out not a bug but a possibility for
optimization.
That means replacing the line
\edef\bs{\csname @firstoftwo\expandafter\endcsname\string\ .}%
by
\expandafter\let\expandafter\bs\csname @backslashchar\endcsname
(Some people fear \makeatletter.)
Sincerely
Ulrich