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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.