I am trying to keep a journal-type file using TeX. I would like to create a template in which I need not manually enter the date each day. Example:

January 26, 2014 Entry for the day here.

January 27, 2014 Entry for the day here.

January 28, 2014 Entry for the day here.

I would ideally like to automate this to:

\today <--- Set date to January 26, 2014 that does not change when compiling next day Entry for the day here.

\today <--- Set date to January 27, 2014 that does not change when compiling next day Entry for the day here.

\today <--- Set date to January 28, 2014 that does not change when compiling next day Entry for the day here.

Any help would be greatly appreciated! Best wishes, ~Joco

  • 5
    Welcome to TeX.SX! This is simply not possible. TeX reads a text file and can't know when you made a note; this is to be done at the editor's level. – egreg Jan 27 '14 at 18:56
  • I wouldn't go so far as to say it is impossible, but it may be far more risky to automate such a procedure rather than specifying a day manually. For example, what should happen when you consider to skip a day of writing and write two days in one? – Werner Jan 28 '14 at 6:23

Well, here is one way to achive what you want, but this requires that you:

  • Add any new entries at the bottom (ie., your file's entries are in the order that you added them).
  • Run pdflatex everytime you add a new entry.
  • Keep the \jobname.db which keeps track of what each of the \today's refer to.

So, any earlier uses of \today (in this example these are the first two) get marked in blue), and today's entry shows up in red:

enter image description here

Further Enhancements:

  • Define a \yesterday macro in case you don't get around to adding the enteries until after midnight for some reason.




\noindent\tikz \draw [draw=black, ultra thick, #1]
    ($(current page.center)-(0.5\linewidth,0)$) -- 
    ($(current page.center)+(0.5\linewidth,0)$)
    node [midway, fill=white] {#2};


        \DTLloaddb[keys={TodayCount,MonthAndDay,Year}]{HistoryDB}{\jobname.db}%  Read prior DB
        \DTLnewdb{HistoryDB}%           Initialize new DB (this is first time usage)
    \renewcommand{\today}{% Get data from HistoryDB while we can
            % Then this is a new entry 
            % This is an older entry, so need to retrieve the date for it
            \bigskip\par\CenteredText[thin,blue]{\textbf{\HistoryMonthAndDay, \HistoryYear}}%


Well, today I saw this problem at TeX.SE that some say can't be done.
Of course this make me want to tackle it.

Had an idea as to how to tackle it, but since I am flying out of the country I can't quite work on it.

Now that I have done enough procrastinating on TeX.Se, I can do some more by working on that
so-called "unsolvable problem".  I think I have a solution ready to post.


I've seen so many crazy things made with LaTeX, i wouldn't say that something is impossible, but you have to use LuaLaTeX for my solution.

At first make a file,call it datetime.lua and add the following line.


t = {}

All dates are saved in a lua table. You can edit them later in this file.




 function getdate(c)
  d = os.date("%d %B, %Y")   
   if (c <= #t) then
    file = io.open("datetime.lua", "a")
    file:write("t[".. c .."] = '" .. d .. "'; ")






I am using a counter to make a referenz to the date position. The value is passed to a simple lua function. If the date is already saved, it is loaded from the table and if not, it is written to the datetime file and the current date is printed.

Edit: You can get a problem when you change the order. (reorder the numbers in datetime.lua)


Put every entry in a file of its own. Use a consistent naming scheme; I’ll use entryinteger.tex below to work well with platform-independent pgffor, but you could also do standard ls (Unix, Linux, OS X) or dir (DOS, Windows) with --shell-escape (see also package ifplatform). This could look something like this:

\usepackage{pgffor} % \foreach
\usepackage{filemod} % \Filemodtoday etc., does not work with xetex
\def\inputentries#1{% takes the max number of entries as an argument
  \foreach \i in {1,2,...,#1}{%

Alas, I assume you want everything in one file. That won’t work.

  • 3
    Also correcting a typo in one file on a later day than its creation would produce a wrong date. – egreg Jan 27 '14 at 22:04

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.