GeneralMaking a command that can take input from the left

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

Making a command that can take input from the left

Post by pkledgrape »

I'm inspired by the format of

Code: Select all

{n \choose k}
(which I know is not as preferred as \binom{n}{k}, but it suggests to me that what I hope to achieve is possible). So perhaps let's recreate that as the minimal example?

I want to write a new command which will take its first input from the left, and its second from the right. What I'm used to is something like

Code: Select all

\newcommand{\newchoose}[2]{\left(\begin{tabular}{c}$#1$\\$#2$\end{tabular}\right)}
which you could then call by saying,

Code: Select all

$\newchoose{n}{k}$
But I really wold like to make a new command that would do the same thing, but instead be callable by

Code: Select all

${n \newchoose k}$
Is \newcommand still the appropriate place to do this?
Is such a command even possible upfront, or is something like {n \choose k} only viable because of crazy backend package stuff?
And of course, if this is possible, how would I do it?

Thanks for reading : )
Last edited by pkledgrape on Sun May 08, 2011 1:11 am, edited 1 time in total.

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Making a command that can take input from the left

Post by Stefan Kottwitz »

Hi,

welcome to the board!

\choose is defined using the TeX primitive \atopwithdelims which works this way, it's equivalent to \atopwithdelims().

Though it's interesting, using this kind of syntax is not very recommendable. Reasons are described in the amsmath technical notes.

Stefan
LaTeX.org admin
pkledgrape
Posts: 4
Joined: Sat May 07, 2011 7:00 pm

Making a command that can take input from the left

Post by pkledgrape »

Thanks for your reply! I now know more about the motivations and backend of LaTeX.

Ok, so \atop (and \atopwithdelims) are how \choose, in particular, is made - and based on what the linked document says, this is exactly why people prefer \binom now.

Maybe I should not be so cagey about what I'm trying to do though, as I don't really need to recreate the \choose function, so much as get a new command that takes input in the same way as \choose or \atop: one input from the left, one from the right. I think I understand the risks involved re: formatting, but I'm working toward a pretty specialized purpose where I'm not so concerned about this:

I hate all the examples I've found online of drawing logic circuits: the simple gated ones, where you have labels of things like "p" or "~q", where series means "and" and parallel means "or". I'm still pretty new to LaTeX, and have just been drawing everything by hand, point-by-point, in tikz. I'd really love to instead make a very user-friendly code that anyone (in particular, the other instructors in my department) can copy/paste into their quizzes/tests/example sheets. My vision is that a statement that you'd write out as "(p V ~q) ^ r" could be displayed in circuit-form by

Code: Select all

{{p \or \not{q}} \and r}
instead of

Code: Select all

\and{\or{p}{\not{q}}}{r}
(yes I know \not already means something else... still trying to decide if, for the purposes of this one class, we care little enough about the original \not that I can \renewcommand it, or whether I should just do \n or something)

What I'm aiming for is something that reads like how you'd actually write the statement, so that a frazzled instructor on a deadline who isn't necessarily that comfortable with LaTeX but using it nonetheless can diagram the circuit they want to ask their class about without much of any learning curve. The idea is to get things to nest like here: http://www.texample.net/tikz/examples/s ... -diagrams/
but of course, with that charming one-input-from-each-side. Which I can't figure out how to get. Which may still be inadvisable, but I think that since the inputs are only every going to be single letters or \not{} where the input of not is a single letter, it shouldn't be too bad.

Augh and now this is ridiculously detailed and babbly. Thanks so much if you've read this far! I really appreciate the above information, and welcome further thoughts on how to get a new command to take inputs from the left.
Post Reply