I have a folder called diary
which contains a series of files:
20120101.tex
20120105.tex
20120304.tex
- etc.
How can I create a single LaTeX document that includes each of these files, in alphabetical order? I'd like to do this within LaTeX, not using LuaTeX or shell operations (to make it portable).
I found a near-solution here, but I can't get it to work properly for this situation.
\documentclass{book}
\usepackage{xifthen}
\begin{document}
% 20120101.tex included here
% 20120105.tex included here
% etc
\end{document}
The code from the near solution linked above for iterating over files that I am trying to modify is:
\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}
{ \newread\mysource
\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
}
}
}
}
Here is my failed modification that I want to not look in year/month subdirectories, but read the files as I have listed them above:
\foreach \Year in {\StartYear,...,\EndYear}
{ \foreach \Month in {01,02,03,04,05,06,07,08,09,10,11,12}
{ \foreach \Day in {01,...,31}
{ \IfFileExists{{Year}{Month}{Day}}
{ \newread\mysource
\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{{YearMonth/\Day}
\end{loggentry}
}
{ % files does not exist, so nothing to do
}
}
}
}
The problem is in concatenating the variables to create the file name instead of subdirectories, which I can't figure out how to do (the above, obviously, doesn't work).
\documentclass
and the appropriate packages that you used and we can help you from there.standalone
package. There are numerous example of that on this site.\foreach \Y in {2012,...2013}{\foreach \M in {1,...,12}{\foreach \D in {1,...,31}{\IfFileExists{\Y\M\D} {\input{\Y\M\D}}{}}}}
should work.