5

I create a lot of handouts and the like for my students using LaTeX. I find that I forget to update the date field, and so I often give out handouts with the incorrect date on the top. This is a bit of a nuisance and would be easily fixed by me being slightly less lazy.

However, I save the source files in the format [YY-MM-DD]_DocumentType.tex, e.g., [18-02-14]_Handout.tex and [18-02-14]_Plan.tex are the handout and plan for my class tomorrow.

Does anyone know of a way that I could use the name of the file to automatically generate the corresponding date within the compiled document?

5

I created the file [18-02-14]_james.tex (on February 13).

\documentclass{article}

\def\splitjobname[#1-#2-#3]#4\relax{%
  \year=\numexpr2000+#1\relax
  \month=#2
  \day=#3
}
\expandafter\splitjobname\jobname\relax

\begin{document}

\today

\end{document}

enter image description here

| improve this answer | |

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.