# How to place expl3 function output to variable not in stream?

As explained in interface3

\int_to_roman:n {<integer expression>}

Places the value of the <integer expression> in the input stream as Roman numerals, either lower case (\int_to_roman:n) or upper case \int_to_Roman:n). The Roman numerals are letters with category code 11 (letter).

But, how can I put function value into a some variable, say \l_here_str not in stream (If I correctly understand stream mean "output to LaTeX document")?

Maybe the more general question, that refer to the behavior of conventional programming languages, where the functions values can be assigned to the variables: how does it implemented in expl3?

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn

\cs_generate_variant:Nn \int_from_roman:n {V}
\cs_generate_variant:Nn \int_to_roman:n {V}

\NewDocumentCommand{\CharCount}{ m }
{   \tl_set:Nn \l_roman_tl {#1}
\int_to_roman:V \l_roman_tl % How to assign mmciv to some variable, say \l_here_str
}

\ExplSyntaxOff

\begin{document}

\noindent\CharCount{2104}

\end{document}

• \tl_set:Nx \l_sk_roman_tl { \int_to_roman:n { #1 } }? (With a previous declaration outside of the function \tl_new:N \l_sk_roman_tl, don't forget that.) – Manuel May 29 '17 at 21:08

Ultimately expl3 is written in TeX so retains the fundamental of being a macro expansion language. Here, if you want to store the outcome of a function rather than the exact input you need to force evaluation. That is normally done by what is known as x-type expansion

\tl_set:Nn \l_tmpa_tl { \int_to_roman:n {#1} } % _Exactly_ "\int_to_roman:n {#1}"
\tl_set:Nx \l_tmpa_tl { \int_to_roman:n {#1} } % Result of \int_to_roman:n


This will work with any expandable function (those marked with a star in interface3).

If you were producing an integer here you would probably use an int variable. These can only hold integers so automatically evaluate their argument to yield one. For example, for the reverse conversion:

\int_set:Nn \l_tmpa_int { \int_from_roman:n {#1} }


One note if you have a 'classical' programming background: the str type is rather specialised in TeX, and tl is much more generally used. TeX associates a 'category code' with every token, and this affects interpretation. Most of the time you want to retain that meaning, so a tl is the way to go. (The str type is a special case of tl in which all characters are 'other', except for spaces which are 'space'.)