3

Consider

\def\niii{10}
\def\niiii{21}

I can easily obtain it via

\use:c {niii} % 10
\use:c {niiii} % 21

However I would like to create csname dynamically using \int_step_inline:nn {4} {i}. I tried the following, but neither worked

\use:c { n\int_step_inline:nn {4} {i} }
\exp_args:Nx \use:c { n\int_step_inline:nn {4} {i} }

\tl_set:Nx \l_tempa_tl { n\int_step_inline:nn {4}{i} }
\use:c {\tl_use:N \l_tempa_tl}
4
  • 2
    c arguments are always fully expanded, but \int_step_inline:nn is not expandable (no * in interface3 description) Jan 22 at 15:18
  • 3
    \use:c { n\prg_replicate:nn {4} {i} } should work. Jan 22 at 15:21
  • In OpTeX, there is no problem: \def\niiii{21} followed by \cs{n\fornum 1..4\do{i}} expands to 21.
    – wipet
    Jan 22 at 15:35
  • 1
    @wipet yes same as latex, there is no problem if you use an expandable loop and it fails if you use a non-expandable one. Jan 22 at 15:40

2 Answers 2

7

The argument to \use:c must expand to character tokens only. Since \int_step_inline:nn is not fully expandable (no asterisk or hollow star next to it in the manual), it cannot be used in such a place.

You could use \int_step_function:nN like

\cs_new:Nn \__antshar_makei:n { i }

\use:c { note \int_step_function:nN { 3 } \__antshar_makei:n }

but if the purpose is to obtain a string of four i's, it's much simpler to use \prg_replicate:nn

\use:c { note \prg_replicate:nn { 3 } { i } }

But probably you don't want to create \notei, \noteii, \noteiii and so on. You can define a numeric array using

\intarray_new:Nn \g_antshar_note_intarray {100}

This allocates an array of length 100. If you want to store values in the array (which is initialized to all 0 entries)

\intarray_gset:Nnn \g_antshar_note_intarray { 3 } { 10 }
\intarray_gset:Nnn \g_antshar_note_intarray { 4 } { 21 }

and you can (expandably) retrieve a value with

\intarray_item:Nn \g_antshar_note_intarray { 3 }
2
  • doesn't that last one generate just 3 i's?
    – daleif
    Jan 22 at 15:43
  • 1
    @daleif I used 3, but 4 would be good as well. I like better 3 than 4. ;-)
    – egreg
    Jan 22 at 15:47
2

The command \int_to_roman:n can be used inside \use:c.

enter image description here

\documentclass[border=6pt,varwidth]{standalone}
\begin{document}
\ExplSyntaxOn
\def\niii{10}
\def\nxxiv{21}
\use:c { n \int_to_roman:n { 3 } }\\
\use:c { n \int_to_roman:n { 24 } }
\ExplSyntaxOff
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .