I want to simplify codes for writing vectors. For example, if I write


it would be equivalent to

\begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}



would be

\begin{bmatrix} 1 \\ 2 \\ 3 \\ 4 \end{bmatrix}

How can I create a macro for this type of work?

3 Answers 3


The stackengine package already supports this construction with \bracketVectorstack, which I bundle in the form asked for by the OP. Of course, it is not actually using bmatrix.

Note that if matrix construction is needed rather than vectors, look for the extensions provided by the tabstackengine package. Also, the inter-row baselineskip can be altered with, for example, \setstackgap{L}{1.2\baselineskip}.

X = \Vector{1,2,3,4} \ne \Vector{1,x,3}

enter image description here


The splitting is quite easy with expl3 syntax and a wrapper command, say \feqvector. This example does allow for setting the separator and the type of the matrix, say b or p or any other allowed type.



\clist_new:N \l_feq_vector_clist
  \clist_set:Nn \l_feq_vector_clist {#2} % Set the list
  \clist_use:Nn \l_feq_vector_clist {#1} % show it with separator from #1 (\\)

A few: $\feqvector{1,2,3}$

More of them: $\feqvector{1,2,3,4,5}$

horizontal: $\feqvector[&]{1,2,3,4,5}$

Now with parenthesis and horizontal: $\feqvector[&]{1,2,3}[p]$

enter image description here

  • There should not be braces around N arguments (although in many cases they do no harm); there's no need to clear the clist, if you set it afterwards.
    – egreg
    Commented Sep 29, 2015 at 21:05

If you can accept a bit different syntax (one character more in the first case), there is a simple solution:

\def\vector#1.{\begin{bmatrix} #1 \end{bmatrix}

with usage

\vector 1\\2\\3. or \vector 1\\2\\3\\4.

Certainly, dot as the end of argument(s) is only an example.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .