I am trying to compile a document where a section is made up of various subsections (one for each topic I want to report), each of them made up of a different number of subsubsections (varying depending on the topic).
As the number of topics, as well as the number of subsections is likely to change in future, I need to automatize the process.
Ideally, what I need to achieve is like
Pseudo-Code
foreach \section in {a,b,c}{
\section{section}
foreach \subsection in {1,2,3}{
\subsection{\subsection}
\input{file}
}
}
Where file is a composite name made by \subsection\textunderscore\section.tex
I found several suggestions. The one I think best suits my need is this \ForEach fails with underscores. However, I could not find a way to access the outer loop item to include the levelitem into the name within the inner loop, the one defining the first part of the name of the file I want to input.
I am relatively new to loops in latex (and also to latex, to a certain extent) so I am surely missing something.
I have only been able to make the first loop working. The solution might lie in the \ForEachSublevel command, but even reading the forarray manual, I have not been able to come up with a solution.
Below, my code
\documentclass[a4paper,11pt]{article}
% Packages
\usepackage[margin=2.5cm]{geometry}
\usepackage[stable]{footmisc}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{setspace}
\usepackage{enumitem}
\usepackage{booktabs}
\usepackage[para]{threeparttable}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{graphicx}
% ----------------------------
% FORARRRAY TO LOOP WITH UNDERSCORES
% https://tex.stackexchange.com/questions/456693/foreach-fails-with-underscores
\usepackage{forarray}
\newif\iffilename
\global\filenamefalse
\makeatletter
\newcommand\myunderscore{%
\iffilename
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi{\string_}{\textunderscore}%
}%
\makeatother
% -----------------------------
\usepackage{bookmark}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{natbib}
% ------------------------------------------
\begin{document}
\section{Results}
% https://tex.stackexchange.com/questions/456693/foreach-fails-with-underscores
\ForEach{,}%
{%
{% Open local scope
\subsection{SYNTH OUTCOME ON \thislevelitem \hspace{1pt} OUTCOME}%
}% Ends local scope
}% ForEach ends here
{%
ipc\myunderscore ruleoflaw,ipc\myunderscore politicalrights,ipc\myunderscore gender,ipc\myunderscore socprotection,ipc\myunderscore business,ipc\myunderscore health,ipc\myunderscore work,ipc\myunderscore edu,ipc\myunderscore security,ipc\myunderscore environment,ipc\myunderscore minority,ipc\myunderscore cvrights,ipc\myunderscore womenrights,ipc\myunderscore corrupt% Needed comment
}%
\end{document}

