# How to make functions

I’m not entirely sure here what terminology I should exactly be using, but let me illustrate a use case.

...
\matr{1 & 2 \\ 3 & 4}
...


to replace this:

...
$\left[\begin{matrix} 1 & 2 \\ 3 & 4 \end{matrix}\right]$
...


How would I go about defining \matr{...}?

• @doncherry: Other unnecessary edited stuffs were done just for passing the 6-character constraint. – kiss my armpit Oct 19 '13 at 15:56

Nothing to it, really :)

For more details on how to define custom macros in LaTeX, have a look at this section of the LaTeX wikibook.

\documentclass{article}

\usepackage{amsmath}

\newcommand\matr[1]
{%
\ensuremath
{
\begin{bmatrix}
#1
\end{bmatrix}
}
}

\begin{document}
\matr{1 & 2 \\ 3 & 4}
\end{document}

• Why not bmatrix? – egreg Oct 19 '13 at 17:14
• @egreg You're absolutely right. – jub0bs Oct 19 '13 at 17:23
• I'd suggest you encase the argument of \matr in an \ensuremath statement instead of a pair of \$ text-mode/inline-math switches. That way, the command \matr will work equally well in text mode, inline math mode, and display math mode... – Mico Oct 19 '13 at 17:33
• @Mico That's a good idea. – jub0bs Oct 19 '13 at 17:51