1

I want the following code to be a new command with two parameters (x and y):

\begin{bmatrix}
x \\
y 
\end{bmatrix}

how can I do that?

Coffeman
  • 13
  • 3

1 Answers1

2
\newcommand\ctwo[2]{%
\begin{bmatrix}
 #1\\
#2 
\end{bmatrix}}

then

\[
\ctwo{1}{2} + \ctwo{3}{4} = \ctwo{4}{6}
\]
David Carlisle
  • 757,742
  • Thank you that worked, although I have to wrap each \ctwo{x}{y} command in $$'s. Also why is there a "%" in the macro, doesnt that indicate a comment line? – Coffeman Dec 14 '21 at 17:39
  • 2
    @Coffeman use \[ as I showed not $$ and as shown here you should not have to wrap each \ctwo in math unless that is the entire expression. https://tex.stackexchange.com/questions/503/why-is-preferable-to/69854#69854 for % see https://tex.stackexchange.com/questions/7453/what-is-the-use-of-percent-signs-at-the-end-of-lines-why-is-my-macro-creat – David Carlisle Dec 14 '21 at 17:46
  • Thank you a lot for your help and information! – Coffeman Dec 14 '21 at 17:49