TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

share|improve this question
Have a look at tex.stackexchange.com/q/15716/3240 – Thorsten Jun 2 '11 at 14:07
up vote 5 down vote accepted

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.

share|improve this answer
Thanks, that's nice! – student Jun 2 '11 at 14:41
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} \]
share|improve this answer
very nice! – Ian Thompson 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

share|improve this answer
... incidentally, this solution helps me a lot. Thanks! – Reinhard Neuwirth Aug 5 '15 at 4:53

Here is a solution that uses the xparse package:

share|improve this answer
\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.

share|improve this answer

Your Answer


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.