add tag
DDCanada
One year ago, I posted a question about how to add a macro to the title of the compiled PDF document, using Texmaker, and [I received excellent advice from members of this forum](https://topanswers.xyz/tex?q=1134). (I remain grateful!) 

I recently purchased a new computer and I have decided to use this as an opportunity to switch from Texmaker to TexStudio. However, these two programs have different approaches to compiling TeX files into PDF documents---and, therefore, I am revisiting my question from last year about how to add a macro to the PDFLaTeX command. 

*What I wrote a year ago:*
> My ultimate goal is to add the current date (e.g., YYYY_MM_DD) to the PDF filename. For instance, if my input TeX document were named “Original_Name.tex”, I would want the output PDF file to be named “New_Name_YYYY_MM_DD.pdf” in which the current date is filled in.

*The solution (by [samcarter](https://topanswers.xyz/user?id=167&community=tex)):*
> You can add a “user command” like this:
\
> `sh -c "mydate=$(/bin/date +'%%Y_%%m_%%d') ; pdflatex --jobname=document1_$mydate document.tex "`
\
\
This will result in a pdf file document1_2020_06_25.pdf. The exact format of the date can be adjusted according to your taste, a summary of the available options can be found at https://www.man7.org/linux/man-pages/man1/date.1.html

*My modification to the solution, which allows me (a) to create a second PDF with the date in the title and (b) to view the resulting PDF, all in one command line:*
> `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.

I have been experimenting with how to adapt this code for TexStudio, but I haven't been successful yet. In last year's thread, [samcarter](https://topanswers.xyz/user?id=167&community=tex) did make the following comment:
> With texstudio I would simply add something like `txs:///view-pdf "?am)_$mydate.pdf"` to the command, but this obviously won’t work with texmaker…

However, I am struggling to integrate the requisite shell command (e.g., `sh -c "mydate=$(/bin/date +'%%Y_%%m_%%d')`) to the user commands in TexStudio.

My question for everyone is: 
**After compiling a TeX file with PDFLaTeX, how can I add a macro with the current date to the resulting PDF document's filename---but this time using TexStudio?**
Top Answer
DDCanada
In the end, I was able to answer my own question about how to add a macro (with the date) to the title of my PDF document in TexStudio.

First, I created a user command that copies the PDF document and renames the new PDF document with the current date: 

```
sh -c "cp %.pdf %--$(/bin/date +'%%Y.%%m.%%d').pdf "
```

Second, I call this line of code in a subsequent user command. E.g.:
```
txs:///pdflatex | txs:///titledate | txs:///view
```

Here is a screenshot of the user commands that worked for me in TexStudio:
![Screen Shot 2021-11-01 at 4.47.14 PM.png](/image?hash=7d425bd53283305e8c2c23a197ffb8efe87a9d6316c89d837f7c7ef5bba5f3a7)

Perhaps this will prove useful for someone who finds this thread via a search for a related TeX question!

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.