I'm trying to create a new command in LaTeX that will let me do


Like this:


I can make two functions, one for the begin and one for the end bmatrix, and that works, but I'd like to make it work with one command. The issue with that is there can be any number of variables in the command. I've looked around and found some answers showing how to do it if you have, say, an optional second variable only. I'm trying to make this work with any number of arguments.

  • 7
    You should try with \newcommand{\m}[1]{\begin{bmatrix}#1\end{bmatrix}}...
    – Werner
    Commented Jan 8, 2016 at 21:21
  • Oh...... I don't know why I thought I needed multiple arguments, I guess everything is going in one whoops! If you make an answer I'll mark it best
    – Nat
    Commented Jan 8, 2016 at 21:26
  • 3
    Just a comment: it's usually best to avoid very short names for macros. Although \m isn't taken, lots of others are. See Short names for macros.
    – Alan Munn
    Commented Jan 8, 2016 at 21:41

1 Answer 1


If you'd like a command where you can pass a single argument as a comma-separated list, rather than using \\ inside the argument (like Werner suggested), you could do the following:


\usepackage{etoolbox} % needed for the \forcsvlist command





enter image description here

  • 2
    This code looks familiar. :) I was just about to post it.
    – Alan Munn
    Commented Jan 8, 2016 at 21:38
  • 2
    @AlanMunn Thanks for the edit. And sorry for stealing your thunder (and code) :p
    – Adam Liter
    Commented Jan 8, 2016 at 21:47

You must log in to answer this question.

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