I'm trying to follow along with this answer to automagically include files based on the filesystem hierarchy.
My file structure looks like:
article.tex
sections/
|-- 00-introductions.tex
|-- 10-data.tex
|-- 20-analysis.tex
|-- 90-conclusions.tex
|-- data/
| |-- 00-xxx.tex
| |-- NN-xxx.tex
|
|-- analysis/
|-- 00-xxx.tex
|-- NN-xxx.tex
So I want to include everything inside sections
in article.tex
, everything in sections/data
in 10-data.tex
, and everything in sections/analysis
in 20-analysis.tex
. For the purposes of this question, let's just focus on article.tex
.
In an attempt to follow the linked answer, I've created the following bash script to generate a list of the appropriate files:
#! /bin/bash
ls -mp sections/ | grep -v / | tr ' ' '\n' > sections.list
And I've added this to my .latexmkrc
so that it runs on every build (this bit works). It outputs the following (the new line is there if that's relevant):
00-introduction.tex,
10-data.tex,
20-analysis.tex,
30-conclusions.tex,
I've also tried an alternative that didn't have the commas appended.
My articles.tex
(sans cruft) looks like this:
\documentclass[twocolumn, a4paper]{article}
\usepackage{pgffor}
\newcommand*{\listofsections}{\input{sections.list}}
\begin{document}
\foreach \c in \listofsections {%
\input{sections/\c}%
}%
\end{document}
And if I just output \listofsections
it looks fine to me:
It looks as though something's wrong in my definition of the loop as these errors are popping up in the logs:
/home/james/repos/discos-paper/article.tex:28: Missing endcsname inserted. let l.28 } % /home/james/repos/discos-paper/article.tex:28: Use of ??? doesn't match its definition. ???
! LaTeX3 Error: let invalid in file name. Lost: reserved@d =... l.28 } % /home/james/repos/discos-paper/article.tex:28: Missing endcsname inserted. let l.28 } % /home/james/repos/discos-paper/article.tex:28: Use of ??? doesn't match its definition. ???
! LaTeX3 Error: let invalid in file name. Lost: reserved@d =... l.28 } % /home/james/repos/discos-paper/article.tex:28: Missing endcsname inserted. let l.28 } % /home/james/repos/discos-paper/article.tex:28: Use of ??? doesn't match its definition. ???
! LaTeX3 Error: let invalid in file name. Lost: reserved@d =... l.28 } %! LaTeX Error: File `sections/.tex' not found.
What have I missed here?
Edit 1:
For some reason, it seems as though my \listofsections is coming through as a single item and the iterator is only being called once...
I've also now tried editing the list file to be:
00-introduction.tex,10-data.tex,20-analysis.tex,30-conclusions.tex
Which still doesn't work, nor does it work if I place that in the \newcommand
but curiously does if I copy the contents straight into the foreach loop... So I'm really not sure what's going wrong if I'm honest.