The problem has been examined under a different point of view in Is a command with an argument before and after the command possible? but the situation is different: the object that was to be placed before or after the main command is itself a macro.
It's not possible to have a macro that “looks backwards”. TeX is strictly “first in, first out”, after macro expansion. Moreover it tokenizes the input only when needed for supplying arguments to macros or primitives.
After macro expansion, only unexpandable tokens remain and they are executed in the order they are found and removes them. So in a situation such as
{abc}\macro{def}
the {abc}
part is already gone when \macro
is examined. Trace of it can remain in some of the internal lists, so, for example, TeX is able to execute \unskip
which really is a command that, upon execution, removes the last node from the current list, provided it is glue (there are hairy details, but this is basically the truth).
A command that seems to do what you want is \over
. However, this is not a macro, but a primitive.
Its work is performed at the level of the internal lists: when TeX finds \over
, it executes it, because it's unexpandable. The execution consists in storing whatever is in the current math list in a special place and go on. When the end of the current math list is found, TeX uses it and the stored part to build a Frac atom with the head sublist as numerator and the tail sublist as denominator. But nothing of this happens at the macro expansion level.
You can have a macro \first
that looks ahead after its argument to see if a macro \second
comes along and then take appropriate decisions about what to do.
Even LuaTeX can't do it, unless you modify the macro processor, because it can examine and manage all types of nodes in the current list, while TeX abilities are more limited (only penalties, glues, kerns and boxes and not in every situation).
lettrine
. Only problem: Sometimes there are quotation marks before the calligraphic letters.lettrine
can handle this, provided that I can tell it to. But that requires such a command.$a \over b$
and$a \choose b$
are examples of (something pretty close to) what you want. However, I don't know how those are defined. (Yes, I really need to read the TeX-book, but I still haven't had the time for it.)\over
is very different: first of all it's not a macro, but a primitive. When TeX finds it, it stores whatever is in the current math list, determines the denominator and then builds the Frac atom. With macros it's not possible: TeX strictly expands in the order tokens are created and after expansion or execution it discards the items.