TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How to influence the name of the pdf file created with pdfLaTeX (from within the source code)?

I have a template as follows.

% template.tex

    % if it is compiled with latex.exe, it will produce DVI output with \InputFileName as its name.
    % if it is compiled with pdflatex.exe or xelatex.exe, it will produce PDF output with \InputFileName as its name.
    % notify error!

If I execute either TeXDviPsPdf.bat subfile or TeXPdf.bat subfile in the DOS prompt,

rem TeXDviPsPdf.bat takes a file name without extension
latex "\def\InputFileName{%1}\input{template}"
dvips %1.dvi
ps2pdf %1.ps
acrord32 %1.pdf
rem TeXPdf.bat takes a file name without extension
xelatex "\def\InputFileName{%1}\input{template}"
acrord32 %1.pdf

where the subfile.tex contains code as follows

% subfile.tex

I will obtain subfile.pdf rather than template.pdf.

Is it possible to produce a DVI or PDF output with a name specified in the TeX input file?

Note: I can actually rename it in the batch files, but I want to know whether it is possible to be done internally.

share|improve this question

marked as duplicate by Lev Bishop, lockstep, Alan Munn, Seamus, Martin Scharrer Aug 3 '11 at 19:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

What's the sense of \InputIfFileExists{\input{...}}{}? The command has three arguments and the first should be a file name. Please, correct the example. – egreg Jul 31 '11 at 19:44
+1 @egreg: Thanks for checking the code. It has been corrected. – xport Jul 31 '11 at 20:04
It's still wrong: why input the file twice? The file is input if it exists; the second argument contains code to be executed before inputting the file. – egreg Jul 31 '11 at 20:13
@egreg: DONE. :-) – xport Jul 31 '11 at 20:21
up vote 5 down vote accepted

From within latex is not possible, try

latex --jobname=%1 "\def\InputFileName{%1}\input{template}"
share|improve this answer
+1 but I want to change it internally. – xport Jul 31 '11 at 20:15
from within latex is not possible – Herbert Jul 31 '11 at 20:23
+1 Accepted. Thanks. – xport Jul 31 '11 at 20:27

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