Skip to main content
31 votes
Accepted

Unbalanced dollar signs

First example: \newcommand\weird{$$xyz$} \weird$ \weird is expanded to $$xyz$ and processed; The first $ is identified and TeX searches for a following $ since there's a difference in how $...$ and $...
Werner's user avatar
  • 607k
22 votes
Accepted

Expandable test for an empty token list—methods, performance, and robustness

General There are a few considerations when it comes to performance of TeX code: argument grabbing costs time, don't grab arguments unnecessarily \expandafter is slow, if you can work around it with ...
Skillmon's user avatar
  • 61.5k
18 votes
Accepted

Character bytes and character tokens: If newlines are converted to spaces, then where does catcode 5 come into the picture?

There are never any tokens with catcode 5. Initex sets up \catcode`\^^M=5 But that acts in a similar way to \catcode`\%=14 which makes % catcode 14, but there are no tokens with that catcode, If ...
David Carlisle's user avatar
17 votes
Accepted

what \relax command means?

\relax is a tex primitive command that is non expandable but is defined to do nothing at all, it is useful in several contexts as a delimiter of various sorts. LaTeX always writes one to the start of ...
David Carlisle's user avatar
16 votes

Why does the TeX scanner process tokens for register numbers and macro names differently?

Your assumptions are wrong. When doing an assignment to a count register, TeX obeys the syntax <count register><optional equal sign><number> where <count register> can be an ...
egreg's user avatar
  • 1.1m
15 votes

Character bytes and character tokens: If newlines are converted to spaces, then where does catcode 5 come into the picture?

Characters have a category code; they can generate a character token during the tokenization phase, but they need not to. Category codes are used with twofold purposes: they are looked at during ...
egreg's user avatar
  • 1.1m
15 votes
Accepted

Why does the TeX scanner process tokens for register numbers and macro names differently?

I don't think that your description of scanning for a macro name is accurate (although I do not know what you mean by typeset:false, so that may or may not be true) Note that scanning for macro names ...
David Carlisle's user avatar
14 votes
Accepted

What are the constituents of a LaTeX3 token list?

In expl3 lingo, token is the same as in basic TeX, see What is a token? However, a token list (in a variable or explicit) can be seen in a dual fashion: a container of tokens a list of items For ...
egreg's user avatar
  • 1.1m
13 votes

Unbalanced dollar signs

As explained in chapter 24 of the TeXbook, a (category code 3) $ cannot be in vertical mode: if it is found when TeX is in vertical mode, horizontal mode is started and $ is reexamined. Chapter 25 ...
egreg's user avatar
  • 1.1m
12 votes
Accepted

How are parameter tokens (#1,#2,...,#9) processed?

tex macros have two kinds of argument, delimited and non delimited, for a non delimited argument the argument is either a single token, or if the token is an explicit brace (a character of catcode 1) ...
David Carlisle's user avatar
11 votes

When to use \tl_to_str:V and when \tl_to_str:N?

I see that schtandard has written an excellent answer, but thought I might elaborate a bit on the difference between n-, N- and V-type arguments. I'll also include a little history and TeXnical detail ...
Joseph Wright's user avatar
  • 262k
11 votes
Accepted

What happened to expl3's case changing functions? (e.g. \tl_upper_case:n and \tl_lower_case:n)

As the error message says, the function \tl_upper_case:n are now deprecated and should be replaced by \text_uppercase:n. The full list is: \tl_<some>_case:n(n) → \text_<some>...
Phelype Oleinik's user avatar
11 votes
Accepted

LaTeX3 - Check if an argument is empty

That is precisely how \tl_if_empty:nTF is defined: \documentclass[12pt]{article} \ExplSyntaxOn \newcommand\test[1] { \tl_if_empty:nTF {#1} { EMPTY } { FILLED } } \ExplSyntaxOff \begin{document} \...
Phelype Oleinik's user avatar
10 votes

How are parameter tokens (#1,#2,...,#9) processed?

Parameter tokens #1 to #9 are only relevant at macro definition time, so you're being misled when thinking to them. The macro \setarray has two undelimited arguments (because the parameter token are ...
egreg's user avatar
  • 1.1m
10 votes
Accepted

TeX's expansion rules: a case study with a token-list register

I'll skip over the three assignments and go straight to \the\toks1\noexpand\mac The \the primitive inserts the content of a register: here a \toks. After the \toks we need a number, so TeX goes ...
Joseph Wright's user avatar
  • 262k
10 votes
Accepted

When to use \tl_to_str:V and when \tl_to_str:N?

\tl_to_str:V is a variant of \tl_to_str:n, i.e. it retrieves the value of any variable you throw at it and passes it to \tl_to_str:n. \tl_to_str:N on the other hand expects a token list variable and ...
schtandard's user avatar
  • 15.4k
9 votes
Accepted

How to handle a LaTeX3 token list as a list of tokens rather than as a list of items?

You can use Bruno's gtl package for that. The package performs some extremely non-trivial tasks and has a lot of subtleties, so you have to read the documentation if you want to use it. At the same ...
Henri Menke's user avatar
9 votes
Accepted

How can I condition on the last token?

You can define a \stripdot command, which does the opposite of what you asked for - stripping a final "." - in two lines using only TeX primitives: \def\stripdot#1{\stripdotA#1\end.\end!{#1}} \def\...
wipet's user avatar
  • 75.7k
9 votes
Accepted

How to use \cs_generate_variant:Nn to compare token lists?

You have two issues. The first is that a V argument doesn't really make sense as variant for an N argument (that's why it's deprecated). When you get the Value of a variable, the result will not ...
Phelype Oleinik's user avatar
9 votes
Accepted

How to pass the the content from Lua function to a LaTeX3 token list (tl)?

You can set the tl (macro) from Lua: \documentclass{article} \usepackage{luacode} \begin{luacode*} function make_bibliography() local result = "\\textbf{Foo}" token.set_macro("...
David Carlisle's user avatar
8 votes
Accepted

Why \pgfkeyssetvalue uses a token list?

By using an intermediary toks register the user can store argument parameters (#1, #2) without having to manually double the # in the input. This means that things like \pgfkeyssetvalue{blub}{abc#1} ...
Ulrike Fischer's user avatar
8 votes

Why does the TeX scanner process tokens for register numbers and macro names differently?

What do you mean by "constructing a macro name"? At the time of reading/tokenizing input it is not important whether the control sequence token in question will denote a macro or a primitive ...
Ulrich Diez's user avatar
  • 29.7k
8 votes
Accepted

Avoid @ hackery: How can I preserve spaces in a format specification when processing the specification with expl3 and PGF/TikZ?

There are really two parts to this question, the specifics of the use case and the more general 'how to iterate with spaces' one. I'll tackle the two separately. For the specific case here of ...
Joseph Wright's user avatar
  • 262k
8 votes
Accepted

Can I test line break types? e.g. line endings of type LF or LFCR?

No, or at least not from the TeX end (LuaTeX is different: can use Lua). Line-end normalisation happens very early, before any TeX code gets to see anything. As such, all you will ever get is ...
Joseph Wright's user avatar
  • 262k
8 votes

Can I test line break types? e.g. line endings of type LF or LFCR?

Not only can you not tell what is the line end terminator you can not tell if there was a linebreak character at all, nor can you tell if there were any space characters at the end of the line. This ...
David Carlisle's user avatar
8 votes
Accepted

Extra space in cells when using token lists to build tabular content

As is often the case, the culprits are stray spaces introduced at the ends of lines. And because of the nature of the token list, which gets added to the tabular at the end of the process, all those ...
Steven B. Segletes's user avatar
8 votes

What is the difference between `put` and `gput` in `\tl_new:N` token lists?

Why is there one function to define (globally) e.g. a token list \tl_new:N, but there are two functions to put an element into it: \tl_put_left:Nn and \tl_gput_left:nN Because all variables are ...
Phelype Oleinik's user avatar
8 votes
Accepted

What is the difference between `put` and `gput` in `\tl_new:N` token lists?

I see that Phelype has covered the key points: here I'll try to give some context for the approach. To understand the ideas here, it's probably best to start with how TeX grouping works. As a macro ...
Joseph Wright's user avatar
  • 262k
8 votes

How to use \cs_generate_variant:Nn to compare token lists?

There is no reason to define variants (besides being wrong to begin with, in this case): \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl {true} {false} is already the thing to do (and yields false in your case)...
egreg's user avatar
  • 1.1m
8 votes
Accepted

Using expl3 to load geometry parameters from a file

\geometry doesn't expand it argument, it wants a key list as argument, not a key list hidden in some command. So nothing what you do inside the argument will work. Assuming that your key list is in a ...
Ulrike Fischer's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible