0

After calculating \pgfmathresult and turning the output as an integer:

\pgfmathprintnumber{\pgfmathresult}

Which for example is 10, I want to iterate instead of

\foreach \i in {1,...,10}{%
    some iteration
    }

,with something like this

\foreach \i in {1,...,\pgfmathprintnumber{\pgfmathresult}}{%
some iteration
}

Unfortunately it doesnt work. How can I approach this, any ideas?

THX a lot!

  • 1
    Maybe better use \pgfmathparse{int(<your calculation>)} and then \foreach \i in {1,...,\pgfmathresult}{ ... – Jasper Habicht Nov 16 '22 at 14:27
  • 1
    The most straight-forward way is probably \foreach[parse=true] \i in {1, ..., int(<your calculation>)} but we'd need to know more about your actual calculation to figure out what's best. \pgfmathprintnumber certainly won't work. – Qrrbrbirlbel Nov 16 '22 at 14:32
  • Thanks a lot Jasper, your code works in my case! – Bilal Yilmaz Nov 16 '22 at 15:18
  • Thanks also to you, Qrrbrbirlbel! The calculation is the "number of lines in a text", which is from osjerick in this post: https://tex.stackexchange.com/questions/317713/count-lines-in-a-block-of-text

    So basically, i wantet to calculate first the number of lines in a paragraph, and then with this integer, iterating through some stuff.

    – Bilal Yilmaz Nov 16 '22 at 15:20

0 Answers0