GeneralMessing with Command Arguments

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
pkledgrape
Posts: 4
Joined: Sat May 07, 2011 7:00 pm

Messing with Command Arguments

Post by pkledgrape »

Ok, I know this isn't the most TeX-like of coding, but I'm trying to make a mini-package for instructors of this one course at my Uni, and I'd like to make it very readable.

What I am looking for: a way to make a command that takes one input from its left side, and one from its right side.

I know this is possible, because there are commands in TeX such as \atop:
\atop takes in TWO inputs, and puts one on top of the other; but it does it by

Code: Select all

{a \atop b}
rather than the normal \atop{a}{b}.

However, I don't need something that does what \atop does at all: eventually, I'm trying to draw logic circuits that look kind of like a labeled version of those at http://www.texample.net/tikz/examples/s ... -diagrams/

I've worked out most of the details on how to tweak this example to get something that'll work like

Code: Select all

\cor{\cnot{p}}{\cand{q}{\cnot{p}}}
but would love to make it typeable as

Code: Select all

{\cnot{p} \cor {q \cand \cnot{p}}}
which I think will be easier for the instructors to write out and check for typos, since they'll be translating from a sentence that'll read something like "not p or (q and not p)"

So... despite it generally being ill-advised, does anyone know how I can make a new command that'll take one input from each side?

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Messing with Command Arguments

Post by josephwright »

It's not possible, at least in the general case. The TeX \atop primitive is not a macro: it's coded into the binary. So the syntax there is not defined in terms of some macro approach.

It is possible in some circumstances to create macros which look like they have similar syntax, but relies on delimited arguments. So something like

Code: Select all

\foo{ a \baz b}
can work if \foo is defined something like

Code: Select all

\def\foo#1{\@foo#1\stop}
\def\@foo#1\baz#2\stop{% do stuff
}
(In reality, this would need some sanity checks in case the user forgot \baz entirely.)
Joseph Wright
Post Reply