problems with \forloop and \foreach (Support #585)


Added by Giovanni Morando over 5 years ago. Updated over 5 years ago.


Status:Feedback Start date:09/08/2018
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-

Description

Dear Community, I am preparing an AMC test importing questions from a unique directory through some \element{all}{\input{q1.tex}} commands. My questions are named q1.tex q2.tez q3.tex q4.tex I would like to import all of them in a unique way through a loop with a counter.
I tried \forloop and pgf command \foreach but none of them is working. The first one works if the loop is defined inside the \element{all}. In this way I have 4 questions which cannont be shuffled (if I understood correctly elements of group are shuffled but different questions inside a unique element are not shuffled). I try to define \forloop outside the \element command but it does not work. It seems that the element command produces conflicts with loops.

Any idea?

Thanks in advance,
Giovanni


groups.tex (1.1 kB) Giovanni Morando, 09/08/2018 11:20 pm

q1.tex (226 Bytes) Giovanni Morando, 09/08/2018 11:20 pm

q2.tex (209 Bytes) Giovanni Morando, 09/08/2018 11:20 pm

q3.tex (278 Bytes) Giovanni Morando, 09/08/2018 11:20 pm

q4.tex (224 Bytes) Giovanni Morando, 09/08/2018 11:20 pm

amc-compiled.log (29 kB) Giovanni Morando, 09/08/2018 11:20 pm


History

Updated by Alexis Bienvenüe over 5 years ago

  • Tracker changed from Bug to Support

Updated by Alexis Bienvenüe over 5 years ago

The whole code inside the \element call is added as-is in the group. It is only called when displaying elements, so that at this time the question counter equals 4 for all elements…
Maybe you can try something like that:

\newcommand\addsource[1]{
\element{all}{\input{./q#1.tex}}
}

\newcount\nsource\nsource=1
\loop
  \expandafter\addsource\expandafter{\the\nsource}
\ifnum\nsource<4\advance\nsource by 1\repeat   

  • Status changed from New to Feedback

Also available in: Atom PDF