Although I've been a LaTeX user for years, this is the first time that I've been unable to find the answer to a LaTeX issue, so this is my first posted question.
I'm defining a command (\QPreparation) that will redefine the command \QInput. The command \QInput{N} should input code into my document based on number N that I send it. With each call of the \QPreparation command, I want the base path \QInput looks in to change as well as the total number of cases that \QInput will consider. The input files are named "C0.tex","C1.tex","C2.tex",... so that in redefining \QInput, the new file options are easy to update.
In the code that I've been working on (below), the 2 inputs to \QPreparation are (a) the base path to update \QInput and (b) the number of cases that I want \QInput to consider.
Because my next step is to modify the \QPreparation command so that the calls \QInput{0}, \QInput{1}, ... \QInput{N} load all N files in a random order, I DO NOT believe that it is feasible to make \QPreparation define \QInput in a manner like \input{#1/C##1.tex}.
If you are curious about how I plan to do the randomization, consider randomize the order of text lines in a .tex file .
It seems to me that the easiest way to solve this problem is to define \QInput with an \ifcase that is generated by a loop. The sample code (below) shows my attempt at this, but the additional \or in the loop throws errors such as:
! Extra \or. \iterate ->\ifnum \the \QIternum <4\relax \or \input {./Q1/C\the \QIternum ....
My sample code:
\newcommand{\QPreparation}[2]{%
\expandafter\renewcommand\csname QInput\endcsname[1]{%
\ifcase##1
\input{#1/C0.tex}
\QIternum=1
\loop\ifnum\the\QIternum<#2\relax
\or
\input{#1/C\the\QIternum.tex}
\advance\QIternum by 1
\repeat
\fi
}
}
Any help would be greatly appreciated.
Thanks!
\Qpreparation{foo}{2}the command\Qinputshould be defined like in the code\renewcommand{\Qinput}[1]{\ifcase#1\relax \input{foo/C0.tex}\or\input{foo/C1.tex}\or\input{foo/C2.tex}\fi}Am I right? – egreg Aug 16 '16 at 18:11\ifcaserather than simply\renewcommand{\Qinput}[1]{\input{foo/C#1.tex}}? – David Carlisle Aug 16 '16 at 18:13\Qinput{1}will not give\input{fooC1.tex}but instead\input{fooCN.tex}where N is random and determined by the shuffling. I've already found info on how to ``shuffle'' lines of tex code (see main body of text). If I can make the \ifcase work, then I can reach the goal. – Stephen Strickland Aug 16 '16 at 18:17