0

The following code still renders correctly but throws an error ('Missing } inserted') when including amsmath:

\cs_new:Npn \putInEnvironment:nnn #1 #2 #3
{
    \if_bool:N #2
        \tl_put_left:Nn  #1 {#3\c_group_begin_token}
        \tl_put_right:Nn #1 {\c_group_end_token}
    \fi:
}

used, e.g., for

\putInEnvironment:nnn {\l_my_symbol_tl}{\l_my_corrected_bool}{\hat}
\putInEnvironment:nnn {\l_my_symbol_tl}{\l_my_dot_bool}{\dot}

as part of a larger macro. Other environments, e.g., \underline, still work. Can somebody explain to me how I can fix this? Thanks!

EDIT: Thanks for the quick response, to clarify:

  • The intention was to build up a symbol using a lot of possible modifies (via key-value), which leads to nesting of quite some \cmd{< symbol >}
  • my misunderstanding was that I thought \cmd{< symbol >} == \cmd\group_begin< symbol >\group_end, which was what the function did, nest, what I erroneously called environments
  • funny enough, without including amsmath my function did what I intended
2
  • Welcome to TeX.SX! Note that \hat\c_group_begin_token x\c_group_end_token will take \c_group_begin_token as the argument to \hat. This would be the same as \hat\bgroup x\egroup that doesn't work; why \underline\bgroup x\egroup works is another story. What's your purpose? – egreg Feb 6 '18 at 10:35
  • it is not clear what you want to do here and the terminology you are using is confusing, \underline, \dot etc are not environments. what do you intend this to do? – David Carlisle Feb 6 '18 at 10:35
1
\cs_new_protected:Npn \behe_putInEnvironment:NNN #1 #2 #3
 {
  \bool_if:NT #2
   {
    \tl_set:Nx #1 { \exp_not:N #3 { \exp_not:V #1 } }
   }
 }

\behe_putInEnvironment:NNN \l_my_symbol_tl \l_my_corrected_bool \hat
\behe_putInEnvironment:NNN \l_my_symbol_tl \l_my_dot_bool       \dot

Altough as david and egreg say, it's not clear what you intend. Other things:

  • \putInEnvironment:nnn is weird surrounded with the style of \behe_put_in_environment:; plus
  • \hat and \underline are not “environments”; plus
  • :nnn should be :NNN since the three arguments are single token; plus
  • I used _protected since the command is not expandable; plus
  • I used \bool_if:NT rather than the plainer \if_bool:N.

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.