LaTeX3 reduces the need to use \expandafter/\exp_after:wN tremendously. But what is the LaTeX3 way for this problem?

  \tl_new:N \__a
  \tl_new:N \__b
  \tl_set:Nn \__a { \emph{emph} }
  \tl_set:No \__b { \exp_after:wN \overset 
                    \exp_after:wN { 
                    \exp_after:wN o 
                    \exp_after:wN } 
                    \exp_after:wN { \__a }  }
  \tl_show:N \__b % target: b = \overset{o}{\emph{emph}}
  • Welcome to TeX.SX! – Adam Liter Nov 26 '14 at 21:34

While one could use \tl_put_right:NV or similar here, there would be something of a loss of efficiency as you've got to introduce a brace group and that need several steps. Instead, I would here us an x-type expansion and appropriate control:

\tl_set:Nn \l_tmpa_tl { \emph { emph } }
\tl_set:Nx \l_tmpb_tl
  { \exp_not:N \overset { o } { \exp_not:V \l_tmpa_tl } }

As we can always limit expansion there is no need to worry about using an x-type process (\edef) here.

I'd use \tl_put_right:NV or similar if I was just joining two token lists directly without the brace business.

  • Note the variable naming here: I've used the expl3 scratch space, but the \<scope>_<name>_<type> idea is general. – Joseph Wright Nov 26 '14 at 22:06

Aren't we mixing 2e conventions and expl3 conventions here? As an alternative to Joseph's answer how about:

Have a version of \overset in expl3 conventions, i.e.,

  \cs_set_eq:NN \overset:nn \overset     % not a very good expl3 name though :-)

Provide the variant you need here, i.e.,

  \cs_generate_variant:Nn \overset:nn { no }

Then use simply

   \overset:no {o}{\__a}

What I'm trying to say is the issue is not in the problem of expanding a second brace group the problem is that we can't apply expl3 conventions if we mix in 2e names.

In fact expl3 does even have the functionality to make this work directly:

   \exp_args:Nno \overset {o}{\__a}

but imho it is cleaner and in the long term better to use expl3 conventions throughout, ie mask 2e names if you want to use them in an expl3 context. For the same reason \__a is short but frowned upon as expl3 promotes the use of variable types and l and g to indicate local and global!

  • I don't see that we are mixing conventions. I do much the same thing inside siunitx where the code level material is in expl3 but is used to create document-level output. For example, in v3 (in development) I set out to generate \mathrm{kg}\,\mathrm{m}\,\mathrm{s}^{-1} from \kilo\gram\metre\per\second and return the 'formatted' material to a higher level. The aim there is that I explicitly want to generate a tl containing what you would type in 'by hand', so it's defined as being 'document level only' tokens. – Joseph Wright Dec 3 '14 at 8:24
  • @JosephWright I think the example is mixing conventions because \overset is a function with arguments and not formed by convention thus you can't use standard argument processing logic. Your example with \kilo\gram... seems to be more in the light of this is the "data" that you manipulate. That would obviously not mixing conventions. – Frank Mittelbach Dec 3 '14 at 9:19

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.