Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Specify name of output file

2,577 views
Skip to first unread message

Rox Smith

unread,
Nov 30, 2010, 5:28:27 PM11/30/10
to
Is it possible to specify the name of the generated pdf file from within
the latex file? in other words, I have a latex file, filename.tex, and
when I run
pdflatex filename.tex
I want the output to be
outfilename.pdf

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.

Lars Madsen

unread,
Nov 30, 2010, 5:48:19 PM11/30/10
to

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

Ulrich D i e z

unread,
Nov 30, 2010, 7:19:52 PM11/30/10
to
Rox Smith wrote:


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

Rox Smith

unread,
Dec 1, 2010, 11:30:03 PM12/1/10
to
On 11/30/10 5:19 PM, Ulrich D i e z wrote:
> 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?

Ulrich D i e z

unread,
Dec 2, 2010, 3:31:28 AM12/2/10
to
Rox Smith wrote:

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

Rox Smith

unread,
Dec 3, 2010, 6:52:00 PM12/3/10
to
On 12/2/10 1:31 AM, Ulrich D i e z wrote:
> 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
> :
>

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


Ulrich D i e z

unread,
Dec 4, 2010, 4:44:57 AM12/4/10
to
Rox Smith wrote:

Where do the complaints come from?
Do they come from TeX?
Or do they come from the shell/coonsole?

Ulrich

Rox Smith

unread,
Dec 4, 2010, 6:32:22 AM12/4/10
to
On 12/4/10 2:44 AM, Ulrich D i e z wrote:
>> > 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

Heiko Oberdiek

unread,
Dec 4, 2010, 6:56:22 AM12/4/10
to
Ulrich D i e z <eu_an...@web.de> wrote:

> 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

Ulrich D i e z

unread,
Dec 4, 2010, 11:10:55 AM12/4/10
to
Heiko Oberdiek wrote:

> 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

Heiko Oberdiek

unread,
Dec 4, 2010, 11:43:49 AM12/4/10
to
Ulrich D i e z <eu_an...@web.de> wrote:

Manual pages of the shells, e.g.:
http://linux.die.net/man/1/bash
See section "Quoting".

--
Heiko Oberdiek

Ulrich D i e z

unread,
Dec 4, 2010, 11:53:54 AM12/4/10
to
Heiko Oberdiek wrote:
.

Thanks.

Ulrich

Ulrich D i e z

unread,
Dec 4, 2010, 12:40:11 PM12/4/10
to
Rox Smith wrote:

> 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

Heiko Oberdiek

unread,
Dec 4, 2010, 1:05:47 PM12/4/10
to
Ulrich D i e z <eu_an...@web.de> wrote:

> \edef\bs{\csname @firstoftwo\expandafter\endcsname\string\ .}%

\let\bs\@backslashchar % defined in LaTeX kernel

--
Heiko Oberdiek

Ulrich D i e z

unread,
Dec 4, 2010, 1:02:18 PM12/4/10
to
Heiko Oberdiek wrote:
.

> Ulrich D i e z <eu_an...@web.de> wrote:
>
> > \edef\bs{\csname @firstoftwo\expandafter\endcsname\string\ .}%
>
> \let\bs\@backslashchar % defined in LaTeX kernel

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

0 new messages