# Using LaTeX to keep a diary

As the title implies, I would like to use LaTeX to keep a personal diary. I've been dumping my entries in a single file which has become unwieldy over time. Ideally I'd find a package (or collection of shell scripts) which assists me in maintaining a consistent directory structure and automatically headlining entries with their respective date.

I haven't found anything relevant in the CTAN repository, so I'm turning to you for advice. If there's no readily available solution, I might sit down and learn how to create custom packages.

Thank you very much!

-
Do you want to just throw in some entries with a date and let LaTex order them, or do you just want some consistent look and are willing to take care of the ordering yourself? – Tom Bombadil Aug 24 '12 at 2:04
A consistent look is important to me. Ideally it would suffice to put an entry into files with a path matching the pattern /year/month/day.tex, and LaTeX would take care of putting the entries at the right place and include the date of writing in a pleasant-looking fashion. – user1428640 Aug 24 '12 at 9:37
Depending on how comfortable you feel with Emacs, you might want to look at org-mode (orgmode.org), and then export to TeX when you want to "generate" a nicely typeset version of your journal. – mvarela Aug 24 '12 at 14:40

As you can't comment yet, here's a proposition using the tufte-latex class and a custom environment. This is just what I made up, you could edit your question to specify what format and features you would like. The lipsum package is just used for some dummy text.

\documentclass{tufte-book}
\usepackage{lipsum}

{\noindent\textbf{#2}\marginnote{#1}\\}{\vspace{0.5cm}}

\begin{document}

\begin{loggentry}{2009-Oct-31}{Snow}
\lipsum[1]
\end{loggentry}

\begin{loggentry}{2010-Dez-31}{Water of Life}
\lipsum[2]
\end{loggentry}

\begin{loggentry}{2011-Nov-15}{Cold}
\lipsum[3-5]
\end{loggentry}

\begin{loggentry}{2012-Aug-24}{Sunrise}
\lipsum[6-7]
\end{loggentry}

\end{document}


Edit 1: Here's an automated version. It assumes your directory to be of the form /Year/Month/Day.tex, formatted as e.g. 2012/Aug/24.tex, so the month is just the first three letters. The individual .tex files have only the requirement to have the first line as \mytitle{<The actual title here>}.

This solutions makes use of Peter Grill's answer to "How to iterate through the name of files in a folder".

## The main file:

\documentclass{tufte-book}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{xifthen}

{\noindent\textbf{#2}\marginnote{#1}\par}{\vspace{0.5cm}}

\def\?#1{}

\pgfmathtruncatemacro{\StartYear}{2008}
\pgfmathtruncatemacro{\EndYear}{2012}

\newcommand{\writetitle}{0}
\newcommand{\mytitle}[1]
{   \ifthenelse{\writetitle=1}{#1}{}
}

\begin{document}

\foreach \Year in {\StartYear,...,\EndYear}
{   \foreach \Month in {Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}
{   \foreach \Day in {1,...,31}
{   \IfFileExists{\Year/\Month/\Day}
{   \openin\mysource=\Year/\Month/\Day.tex
\closein\mysource
\xdef\writetitle{1}
\begin{loggentry}{\Year - \Month - \Day}{\firstline}
\xdef\writetitle{0}
\input{\Year/\Month/\Day}
\end{loggentry}
}
{   % files does not exist, so nothing to do
}

}
}
}

\end{document}


## A sample log entry file:

\mytitle{Something happened}
\lipsum[3-5]


## The Output:

-
The OP's question seems to imply that one problem s/he faces is that there are many entries, so keeping them in a single file is not practical. Your answer could be improved by replacing \lipsum by the appropriate \input commands, perhaps putting each logentry in a separate file as you see fit. – Bruno Le Floch Aug 24 '12 at 8:50
Your sample looks very pretty, thank you very much. As I stated in a comment above, I would like to put entries in files /year/month/day.tex and having LaTeX do the labour of figuring out the right order and headlining every entry with the date of its writing (extracted from the path name). I might write a shell script, but perhaps you can think of some other means. – user1428640 Aug 24 '12 at 9:44
It is very nice! The only problem is that it looks for all the possible files. I believe that \write18 (aka --shell-escape) could be used to get the list of really existing files. Something like ls */*/* | sed 's/^/\\input' > ls.tex. Sorry, I have no experience with sheel escape, as well it is OS-dependent. – tohecz Aug 24 '12 at 12:36
I don't know how that will be once you piled up 1000 files, but I was surprised how fast it compiled, given that in the given configuration it checks for 5*12*31=1860 files. – Tom Bombadil Aug 24 '12 at 12:41
Thank you - it helps me a lot in creating a personal journal template. Just want to mention that \marginpar works if you just want to use the article style instead of tufte-book.. – M-V Oct 3 '12 at 11:14