# Preceding a command by an argument

\usepackage{amsmath,amssymb,amsopn}% read amsldoc.pdf for more details
%\genfrac{left-delim}{right-delim}{thickness}{mathstyle}{numerator}{denominator}
%\newcommand{\frac}[2]{\genfrac{}{}{}{}{#1}{#2}}
%\newcommand{\tfrac}[2]{\genfrac{}{}{}{1}{#1}{#2}}
%\newcommand{\binom}[2]{\genfrac{(}{)}{0pt}{}{#1}{#2}}
\newcommand[1]{\over}[1]{\genfrac{}{}{}{}{#1}{#2}}
\newcommand[1]{\tover}[1]{\genfrac{}{}{}{1}{#1}{#2}}
\newcommand[1]{\binomial}[1]{\genfrac{(}{)}{0pt}{}{#1}{#2}}


How do I precede a command by an argument?

Preferably answer the question by fixing the last 3 lines of the example above.

EDIT: The reason I need to do this is to reduce the time necessary to write notes, for quick note taking. For instance

%macros to make quick note taking easier all escapes try to keep at 3 chars or less
\def\t{\text }
\def\o{\over }
\def\to{\tover }
\def\part{\partial }
\def$${\left( } \def$${\right) }
\def${\left[ } \def${\right] }
\def\l{\left. }
\def\r{\right. }


by adding this in addition to the desired abilities in the original question above it means I can type

${\part f \o \part x}$


as opposed to

$\tfrac{\partial f}{\partial x}$

-
Although this is a rather interesting question on macro hackery, would you mind if I ask why would you want to do such a thing? The commands \frac and friends were introduced precisely because it's such a pain to work with \over and the like, where the “first argument” is not properly delimited. – Juan A. Navarro Sep 21 '10 at 18:52
I'll answer your question by editing question(above). – GlassGhost Sep 21 '10 at 20:02
What operating system and text editor? I think your best bet would be, rather than trying to define LaTeX commands, to define autocomplete methods in your editor, or a pre-processing script, to change what you type, when it matches a certain pattern, into something LaTeX can handle. – frabjous Sep 21 '10 at 20:24
@frabjous you mean like a perl script to find the regex and change it to the \frac form before it is handed to the compiler. I was thinking about that but am too frightened to do it.(i have Miktex) – GlassGhost Sep 21 '10 at 23:30
Yes, that is one possibility. (Probably use sed personally, but only because I don't know perl.) Another possibility would be if your editor could handle the substitutions automatically, e.g., through an autocomplete or autocorrect feature. That might be less scary, since you'd see it happen, but you didn't mention what editor you're using. – frabjous Sep 22 '10 at 1:55

You can't, that I know of. The way that TeX does \over is as a primitive not as a macro. You might consider some special environment that looks for the 'macro' as a delimited argument.

-
Well, of course you "could", maybe by redefining "{" and hoping that you don't break everything else in the process... – Juan A. Navarro Sep 21 '10 at 19:03
If you want to drive yourself mad, then go ahead! – Joseph Wright Sep 21 '10 at 19:32
I'm just saying :) – Juan A. Navarro Sep 21 '10 at 19:42

If you only need this for primitives, then your definitions work (at least on the minimal example that I tested). However, note that you are redefining a lot of core LaTeX macros: \part, \(, $, and \to. You can avoid some of these by using upper case names \PART, \TO, etc. Another option is to have a look at the nath package, which allows for automatic scaling of delimiters (no need to define \(' and[). It also defines many other shortcuts for easy typesetting of math. Note that nath clashes with amsmath, so you can only use one of them. - This doesn't directly answer your question, but how about this hack for typesetting fractions: \mathcode/"8000 {\catcode/13 \global\let/\over}  Now you want a fraction? No problem \[ -{3+x/x^2}$ gives you the fraction you would expect.

[Odd, I thought I already edited my answer.] If you want a \binomial that works, you could simply use

\newcommand*\binomial{\atopwithdelims()}


which is exactly how \choose is defined.

I'm not sure exactly what you want to do with \over since it already works the way you want. There's not an easy way to do something like \tover since the \textstyle has to come before the fraction itself.

-
I'm sure this works, but like you said; This doesn't directly answer my original question of how to use preceding arguments for commands – GlassGhost Sep 23 '10 at 20:56
@GlassGhost: That was already answered by Joseph. TeX's macros can only read tokens after it in the token stream. There are only four TeX primitives that I can think of that operate on preceding tokens: \over, \overwithdelims, \atop, and \atopwithdelims. However, it seems like these are exactly what you want. – TH. Sep 23 '10 at 21:29
Also \above and \abovewithdelims. – TH. Sep 25 '10 at 22:12
@TH. Would is make sense to try an unbox the result of \over? (I have not read the math chapters of the TeXbook.) If so, we could think of doing anything with the box made from the tokens preceeding our macro. – Bruno Le Floch Jan 7 '11 at 23:19
@Bruno: I'm not sure how one could get that box. \lastbox` doesn't work in math mode. – TH. Jan 8 '11 at 0:28