Consider the follwing command:

 \newcommand{\vektor}[3]{\left(\negthinspace\begin{smallmatrix}#1\\#2\\#3    \end{rsmallmatrix}

I can use it like


Now my question is whether it is possible to redefine the command such that the arguments are a comma separated list, such that I could write:


It's easy to do this sort of thing using \def, if you don't mind putting the argument inside delimiters that are not braces.

\def\vektor(#1,#2,#3) {\left(\negthinspace\begin{smallmatrix}#1\\#2\\#3 \end{smallmatrix} \right)}
\[ \vektor(a,b,c) \]

Obviously, the above would go horribly wrong if you replace the parentheses with braces.


See Ryan Reich's answer (or Aditya's comment) for a neat modification that allows you to use braces.

  • 1
    Actually, it is easy to go from this solution to one that uses braces. \def\vektorwrapper#1{\vektor(#1)}.
    – Aditya
    Jun 2 '11 at 15:39

You can do it with \def and braces too, if you use two steps to hide Ian Thompson's code inside another macro.

\def\innervector(#1,#2,#3) {\left(\negthinspace\begin{smallmatrix}#1\\#2\\#3 \end{smallmatrix} \right)}
\[ \vektor{a,b,c} \]
  • very nice! Jun 2 '11 at 14:41
  • That's cheating!
    – Seamus
    Jun 2 '11 at 15:09

As an after thought. You can make it a lot more general with a variable number of arguments and different row or column delimiters


        \my@vector #2,\relax\noexpand\@eolst%

\def\my@vector #1,#2\@eolst{%
      \my@vector #2\@eolst%

$x   = \myvector{1,2,3,:}$ and
$x^T = \myvector[,&]{1,2,3,...}$

This will give

enter image description here

  • ... incidentally, this solution helps me a lot. Thanks! Aug 5 '15 at 4:53

Here is a solution that uses the xparse package:

\usepackage{amsmath} % for smallmatrix

  \lowercase{\endgroup\def\vekcomma{\mathcode`\,=\string"8000 \def~{\\}}}


You are not limited to three components. The a,b part is to show that uses of the comma outside the argument of \vektor are allowed.

The fact that \left-\right make a group is fundamental, because this ensures that changes to the \mathcode of the comma are confined to that place. The special mathcode "8000 means that the comma behaves like an active character; the definition of the active comma is given in an indirect way, so as not to conflict with possible other meanings as an active character.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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