To avoid the XY problem, I'll describe what I am looking for (the X) and the issue that I found while attempting X (the Y). To be clear: I'm not trying to troubleshoot Y, I'd be grateful if only X is solved.
What I'm looking for
I want to define a macro that accepts a string as an argument and it displays a given number of characters (by calling an arbitrary macro) per page until the string is entirely traversed.
Here's an example: Let's consider the string abcdefghijk, 3 as the number of characters we want to display per page, and \foo the macro that we want to call for each character. The resulting document should look like.
\documentclass{article}
\newcommand\foo[1]{Hello #1}
\begin{document}
\foo{a} \foo{b} \foo{c}
\newpage
\foo{d} \foo{e} \foo{f}
\newpage
\foo{g} \foo{h} \foo{i}
\newpage
\foo{j} \foo{k}
\newpage
\end{document}
I came up with the following pseudocode:
1. While the original string is not empty:
1.1. Create a substring from the first character to the third character.
1.2. Remove the first three characters from the original string.
1.3. For every character in the substring:
1.3.1. Call \foo{character}
1.4. Call \newpage
My attempt
For step 1.2, the original string needs to be set to a substring of itself, so I tried setting \mystring to a substring to itself using the \substring from the stringstrings package, but I got the error Use of \\substring doesn't match its definition..
\documentclass{article}
\usepackage{stringstrings}
\usepackage{xstring}
\begin{document}
% An arbitrary string
\def\mystring{abcdef}
% We obtain the length so that we can create a substring from the 4th
% character to the end of the string.
\StrLen{\mystring}[\mystringlen]
% When I try to display the string, I get the following error:
% ! Use of \substring doesn't match its definition.
% \kernel@ifnextchar ...rved@d =#1\def \reserved@a {
% #2}\def \reserved@b {#3}\f...
% l.14 \mystring
%
% ?
\def\mystring{\substring{\mystring}{4}{\mystringlen}}
\mystring
\end{document}
I feel there's a simpler way to implement the pseudocode that I explained above.



\clearpage. – user202729 Mar 25 '24 at 03:15