Out of curiosity I wanted to find the limits of TeX regarding macro definitions. Assume there should be an assignment command which assigns the value of an already defined macro to a yet undefined macro, so something like
\def\newVariable{\variable}
just with the syntax usually find in other languages, i.e. using the equal sign as an assignment operator.
I guess it's not possible to write
\newVariable = \variable
as this results in an 'Undefined control sequence' when \newVariable is read. Is it possible to hook into the execution of whatever detects the undefined control sequence and look ahead with @ifnextchars for an equal sign and an macro?
What were if we'd write
newVariable = \variable
Now this should at least run without error. When \variable is expanded, is there any chance to remove the text newVariable = from the output string again (do some sort of rewinding) and use it in \variable as an option similar to \variable{newVariable}? So I guess here I would look for something like \@iflastchars. I am all open for bizarre solutions with all TeX flavours like finding the string in the output routine or in the aux or even in the PDF file produced by the last run (or any of the other output files).
I guess the answer will be "this is not possible", but as there are a lot of smart people around liking a challenge, I thought I'd give it a try. Please note, that I am fully aware of the solution with the normal TeX syntax so this is a more a theoretical exercise.
\variableto be expanded? (It doesn't get expanded in\def\newVariable{\variable}.) – Ian Thompson Oct 08 '12 at 18:45=for assigment, you just have to use\letas well:\let\newVariable = \variable. You can use=for counters and lengths:\c@section = 5,\footskip = 5mm. However, in LaTeX, you better avoid these low-level format if you don't need them. You must think of (La)TeX as of a "different programming language" that has its very strange specifics ;) – yo' Oct 08 '12 at 18:47\variablewould be expanded after reading the equal sign, as otherwise there is no chance of changing the execution. If it gets expanded it could do whatever it wants to hide the expansion to the outside if that is wanted. If you find a solution without expansion that would also be great. – Patrick Häcker Oct 08 '12 at 18:54\letis left of the\newVariable(it's the same with\def) or because the thing is already defined (for counters and lengths). I guess my question could be reformulated as: Is this possible with yet undefined macros without having a macro like\leton the left? – Patrick Häcker Oct 08 '12 at 18:58=as a "text" and "math" character with its real meaning to the "normal" people. I think that doing this is impossible because TeX reads its input lineary and invokes an error on an unknown macro in the input sequence. – yo' Oct 08 '12 at 19:11=active, but beside the problems you mentioned, it would also be too late, as thenewVariablewould have already been read and we again would have the same problem as before. – Patrick Häcker Oct 08 '12 at 19:22\declarevariable\variableyou can define\variablesuch that later\variable={something}will execute the assignment. – Stephan Lehmke Oct 08 '12 at 19:35\double \newVariable = \variable, where the\doublecommand could take care of creating\newVariableand ensuring its type. This is fair enough, although there are languages which allow using a variable before declaring it (though this might indeed be a bad idea). – Patrick Häcker Oct 08 '12 at 19:44\newVariable=\variablecould be an alternative syntax to\let\newVariable=\variablebut you give the example of being like\def\newVariable{\variable}which is a very different assignment. It is of course possible to do this if you make\active but that then makes you incompatible with everything so you'd have to rewrite latex (or whatever other format you use). Most other macro language aslo need a define keyword not just an infix=think#definein C pre-processor . – David Carlisle Oct 08 '12 at 22:42\variablein\def\newVariable{\variable}will work even before declaring\variable. Apart from theoretical musings, I'd like to point out that setting this kind of thing into action needs really deep knowledge of the inner workings of TeXs macro processing. If you `just' want to use TeX productively, then it would be much better to acquire a better understanding of the way things are supposed to be instead of trying to turn TeX into another language. – Stephan Lehmke Oct 09 '12 at 03:28\letand\def. I just had the case of defining basically a primitive constant and then it does not matter much which of both is used. – Patrick Häcker Oct 09 '12 at 19:18