I'm using Spundun's method for automating inputing the entries in a diary, in turn inspired by Peter Grill (Using LaTeX to keep a diary), and I would like to add section dividers by year. This should be easily achieved by introducing an if-then clause with an existential quantifier in it, but I don't know how to do this.
Clarification about directory structure: The directory is of the form /Year/Month/Day.tex (e.g. 2014/Jan/25.tex), and each of the entries starts with \mytitle{Title}. The main .tex file is in the father directory of \Year.
How I think this could be solved: I thought one way to do what I want would be to introduce a clause like the following: for every /year, if there's a file in /Year/Month, input the file /Year.tex —which would include only a line: \section{Year} (say \section{2014}). Unfortunately, I'm not familiar enough with LaTeX to implement the solution.
Here's the code I'm using:
\documentclass{tufte-book}
\usepackage{tikz}
\usepackage{xifthen}
\title{Title}
\author{Author}
\newenvironment{loggentry}[2]%date, heading
{\noindent\textbf{#2}\marginnote{#1}\par}{\vspace{0.5cm}}
\def\?#1{}
\pgfmathtruncatemacro{\StartYear}{2014}
\pgfmathtruncatemacro{\EndYear}{2016}
\newcommand{\writetitle}{0}
\newcommand{\mytitle}[1]
{ \ifthenelse{\writetitle=1}{#1}{}
}
\newread\mysource
\begin{document}
\maketitle
\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}
{ \openin\mysource=\Year/\Month/\Day.tex
\read\mysource to \firstline
\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}
Here's what I would like the result to look like:

Thanks!

\mytitlecalled? Within the included.texfile? – Jul 30 '14 at 05:23