Tagged Questions
3
votes
2answers
84 views
List of tokens from TeX mouth
Is it possible to get list of tokens which comes from TeX "mouth"? If I understand correctly: in mouth all macros, conditionals and special operations (like \the and \input) are expanded and then goes ...
14
votes
3answers
184 views
Parsing strings containing diacritical marks (macros?)
I apologize that this question may seem very much like several other recent ones I have asked (Parsing leading hardspaces, Parsing a \$ as part of an improved \getargs command). They are all related ...
5
votes
2answers
97 views
Variadic arguments macro
I am trying to make macro with variadic arguments, iterating over them.
The final result is supposed to be:
\foreach[x]((var = \x )){foo}{bar}{baz}\null
evals to
var = foo var = bar var = baz
My ...
7
votes
2answers
105 views
Is there a way of defining a command \nullifyifmoved{arg} that will normally act like its argument but act like a no-op if the macro is “moved”?
I'm interested in a macro \nullifyifmoved that takes one argument arg and acts like arg in normal contexts, except it acts like a no-op wherever it is written to a file. Some background:
Martin ...
5
votes
3answers
98 views
Metacommand for commands that dynamically select a parameter?
Original question
I would like to create a metacommand for creating new projection commands. Specifically, \newproj{\cmd}{<n>}{<m>} should create \cmd as a new command of <n> ...
4
votes
1answer
54 views
Error with expansions
I am getting an error while trying to compile this minimal example:
min.cls:
\ProvidesClass{min}
\LoadClass{minimal}
\NeedsTeXFormat{LaTeX2e}
\newenvironment{myenv}{}{
\def\aaa{test }
...
35
votes
3answers
774 views
Advantages and disadvantages of fully expandable macros
As I currently understand them, fully-expandable macros are analogous to pure/effect-free functions in functional programming. Correspondingly, things that are not expandable, such as \def, are ...
22
votes
3answers
519 views
How to know whether or not we need \expandafter?
The following is quoted from Peter Grill's answer on question LaTeX dynamic macro definition.
The \expandafter is requried as the \newcommand needs to be dealt
with after the \csname.
As a ...
25
votes
1answer
345 views
Why six \noexpand in a row?
Trying to understand TeX's rules for parsing dimensions, I came up with the following weird behaviour:
\dimen0=1\noexpand\noexpand\noexpand\noexpand\noexpand\empty pt
is valid, but
...
10
votes
3answers
220 views
Expandable 'character scanning' command that preserves spaces
David Carlisle recently offered a clean and rather elegant TeX solution to a question about expandable 'character scanning' commands. Unfortunately, David's solution does not preserve spaces in the ...
42
votes
0answers
1k views
A LaTeX log analyzer application (visualizing TeX expansion)
Consider the following MWE, test.tex:
\documentclass[12pt]{article}
\begin{document}
\tracingassigns=1
\tracingmacros=1
\def\aaa{something}
\def\bbb{else \aaa, else}
\edef\ccc{third \bbb, level}
...
5
votes
1answer
242 views
A \typeout (or expandable command) that can expand once - or with variable levels of expansion?
Consider the following MWE:
\documentclass[12pt]{article}
\begin{document}
\def\aaa{something}
\typeout{=1==\aaa==}
\typeout{=1==\meaning\aaa==}
\typeout{}
\def\bbb{else \aaa, else}
...
2
votes
2answers
173 views
An expandable 'character scanning' command?
Please consider the following MWE, for a "character scanning" command "\looper" which utilizes \@tfor:
\documentclass{minimal}
\usepackage{trace}
\makeatletter
\newcommand\looper[1]{%
% ...
3
votes
1answer
128 views
Showing expanded `\let` command with `\typeout`
I have already seen the related page macros - What is the difference between \let and \edef?, but I'm afraid it still doesn't expain to me the following MWE:
\documentclass{minimal}
...
5
votes
2answers
221 views
On unprotecting (expanding) \protected macros (or, “the space after command name”)
I quite often come into a situation, where I need to obtain some text produced by a package macro as a string, like in say:
Expanding (edef) a lipsum command?
How do I "unprotect" an ...
8
votes
2answers
134 views
Execute non-expandable code inside a tabular environment
As there is no Expandable version of \InputIfFileExists or \IfFileExists, the question arises whether it is possible to execute non-expandable code in a tabular environment after all:
File main.tex:
...
7
votes
2answers
258 views
Force the expansion of a macro parameter without \edef or \xdef
Two days I am looking for a solution but I have no more idea. This is my problem.
I'm trying to create a macro to automatically define new other macros to write references in a document. I want to ...
11
votes
2answers
382 views
\expandafter within a \begingroup … \endgroup [duplicate]
Possible Duplicate:
What does \begingroup\expandafter…\endgroup do?
In many of Heiko Oberdiek's packages one sees this type of construction:
...
5
votes
1answer
134 views
How to extend the \romannumeral-based \fullyexpand to handle empty/all-space arguments?
In Expandable full expansion of tokens that preserves catcodes, Joseph Wright presents the following code:
\long\def\fullyexpand#1{%
\csname donothing\fullyexpandauxi{#1}{}%
}
...
12
votes
2answers
214 views
Get the lion to run in loops. Tersely
Various constructions can cause TeX (aka the lion) to go into an infinite loop. The simplest example is \def~{~}~, which defines ~ to expand to itself, then expands it. Now, if we exclude macro ...
12
votes
4answers
443 views
Detokenizing without extra spaces?
I have a need to pass through potentially arbitrary characters untouched and found this macro:
\def\test#1{\expandafter\zap@space\detokenize{#1} \@empty}
The problem is that \detokenize inserts ...
9
votes
1answer
633 views
Expansion in \numexpr…\relax versus \pdfstrcmp
The \numexpr...\relax construction in eTeX allows to evaluate numerical expressions, and it expands tokens fully as it goes.
The \pdfstrcmp{...}{...} construction in pdfTeX lets us compare two lists ...
52
votes
3answers
864 views
Why isn't everything expandable?
TeX's macro processor does its work in a process called expansion. For an input stream of tokens, the macro processor repeatedly expands them until non-expandable tokens remain. The resulting stream ...
21
votes
4answers
350 views
Can one define an expandable command that removes control sequences from its argument?
I am trying to create an expandable command that accepts a single argument that may contain control sequences, and expands to that same argument with all control sequences and braces removed. That is:
...
6
votes
1answer
301 views
Use \csname … \endcsname to compute the starred-version of some command
I want to define some commands declaring paired delimiters using the mathtools package in LaTeX. For example, \paren{...} should result in \left(...\right), whereas \paren[Big]{...} should give ...
11
votes
3answers
283 views
TeX macro and command expansion?
I have implemented couple of macros that should remove commas from numbers. It's nasty dirty stuff, but it works when input is number:
\removecommas{12,34,56.7} % => 123456.7
But it stop working ...
8
votes
4answers
247 views
Does macros get applied to the source code before compilation?
I wonder if this is true.
The latex compiler first run though the document, and search for all the macro declarations.
the compiler then go though the document, apply each macro as a string ...
24
votes
4answers
432 views
Why isn't a command defined by \newcommand with an optional argument expandable?
In trying to fix a problem with a nested macro repeatedly calling itself, I tried expanding the inner call before passing it as an argument to the outer one. This failed miserably because the macro ...
6
votes
1answer
576 views
How do I examine a token?
... let me count the ways.
I can test it with \if and \ifx
and \show its \meaning
And there I stop, both in my knowledge and my poetic ability (though some might argue that the latter never ...
14
votes
3answers
733 views
Does `\noexpand` have to be a primitive?
Background: I'm trying to deepen my understanding of TeX and how the intricacies work (spurred a little by this place, I should say, and hoping one day to not be a "Cargo Cult Programmer" - see When ...
12
votes
3answers
288 views
Expansion of first token in a tabular cell
Background
I currently do some work on the collcell package which collects the content of a tabular/array cell and provides it to a user defined macro, e.g. using ...
8
votes
2answers
242 views
reversing the order of expansion
Is there a non-expl3 expandable function for reversing the order of expansion of an arbitrary number of tokens or macros? For example,
\reverseexpansion<n>\a\b
...
17
votes
5answers
1k views
Are there purely expandable variants of \MakeUppercase?
\MakeUppercase and \uppercase use TeX's uccode, and they are not purely expandable. Say,
\edef\temp{\MakeUppercase{abc}}
will fail.
Sometimes purely expandable macros are very useful. They are ...
10
votes
1answer
399 views
How to do \scantokens inside \edef without triggering “Runaway definition”
I'm trying to find a way to use the e-TeX \scantokens command inside [the equivalent of] an \edef (well, actually an \xdef, but presumably this does not make any real difference since that's just the ...
6
votes
3answers
181 views
Are we inside an edef?
How would you test whether we are in an expansion only context (i.e., \edef, \xdef, \write,...) or not? The only ways I could think of leave things behind (but the full expansion of that extra stuff ...
5
votes
2answers
334 views
Using \input vs. \scantokens in section title (with package hyperref)
I meet the following issue when trying to use \scantokens in section titles, together with the hyperref package (whithout this package, all is fine).
\protect\input... can appear in a section title. ...
11
votes
2answers
597 views
Tricks to make macros expandable
Expandable macros are useful (I find working in the lion's mouth super cool). But they are difficult to write.
Can more experienced users give hints that help achieve expandability?
For example, we ...
33
votes
3answers
2k views
What is the difference between \let and \edef?
When you write
\edef\a{\b}
\let\a\b
the results are often identical. What is the difference between these two commands? When do they behave the same? When do they not?
(The question isn't for me; ...
7
votes
3answers
460 views
\aftergroup a list of tokens
\aftergroup executes the next token after the end of the current group. Is there a variant, \Vaftergroup{\some\tokens\a\b} that would put \some\tokens\a\b after the current group ends? Of course, one ...
21
votes
4answers
496 views
Can one define a '\superexpandafter{n}' that would expand to 2^n-1 '\expandafter's?'
This question was inspired by comment banter in this question. See title.
22
votes
2answers
637 views
Why do we need eleven expandafters to expand four tokens in the right order?
In Appendix D - Dirty Tricks Knuth gives an example of expanding four tokens in the right order by using eleven \expandafter commands. Here, is the code slightly adapted for to-morrow!
...
14
votes
2answers
760 views
How to add a hook to a macro
LaTeX uses hooks extensively, one method employed is the command g@addto@macro. It is defined in source2e as:
\long\def\g@addto@macro#1#2{%
\begingroup
\toks@\expandafter{#1#2}%
...
15
votes
1answer
428 views
How do I ‘expand’ a control sequence `\let` to a character?
Consider the following:
\let\1=X
\edef\2{\1}
\show\1 \show\2
The result is
> \1=the letter X.
> \2=macro:
->\1.
Is it possible to ‘expand’ the meaning of \1 so that \2 contains just ...
18
votes
1answer
616 views
Why do the definitions of \quad, etc. have \relax in them?
Plain Tex defines \quad so:
\def\quad{\hskip1em\relax}
Why is the \relax there? It's usually used as a token that can't be expanded, serving as a "do nothing" operation after macro expansion is ...
66
votes
4answers
10k views
When to use \edef, \noexpand, and \expandafter?
I'm quite happy hacking TeX macros and cobbling together bits and pieces from different style files to suit my own ends, but I have a suspicion that my resulting hacks are not quite as elegant as they ...
