Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

With newcommand I can define customized command like \ABC. Is there any way to define a command with arguments. For example I want \brat{A}{B} be the same as [\![A,B]\!].

share|improve this question
    
Just to make sure: You want use to round parentheses and one comma (and no spaces) to set off the two parameters? –  Mico Jul 13 at 12:32
    
No, I want to feed the arguments, I don't know how. –  user69453 Jul 13 at 12:33
    
So would \brat{A}{B} be acceptable syntax? –  Mico Jul 13 at 12:35
    
\newcommand\ABC[3]{Something with #1, #2 and #3} where the number is the number of parameters. –  Manuel Jul 13 at 12:42
    
This might be relevant: tex.stackexchange.com/questions/28042/…. –  Ethan Bolker Jul 13 at 13:38

1 Answer 1

up vote 12 down vote accepted

The general form of \newcommand is

\newcommand\commandname[number of arguments][value of optional argument]{code}

(Most of the time there won't be an optional argument, in which case this is omitted.) The arguments are given as #1, #2 etc in code.

To define your \brat command you would write

\newcommand\brat[2]{[\![#1,#2]\!]}

You then use this macro by writing \brat{A}{B}, \brat{A}{C} and so on. If almost all of the time you wanted the first argument to be A then you could instead use an optional first argument and define

\newcommand\Brat[2][A]{[\![#1,#2]\!]}

You use this version of the macro n almost exactly the same way except that you do not need to specify A: so \Brat{B} produces the same as \brat{A}{B} before. To change the value of the optional argument from A to C, say, you would write \Brat[C]{B}. This is the same as \brat{C}{B} using the first macro.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.