[Tex/LaTex] How to make functions

macrosmath-operators

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

Best Answer

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}