transcript for Adding a macro to the -jobname section of the PDFLaTeX compiler (i.e., how to add dates to the PDF filename)
2020-06-25 05:14:45  joulev
I think you need more than `pdflatex` to do this. A bash script may be needed, for example.
2020-06-25 19:15:47  DDCanada
@samcarter, re: [your answer](#a1357), This worked really well, and you are the first person to be able to get the automated date to work in my Texmaker user command.  Thank you so much!
  
My only remaining question, now that I have successfully gotten your code to run and do almost everything I am looking for, is about **how I can include the "filename without extension" (denoted by the '%' symbol in Texmaker) to work with the "sh -c" script.** (I.e., clearly the double %% symbols before the date are  now operating as macros, rathe than "filename without extension.") What if I still want to call the original filename? Can I do that within the "sh -c" script, perhaps with some workaround that doesn't rely on the '%' symbol that Texmaker normally uses?
2020-06-25 19:17:32  DDCanada
Short question: Instead of ```document1.tex``` and ```--jobname=document1_$mydate``` ... can I somehow replace "document1" with the "filename without extension" (previously denoted by the '%' symbol)?
2020-06-25 21:07:51  samcarter  replying to  DDCanada
I did not quite manage to smuggle the file name into the command. The closest I got was   
```  
sh -c "mydate=$(/bin/date +'%%Y_%%m_%%d') ; pdflatex -interaction=nonstopmode --jobname=$0_$mydate $0.tex " %
```  
but unfortunatly  the % does not get expanded to the filename
2020-06-25 23:34:38  DDCanada
Thank you so much, @samcarter!! With your help, I got 95% of the way to my solution. (It just means that for each file, I will have to rewrite the filename output for the PDF document in the Texmaker user command, but that's not the end of the world.)  
 
In the end, I expanded your compilation script to include XeLaTeX, BibTeX, and XeLaTeX(x2)---which can also be used with PDFLaTeX or LuaLaTeX---so that I can compile documents that include references:
  
```sh -c "mydate=$(/bin/date +'%%Y_%%m_%%d') ; xelatex -synctex=1 -interaction=nonstopmode --jobname=New_Name_$mydate Original_Name.tex ; bibtex Original_Name.aux ; xelatex -synctex=1 -interaction=nonstopmode --jobname=New_Name_$mydate Original_Name.tex ; xelatex -synctex=1 -interaction=nonstopmode --jobname=New_Name_$mydate Original_Name.tex ; open New_Name_$mydate.pdf  "```   
  
I've also been able to add code that removes LaTeX's compilation files after the PDF has been created:  

```" ```[...]``` ;  rm -f New_Name_$mydate.log ; rm -f New_Name_$mydate.synctex.gz ; rm -f New_Name_$mydate.aux ; rm -f Original_Name.blg "```
2020-06-26 04:59:31  DDCanada
**Note for the sidebar chat:** I solved the remaining 5% of my issue, regarding the use of Texmaker's "filename without extension". I posted the solution as Answer #2 in the main window. Thanks for all of your help!
2020-06-26 05:19:03  Circumscribe  replying to  DDCanada
For large documents it is common to have a “master” document that includes a whole bunch of other documents (e.g. one for each chapter) that cannot be compiled by themselves. The distinction between `%` (master document) and `@` (current document) is relevant because you'll generally want to compile the master document instead of the current document.
2020-06-26 05:20:23  Circumscribe
It sounds like this is likely not relevant to your current use case, but you may run into this at some point.
2020-06-26 05:36:14  Circumscribe
(Sorry, I meant `#` instead of `@` before.)
2020-06-26 06:25:22  DDCanada
Ahh, that makes sense! Thank you! This will definitely be relevant for any multi-file documents, such as book chapters. For now, the ```#``` solution will suffice for single-file TeX documents. 
2020-06-26 07:37:30  samcarter  replying to  DDCanada
Great to see that you found a solution! In case you ever find out why # expands and % is not, please let me know!
2020-06-26 07:41:47  samcarter  replying to  DDCanada
Instead of manually adding all these commands, I would suggest `latexmk` or ltx2any. Advantage: They will automatically determine which compilation steps are necessary and thus not waste your time by performing all of them even if not necessary. They also offer a cleaning option, however I would abstain from cleaning the auxiliary files every time. If you don't like the clutter you can easily have them in a tmp file with ltx2any 
2020-06-26 07:55:54  DDCanada
Thank you for the advice! I will look into both of those recommendations.   
  
(Previously, I was fine with the 'messiness' of the construction files, when I only had a single filename for both my TeX document and the construction files, but now that the output changes each day that I compile the TeX document, due to the inclusion of the date in the output's filename, I was less interested in having daily duplicates for all of the construction files.)
2020-06-26 08:07:29  samcarter  replying to  DDCanada
If you only need the pdf file with the date in the filename, I would use pdflatex without job name and add something like `; cp #.pdf #_$mydate.pdf` at the end of the command. Not so much clutter and no problem with texmakers internal viewer for preview
2020-06-26 16:00:34  DDCanada
Yes, that now seems like a simpler solution! This is fantastic. Your insight is very much appreciated!
2020-06-26 17:04:56  samcarter  replying to  DDCanada
Glad to be of help!
2020-06-26 17:09:37  samcarter
@DDCanada Just for curiosity: why do you need copies of the document for each date? To track the evolution of the file or does it change every day like the lunch menu? 
2020-06-26 21:04:49  DDCanada
It is partially motivated by a desire to version control, though I also use Box and GitHub to do this more effectively. My main motivation is to track drafts of a manuscript that I frequently send to colleagues and I want to know which version of the draft that I sent via email. When I send ```filename.pdf``` via email, it is uninformative, but when I send ```filename_YYYY_MM_DD.pdf```, it reminds both me and the reader that they are reading a version of a draft from a particular date. However, the Tex filename must remain constant over time (```filename.tex```), because I want *that* document to be properly version controlled using Box and GitHub, even though I want the PDF filename to change each day that it is updated.
2020-06-26 21:16:22  samcarter  replying to  DDCanada
Thanks for the background info! I was wondering about suggesting things like git or snapshots, but especially with the email sending stuff, the date in the filename really sounds like the best solution.
2020-06-27 07:44:40  Anonymous 1375
Hola, everyone
2020-06-27 14:47:33  samcarter  replying to  Anonymous 1375
So many users with this name in a single thread - that's confusing :)
2020-06-27 17:31:03  Jack Douglas  replying to  samcarter
not any more!
2020-06-27 17:41:50  samcarter  replying to  Jack Douglas
Thanks! (and good detective work to find the thread)
2020-06-29 04:28:10  DDCanada  replying to  samcarter
**One follow-up question:** In the shell command environment, how would would I open the resulting PDF (e.g., ```#.pdf``` or ```#_$mydate.pdf```) with Texmaker's *internal* PDF viewer? 
2020-06-29 04:29:57  DDCanada
Right now, the code ```"```[...]```; open #.pdf "``` uses my default external PDF reader to open the document, presumably because it is being called by ```sh -c```, rather than natively by Texmaker. I assume that there must be a way to specify a particular app/program (e.g., ```Texmaker::RunCommand```??), but I am not well versed with shell commands. (P.S. Within Texmaker, it looks like the command for the internal PDF viewer is under "Tools > View PDF" and on my Mac OS, it is also assigned the F7 hotkey.)
2020-06-29 07:42:21  samcarter  replying to  DDCanada
Please have a look at the "P.S." in my answer.
2020-06-29 20:02:36  DDCanada  replying to  samcarter
Ah, yes, I remember reading that now. Sorry for asking a redundant question. Thank you for all of your help!
2020-06-29 20:29:15  DDCanada
OK. **I actually solved my follow-up question!** (I can't believe that I didn't think of this earlier.) After the shell command, I simply added a second line of code: 
  
```sh -c "mydate=$(/bin/date +'%%Y_%%m_%%d') ; pdflatex #.tex ; cp #.pdf #_$mydate.pdf "|open %.pdf```  
  
So, after creating a new copy of the dated PDF, I ended the shell command (denoted by the ```"```), I added a 'second' command, using the symbol prescribed by Texmaker (```|```), and I opened ```%.pdf``` using Texmaker's native command.