Most useful LaTex -macros? Help me to understand a statement with $p][s][frac|mat] 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? - Context: I am investigating this issue partly to my answer here about note-taking -- trying to understand real-time TeXing. Some authors say that macros are not important (personally I use them very rarely, I try to keep base intact/minimalistic) but I still would like to understand this because I have never really understood the difference between LaTex and TeX, I have taken LaTex as face value. – hhh Oct 3 '12 at 2:41 2 Answers 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}


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.

-
@hhh he saves a few keystrokes; instead of, for example, \begin{matrix} 1 & 0 \\ 0 & 1 \end{matrix}, he can write \mat{1 & 0 \\ 0 & 1}. – Gonzalo Medina Oct 3 '12 at 3:31
How to read this "\newcommand{\mat}[1]{\begin{matrix}#1\end{matrix}}"? "[1]"? 3 blocks: \mat is the command, [1] is a divider and the last part is the new -command with place-holder? – hhh Oct 3 '12 at 3:32
@hhh maybe I don't understand you. Are you familiar with the use of \newcommand or is that precisely what you are asking? – Gonzalo Medina Oct 3 '12 at 3:34
Yes after thinking a bit, [n] is the amount of parameters where n is the amount. \[p][s][frac|mat], is this some Regex? | is XOR? [p] means at least one p or no p? This is confusing notation, 3 blocks with no specifiers. [...][...][...], what does this mean? – hhh Oct 3 '12 at 3:37
@hhh \mat is the command that will be defined; [1] declares that it has one argument (mandatory in this case); the next part: {\begin{matrix}#1\end{matrix}} is the definition of the command; it indicates that the argument will be typeset inside a matrix environment. – Gonzalo Medina Oct 3 '12 at 3:37

I don't want that Gonzalo Medina's words disappear so I attach them here from the chat. He clarifies the odd notation below. I bolded the clarifying point, thank you.

The author chose [p][s][frac|mat] as a simplified (yet not entirely correct) way to refer to a whole family of commands he defined (the ones I explained in my answer). With [p][s][frac|mat] he wants to refer quicly to \frac, \pfrac, \psfrac, \mat, \pmat, and the \mat version with an "s" which according to his notation should be \psmat, but that he really named \psm. Anyways, don't pay too much attention to the [p][s][frac|mat] notation; it is not relevant to the commands he defined; it was merely a "notational trickery" (that has nothing to do with LaTeX) that he selected to quickly refer to the family of commands that serve as shortcuts for matrices and fractions with or without delimiters. What really matters are the commands themselves. He chose p as a mnemonic for "*p*arenthesized", so \pmat represents a matrix using *p*arentheses as delimiters, \pfrac is a fraction delimited by parentheses, etc. The "s" stands as a mnemonic for "small", so \psm (which should have been \psmat, but he decided to use only \psm as the intent is to save keystrokes) represents a parenthesized small (for in-line use) matrix, etc.

-