18

I need to define a token list of the form

\tl_new:N  \g_silly_tl
\tl_set:Nn \g_silly_tl { Text ~ and ~ a ~ tie:?? }

How do I do this?


More generally, is there a reference where one can see how to input characters 'normally' under expl3 syntax?

20

This question has two distinct parts, one of which is easier than the other!

The specific issue here is (presumably) not inserting a tilde but rather inserting a non-breaking space in some 'fixed' text stores as within a LaTeX3 tl variable. While a tilde is a convenient shortcut for this at the document level, here I think I would simply use the macro \nobreakspace.

\tl_set:Nn \l_silly_tl { Text ~ and ~ a \nobreakspace tie:?? }

(Note that at present there is no expl3 code-level 'non-breaking space' function.)

On the wider issue of 'inserting non-standard catcode characters', the expandable function \char_generate:nn is available to create tokens of (almost) all reasonable category codes

\tl_set:Nx \l_silly_tl
  {
    \char_generate:nn { `\a } { 4 }
  }

Currently, this cannot be used for active tokens (category code 13) for technical reasons. If you really need to create the active character rather than the semantic meaning, you've therefore got two options. The first is to use the regex module, which as it works by execution can generate active characters. A space is a bit tricky, so something like

\RequirePackage{expl3}
\ExplSyntaxOn
\tl_set:Nn \l_tmpa_tl { * }
\char_set_catcode_other:n { `\~ }
\regex_replace_all:nnN { \* } { \cA~ } \l_tmpa_tl 

is needed. The second option is stick to the 'traditional' \lowercase trick, using expl3 naming of course

\group_begin:
\char_set_catcode_active:n { `\@ }
\char_set_lccode:nn { `\@ } { `\~ }
\tex_lowercase:D
   {
     \group_end:
     \tl_set:Nn \l_silly_tl { Text ~ and ~ a @ tie:?? }
   }

(Notice that there is no public interface to \lowercase beyond the saved-primitive.)

  • 1
    Is there any update on this answer? – cfr Jan 20 '17 at 4:13
  • 1
    Not meaning to echo @cfr, but it looks like the github issue has been closed. Is there a better way to do this today? – Sean Allred Apr 16 '18 at 0:08
  • (To clarify, I'm talking about the \lowercase hack.) – Sean Allred Apr 16 '18 at 2:21
  • 2
    @SeanAllred See updated answer. – Joseph Wright Apr 16 '18 at 7:19
  • 1
    @DenisBitouzé That's still true, though you could now \char_generate:nn { `\~ } { 13 } – Joseph Wright Jan 3 at 20:53

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.