I was wondering how to properly use LaTeX3 strings. Consider the following code:

\tl_new:N \l_foo
\tl_set:Nn \l_foo {\"a}
\str_new:N \l_bar
\str_set:Nn \l_bar {\"a}
foo = \tl_use:N \l_foo \\
bar = \str_use:N \l_bar

I expected to get the following output


but actually I get the following


Do I have to treat an umlaut somewhat special in a LaTeX3 string? Beside that what is the recommendation when to use a str and when to use a tl? Are there any benefits from one or the other? My background is, that I'm developing a package where some variables are left to the user in order to customize the output.

  • 1
    In strings all tokens have catcode 12 (space 10), so the backslash doesn't start a command and you are simply seeing the output of "\char92 \char34 \char 97" as backslash has the ascii position 92. – Ulrike Fischer Mar 12 '16 at 13:03

In TeX, and thus in expl3, a string has a very specific meaning. A string is a collection of tokens where spaces (character code 32) are of category space (category code 10), and all other tokens are of category 'other' (category code 12). This is a special case of the more general concept of a token list, which is a collection of tokens of arbitrary category codes.

We have both a tl and a str data type in expl3 as the latter is useful for 'flagging up' programmatic uses where string values are important. However, at a technical level there is no reason these couldn't be called tls. For storing text for typesetting you always want to preserve meaning, so str would be inappropriate: you want tl.

| improve this answer | |

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.