CSS

Monday, November 21, 2022

Emacs Macro: PDF Creation Date for LaTeX

I have been using Emacs...for a while now. I've found it useful to automate away common tasks using Lisp functions. One that has been recurring: write the creation date. Using something like datetime2 package in LaTeX (and assuming you're using PDFlatex), then the following command can be used to automatically determine the date and time you started writing:

(defun latex-created ()
  (interactive)
  (insert (format-time-string "\\DTMsavetimestamp{creation}{%FT%T%z}\n"))
  (insert "{\\DTMsetstyle{pdf}\\pdfinfo{/CreationDate (\\DTMuse{creation})}}\n")
  (insert "\\date{\\DTMusedate{creation}}\n"))

The other bit of advice I have is to use Yasnippets. It's so much easier to start a new line, enter "d", hit tab, and have it expand to a definition environment (or have "thm" expand to a theorem environment). I have written a few snippets and found them wonderful.

No comments:

Post a Comment