6

Let's assume my document is called test.tex. Instead of creating a test.pdf I would like to add a suffix date stamp to the filename, e.g. test_2013_05_29 (test_yyyy_mm_dd). I am compiling with pdfLaTeX and I would like this to work both on Windows and on Mac.

alfC
  • 14,350
Max
  • 421
  • Can't do it, I'm told. See http://tex.stackexchange.com/questions/19182/how-to-influence-the-name-of-the-pdf-file-created-with-pdflatex-from-within-the – Steven B. Segletes May 29 '13 at 19:45
  • That said, you can add the datestamp to the file contents, with the command \today (I often place it in a header) – Steven B. Segletes May 29 '13 at 19:49
  • Oops. My earlier response refers to changing the name from within TeX. I hadn't considered the name change during invocation, as shown in the answer of alfC. Of course, if external renaming is allowed, then just renaming the output following traditional compilation should apply under any operating system. – Steven B. Segletes May 29 '13 at 19:53
  • @StevenB.Segletes, good point anyway. Also, I am giving an answer that the OP may need to "test" in Windows, I am not sure how portable it is. – alfC May 29 '13 at 19:54

2 Answers2

9

Use the -jobname option (the order is important):

pdflatex -jobname=testDATE test.tex

(I am not sure how distribution-dependent this is, I am using This is pdfTeX, Version 3.1415926-2.5-1.40.13 (TeX Live 2013/dev))

Also, in GNU/Linux-like system you can make this automatic from the command line as

pdflatex -jobname=test_`date +%Y_%m_%d` test.tex

(not sure if the date command works in the same way in Mac)

This solution is not perfect with respect to the compilation process, since auxiliary files will be labeled in the same way, so compilation will be "discontinuous" across days, which may not be serious. I think it may be safer to do (the good old) change of name after compilation if you can, for example in GNU/Linux:

pdflatex test.tex && mv/cp test.pdf test_`date +%Y_%m_%d`.pdf
alfC
  • 14,350
2

There's a package varsfromjobname, that allows you to extract certain parts from the name of the document.

Find it under http://www.ctan.org/tex-archive/macros/latex/contrib/varsfromjobname

Uwe Ziegenhagen
  • 13,168
  • 5
  • 53
  • 93