Apparently, the {
and }
'strings' shall appear literally in the string, so one way to add them is to use \c_left_brace_str
and \c_right_brace_str
and the V
modifier for the \str_set:Nn
macro
There are other literal string constants such as \c_hash_str
or \c_dollar_str
, which are constant token lists with catcode 12 actually. See page 75 in the current interface3
manual (as of 2018/12/27).
\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\str_new:N \l_example_var
\int_new:N \l_example_int
\str_set:NV \l_example_var \c_left_brace_str
\str_put_right:NV \l_example_var \l_example_int
\str_put_right:NV \l_example_var \c_right_brace_str
\str_put_right:Nn \l_example_var {~some~text}
\str_show:N \l_example_var
\ExplSyntaxOff
\end{document}
The output is
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018)
(preloaded format=pdflatex) \write18 enabled. entering extended mode
(./stringwith.tex LaTeX2e <2018-12-01>
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(./stringwith.aux)
\l_example_var={0} some text. }
l.16 \str_show:N \l_example_var
? x No pages of output. Transcript written on stringwith.log.
\c_left_brace_str
and\c_right_brace_str
instead of\{
and\}
, but are you sure you needstr
instead of a token list, i.e.\tl_set:N...
?\tl_set:NV \l_example_tl { {\l_example_int} }
results in the surrounding braces disappearing.\tl_set:Nx \l_example_tl { { \int_to_arabic:n { \l_example_int } } }
\tl...
like solution as well...