5

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

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn
\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
\ExplSyntaxOff
\end{document}

I expected to get the following output

foo=ä
bar=ä

but actually I get the following

foo=ä
bar=“”a

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
  • 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. Commented Mar 12, 2016 at 13:03

1 Answer 1

8

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .