# Tag Info

## Hot answers tagged expansion

9

What did I get myself into. . . There are three possible ways: \def\outer{} and go on with your life. Hands down the best choice (in all aspects). I bet it's easier to implement \suppressoutererror in TeX than to write TeX code to do that. It's 2020, the year Knuth will address reported bugs in TeX. Submit \outer for consideration. I said ...

6

Let's try a Lua solution. We could use \suppressoutererror to make scanning easier but that wouldn't be much fun, so we scan individual tokens instead and manually try to keep track of nested braces. For every scanned token, Lua can access the "command id". This is kind of a generalization of catcodes. Especially, every catcode 1 ({) token has id 1, every ...

4

These things are probably difficult if you are “new to LaTeX.” Take your time to learn about tokens, character codes, category codes, expansion, etc. The TeXbook is a good reference to learn about all these. Explanation of the \if test The TeX primitive \if recursively expands what follows in the input stream until there are two unexpandable tokens. If ...

4

This introduces \countouters{<macro>}, which will count the occurrences of \outer macros contained in the argument. The result is stored in the counter outercnt. I had to make an adjustment to the logic of tokcycle token-digesting package (inserting an extra trapping level to look for pre-digested \outer macros) to accomplish this. The macro to be ...

3


3

To pass macros from TeX to Lua, a common idiom has to be followed: \directlua{whatever("\luaescapestring{\unexpanded{#1}}")} In ConTeXt some of the things have different names, so the idiom would read \ctxlua{whatever("\luaescapestring{\normalunexpanded{#1}}")} With that your code works without problems. \starttext \startluacode userdata = userdata ...

2

With your code a lot of unwanted space tokens come into being: Due to \endlinechar a return-character (of category code 5(end of line)) is added at the right end of every line. After producing character-tokens like {1(begin group) and }2(end group) and 112(other) (as in #1=#6(parameter)112(other)) the reading apparatus of (La)...

2

First off: as I've written several times, TeX is not free-form. There's a huge difference between \def\append#1 { \g@addto@macro\slist{#1,}% } and the code you probably want, namely \def\append#1{% \g@addto@macro\slist{#1,}% } With your code the argument to \append is determined as whatever comes after it up to the first space token. So if you write \...

2

As @UlrikeFischer and @DavidCarlisle pointed out, using \edef with arbitrary material is likely to cause errors. For instance, this will be the case with material containing \textbf, and there are plenty of other cases. Two ways in LaTeX2e style I present two techniques in LaTeX2e style that use \protected@edef so that macros defined with \...

2

As Phelype Oleinik, I am thinking that \meaning is a lead for this task. But, in my way, there is no checking all characters in \meaning result still only searching macro: sequence and following analysis previous characters for looking \outer. Perhaps, this solution is not so complete but it still work. \outertest implements basic work. It analyses getting ...

1

So the error I was getting with \tolua{\simple} doesn't have anything to do with \simple being expanded within the \ctxlua block, but simply that \s in "\simple" was triggering an invalid Lua escape sequence. Not the error I was expecting - I thought I'd have to use \noexpand. But this is all that needs to be done: \starttext \startluacode userdata = ...

1

You can build the command as a string where you can format the numbers using decimal and pipe it through scantokens which will read the supplied text as regular input. \documentclass{article} \pagestyle{empty} \usepackage{luamplib} \begin{document} \begin{mplibcode} input metaflow.mp; beginfig(0); z1c = origin ; z2c = (5cm,0) ; draw rrect1("1")...

1

\write works by pure expansion and your \myreplace command is not expandable (and cannot be). You need to do the replacement before passing the token list to the writing stage. \documentclass{article} \usepackage{xparse} %\usepackage{expl3} % already loaded by xparse \ExplSyntaxOn \NewDocumentCommand{\writefile}{smm} {% #1 = * if replacement is needed ...

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