|
|
|
|
|
by zauguin
1341 days ago
|
|
You don't have to define `\First` and `\Second` since these are predefined as `\@firstoftwo` and `\@secondoftwo`. Also the Unicode bytes are already active so setting their catcode is useless. Also redefining the first octet breaks LaTeX's UTF-8 handling and the else case forms an infinite loop. Changing the catcodes of `(` and `)` means that this command doesn't work in the arguments of other commands and it breaks other uses of `(` and `)` in the argument. Instead you could do this as \documentclass{article}
\usepackage{xparse}
\NewDocumentCommand \LambdaCalc {u{.} r()} {%
[arg:(#1) body:(#2)]
}
\DeclareUnicodeCharacter {03BB} {\LambdaCalc}
\begin{document}
λx.(2x)
\end{document}
|
|
> these are predefined as `\@firstoftwo` and `\@secondoftwo`
I do wish LaTeX kernel commands (which I'm assuming these are) were more widely documented. As it stands, it's pretty hard to keep track of what already exists. Is there a nice reference for those?
> Also the Unicode bytes are already active so setting their catcode is useless.
This is true for LaTeX and not TeX, correct? Originally, I'd `\expandafter\let\expandafter\@firstoct\@firstoftwoλ`, but I decided not to assume that that character was already active.
> Also redefining the first octet breaks LaTeX's UTF-8 handling...
How so? (If the else case wasn't broken)
>...and the else case forms an infinite loop.
If `\Firstλ` was not an active character, would this still be true? Since I store `\Firstλ` in `\lambda@first@oct` before it's declared an active character.
> and it breaks other uses of `(` and `)` in the argument.
This is not a concern for the DSL, but...
> Changing the catcodes of `(` and `)` means that this command doesn't work in the arguments of other commands
...this is. Thanks.
> Instead you could do this as
Damn :)
Thanks for the nice feedback. I suppose I should read up on xparse. In any case I feel like it's not moot to try to achieve the same results with primitives, to have some idea of what's breaking when a given program doesn't compile (usually at that point the primitives surface).