Allright, hi guys. Inside my EPS i got quite some texts that are quite similar. Only their index shall change from each one. So i'm trying to get those done in an own command.

They are used inside an \begin{figure}...\end{figure} - block, right after \centering. after them the eps gets included.

My code looks like this:

\newcommand{\qfrag}[1]{\psfrag{q#1}[c][c]{$q_#1$}} %this works as \qfrag{0}\qfrag{1}...
\newcommand{\qrfrag}[1]{\forloop{ctr}{0}{\value{ctr} < #1}{\qfrag{\arabic{ctr}}}} %but not like this.

My \qfrag replaces all q#1 to q_#1. works fine on its own. Also behind each other like this works fine:


But once i try to get them together inside a forloop they kinda mess up and make all indices of my q's to the number inserted to \qrfrag{}

\qrfrag{3} causes to be all q0,q1,q2 to become formatted q_3 but not q3. 

Any clues on your sides there? I'm kinda new to latex.


Please always post complete small documents not just fragments, then answers can be tested, however.


\newcommand{\qrfrag}[1]{\forloop{ctr}{0}{\value{ctr} < #1}{\qfrag{\arabic{ctr}}}

The syntax for a subscript is _{...} not _... when #1 is substituted you get


so as there are no braces, the subscript is just the token \arabic and anything that happens after that is just accidental artefact of the internal expansions.

If you define it as


It has a better chance of working (but this isn't tested as noted above).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.