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?

Werner
  • 603,163
James
  • 187
  • 8

1 Answers1

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

egreg
  • 1,121,712