How can I define a command macro using \newcommand
so that the argument to the command is surrounded by an environment?
1 Answer
A proof that it is possible and using an optional argument that can be b
or p
or anything of the known prefixes (e.g. v
, B
and V
)
Besides that all: It does not improve readability of the code, in my point of view.
\documentclass{article}
\usepackage{amsmath}
\newcommand{\mat}[2][b]{%
\begin{#1matrix}
#2
\end{#1matrix}
}
\begin{document}
$\mat{ 1 & 2 \\ 3 & 4 \\}$ and $ \mat[p]{ 1 & 2 \\ 3 & 4 \\}$ and $\mat[B]{ 1 & 2 \\ 3 & 4 \\}$ and $\mat[v]{ 1 & 2 \\ 3 & 4 \\}$ and $ \mat[V]{ 1 & 2 \\ 3 & 4 \\}$
\end{document}
\newcommand\mat[1]{\envname #1\endenvname}
must be used. Sometimes, not even that works.align
)