
如何使用定義命令宏,\newcommand
以便命令的參數被環境包圍?
答案1
證明這是可能的,並使用可選參數,該參數可以是b
或p
或任何已知前綴(例如v
、B
和V
)
除此之外:在我看來,它並沒有提高程式碼的可讀性。
\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}