In developing documentation for software a new version of .tex files are made as the software is developed. I'd like to be able to build the corresponding pdf's without hard-coding the name of the .tex file every time a new version is made. Is there any way to do this directly? I haven't found any documentation on this possibility, such as passing a variable set to the file name into the pdflatex command.

As an example: I have a source .tex file named myfile_v1.0.tex in the directory I'm currently working in. In the future, a file named myfile_v1.1.tex will replace the previous version .tex file so that an updated pdf for the new software documentation can be built. I'd like to be able to build the pdf's from the source .tex file, no matter the name of the source .tex file, since it will be changing consistently.


You could set the \jobname variable via the compiler's command line option -jobname like this:

pdflatex -jobname mydoc-2019-07-11 mydoc.tex

where mydoc.tex is your input file and mydoc-2019-07-11.pdf would be the produced output file.

From within the .tex file you can also access the file name by \jobname which would expand in this case to mydoc-2019-07-11.

  • It is my understanding that -jobname will only alter the output name for the pdf that is built, so I don't think that this is what I would need, right? I've updated my post with an example that might make what I meant more clear, sorry for any confusion. Thanks for your help! – Halkaz00 Jul 11 '19 at 20:00
  • I'm not sure I understand your updated question correctly, but in this case it seems you would just go the opposite way, i.e. pdflatex -jobname mydoc mydoc_ver1.1.tex – siracusa Jul 11 '19 at 20:22

This link describes exactly what I needed to do to implement my script as I wanted to.


Using a combination of the accepted answer and the highest voted answer gave me the answer I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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