5

In the following MWE my personal definition of \marco_prop_get:nn works unless it isn't inside the macro \color. The snippet is:

\ExplSyntaxOn
\cs_new_protected:Npn \marco_prop_get:nn #1 #2
 {
  \prop_get:cn  { l_marco_ #1 _collection_prop } { #2 }
 }
\color{ \marco_prop_get:nn { color } {my-title} } My~ Title
\ExplSyntaxOff

I am a little bit confused because the using of \prop_get:Nn works well.

\ExplSyntaxOn
\prop_new:N \l_marco_color_collection_prop
\prop_put:Nnn \l_marco_color_collection_prop {my-title} {red}
\color{ \prop_get:Nn\l_marco_color_collection_prop {my-title} } My~ Title
\ExplSyntaxOff

Here the MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{expl3}

\begin{document}
\def\foo{red}
\color{\foo}\foo

\ExplSyntaxOn
\cs_set:Npn \foo { blue }
\ExplSyntaxOff
\color{\foo}\foo

\ExplSyntaxOn
\prop_new:N \l_marco_color_collection_prop
\prop_put:Nnn \l_marco_color_collection_prop {my-title} {red}
\color{ \prop_get:Nn\l_marco_color_collection_prop {my-title} } My~ Title
\ExplSyntaxOff

\ExplSyntaxOn
\cs_new_protected:Npn \marco_prop_get:nn #1 #2
 {
  \prop_get:cn  { l_marco_#1_collection_prop } { #2 }
 }
\exp_after:wN \color \exp_after:wN { \marco_prop_get:nn { color } {my-title} } My~ Title

%\color {  \marco_prop_get:nn { color } {my-title} } My~ Title
\ExplSyntaxOff
\end{document}

Can you explain please why does my command fail without \exp_after:wN.

Please note I am using the svn version of expl3.

3
  • Just a thought: wouldn't \exp_args:No a) be easier to read and b) be more “expl3-like” instead of \exp_after:wN? – cgnieder Jun 3 '12 at 20:24
  • @cgnieder: I can't test it now. Does it work? – Marco Daniel Jun 4 '12 at 5:26
  • Yes it works nicely :) – cgnieder Jun 4 '12 at 6:26
5

It would work with color but as far as I can see xcolor uses \@onelevel@sanitize to suppress expansion so the argument is safe for it to parse its more extensive color syntax. So you need to make sure you do enough expansion before \@onelevel@sanitize uses \meaning. Hence the need for \expandafter.

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.