5

This should probably be obvious but it is not. Or not to me right now, anyway.

I want to generate a list of values (e.g. page numbers and empty values) and then pass that list as a value of a key (e.g. pages) in the argument of another macro (e.g. \includepdf).

I can generate the list of values I want easily using expl3. I can create the list as either a token list or a sequence. (But I can't use a comma-separated list here because I need to allow empty values.)

However, I cannot figure out how to pass this list correctly as the value of a key (pages) in the argument of another macro (\includepdf). Part of the problem is that I'm not sure how to pass the list with curly brackets around it. (Or, rather, I can do this with brackets with category code 12, but that is not much use here.) And part of it is maybe that I'm just missing the point somewhere.

MNWE:

\documentclass{article}
\usepackage{expl3,pdfpages}
\begin{document}
\ExplSyntaxOn
\tl_new:N \l_my_fancy_tl
\tl_set:Nn \l_my_fancy_tl { 1 }
\tl_put_right:Nn \l_my_fancy_tl { , 1 }
\cs_new_protected_nopar:Npn \my_includepdf:nn #1 #2
{
  \includepdf[#1]{#2}
}
\cs_generate_variant:Nn \my_includepdf:nn { Vn }
\tl_set:Nn \l_tempa_tl { pages={\l_my_fancy_tl} }
\my_includepdf:Vn \l_tempa_tl {example-image-a4}
\ExplSyntaxOff
\end{document}

For completeness, this doesn't work:

! Missing = inserted for \ifnum.
<to be read again> 
                   ,
l.68 ...cludepdf:Vn \l_tempa_tl {example-image-a4}

? 

How should I think about how I can fix this?

  • \tl_set:Nx \l_tempa_tl { pages={\l_my_fancy_tl} } – egreg Aug 6 '16 at 5:28
  • @egreg Thank you! I was sure that I'd tried that, but I must have made a mistake somewhere. – cfr Aug 6 '16 at 15:23
4

You're not expanding the value of \l_my_fancy_tl: change the code to do

\tl_set:Nx \l_tempa_tl { pages={\l_my_fancy_tl} }
  • Maybe I tried it with a sequence and that didn't work and then failed to try it after switching to a token list. – cfr Aug 6 '16 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.