[Tex/LaTex] macro for writing vectors

macrosvector

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

\vector{1,2,3}

it would be equivalent to

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

Similarly

\vector{1,2,3,4}

would be

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

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

Best Answer

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}.

\documentclass{article}
\usepackage{stackengine}
\newcommand\Vector[1]{\setstackEOL{,}\bracketVectorstack{#1}}
\begin{document}
\[
X = \Vector{1,2,3,4} \ne \Vector{1,x,3}
\]
\end{document}

enter image description here

Related Question