4

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

1
  • @doncherry: Other unnecessary edited stuffs were done just for passing the 6-character constraint. Commented Oct 19, 2013 at 15:56

1 Answer 1

8

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}
4
  • 1
    Why not bmatrix?
    – egreg
    Commented Oct 19, 2013 at 17:14
  • 1
    @egreg You're absolutely right.
    – jub0bs
    Commented Oct 19, 2013 at 17:23
  • 1
    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
    Commented Oct 19, 2013 at 17:33
  • @Mico That's a good idea.
    – jub0bs
    Commented Oct 19, 2013 at 17:51

You must log in to answer this question.

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