3

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
\documentclass{article}
\usepackage{pstricks}
\SpecialCoor
\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{0pt}
\PreviewEnvironment{pspicture}

\begin{document}
\InputIfFileExists{\InputFileName}{%
    % 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!
}   
\end{document}

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
\input{pstricks}
\begin{pspicture}(1,1)
\psframe(1,1)
\end{pspicture}

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.

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.

  • 2
    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
6

From within latex is not possible, try

latex --jobname=%1 "\def\InputFileName{%1}\input{template}"
  • 1
    +1 but I want to change it internally. – xport Jul 31 '11 at 20:15
  • 4
    from within latex is not possible – user2478 Jul 31 '11 at 20:23

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