[Tex/LaTex] Most useful LaTex -macros? Help me to understand a statement with `\[p][s][frac|mat]`

macrostex-core

I want to understand the below, source here. I am studying material related to real-time-Texing like here.

As for fractions and matrices, I prefer using LaTeX macros instead of snippets. The most useful macros I use are the \[p][s][frac|mat]:
fraction or matrices, with parenthesis if there is the ā€œpā€, small if
there is the ā€œsā€ (small means suitable for in-line math). Analysts may
want to have macros for (partial) derivatives; and remember that to
write differentials you have to write \mathrm{d} t, not simply d t!
The macros file I use is here (use it with usepackage{Commons}).

Please, provide examples how to use the "most useful macros" there and do not hesitate to recite. I can understand \frac 12 i.e. half i.e. 0.5 but what does this \[p][s][frac|mat] mean?

Best Answer

The author is referring to a series of commands he has defined and that are part od the file Commons.sty (the file can be found following a link in the site you linked to in your question); they basically are shortcuts allowing you to write fractions and matrices with or without delimiters; in the following document I've extracted the definitions from Commons.sty and provide an example of their use:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xfrac}

\newcommand{\pa}[1]{\left(#1\right)} % encloses the argument using stretchable parentheses
\newcommand{\bra}[1]{\left[#1\right]} % encloses the argument using stretchable square brackets

% matrices for displayed expressions
\newcommand{\mat}[1]{\begin{matrix}#1\end{matrix}} % no delimiters
\newcommand{\pmat}[1]{\pa{\mat{#1}}} % parentheses as delimiters
\newcommand{\bmat}[1]{\bra{\mat{#1}}} % square brackets as delimiters

% variations of \frac and \sfrac
\newcommand{\pfrac}[2]{\pa{\frac{#1}{#2}}} % enclosed in parentheses
\newcommand{\bfrac}[2]{\bra{\frac{#1}{#2}}} % enclosed in square brackets
\newcommand{\psfrac}[2]{\pa{\sfrac{#1}{#2}}} % sfrac enclosed in parentheses
\newcommand{\bsfrac}[2]{\bra{\sfrac{#1}{#2}}} % sfrac enclosed in square brackets

% for small matrices to be used in in-line expressions
\newcommand{\sm}[1]{\begin{smallmatrix}#1\end{smallmatrix}} % no delimiters 
\newcommand{\psm}[1]{\pa{\sm{#1}}} % parentheses as delimiters
\newcommand{\bsm}[1]{\bra{\sm{#1}}} % square brackets as delimiters


\begin{document}

\[
\pfrac{1}{2}\quad
\bfrac{1}{2}\quad
\psfrac{1}{2}\quad
\bsfrac{1}{2}\quad
\mat{1 & 0 & 1 \\ 0 & 0 & 1 \\ 1 & 1 & 0}\quad
\pmat{1 & 0 & 1 \\ 0 & 0 & 1 \\ 1 & 1 & 0}\quad
\bmat{1 & 0 & 1 \\ 0 & 0 & 1 \\ 1 & 1 & 0}\quad
\]

$\sm{1 & 0 \\ 1 & 0}\quad\psm{1 & 0 \\ 1 & 0}\quad\bsm{1 & 0 \\ 1 & 0}$

\end{document}

enter image description here

Of course, if you save the file Commons.sty in a convenient place (your local tree, for example) where TeX can find it, you can load the package and directly use the commands, as in:

\documentclass{article}
\usepackage{Commons}

\begin{document}

\[
\pfrac{1}{2}\quad
\bfrac{1}{2}\quad
\psfrac{1}{2}\quad
\bsfrac{1}{2}\quad
\mat{1 & 0 & 1 \\ 0 & 0 & 1 \\ 1 & 1 & 0}\quad
\pmat{1 & 0 & 1 \\ 0 & 0 & 1 \\ 1 & 1 & 0}\quad
\bmat{1 & 0 & 1 \\ 0 & 0 & 1 \\ 1 & 1 & 0}\quad
\]

$\sm{1 & 0 \\ 1 & 0}\quad\psm{1 & 0 \\ 1 & 0}\quad\bsm{1 & 0 \\ 1 & 0}$

\end{document}

As a side note, I would have defined \pmat and \bmat using directly bmatrix and pmatrix as provided by amsmath.

Related Question