How To Define And Use Macros In LaTeX

preview_player
Показать описание
In this video we learn how to define and use macros. Macros are a good way to save keystrokes but also to make our code more human readable and "semantic". We also see how to use fullscreen mode in Overleaf.

In our preamble we either use the command \newcommand{}{} or the command \newcommand{}[]{} if we want to define a macro. The former is used when we don't need any options whereas the latter is used when we do want options.

Some macros I like to use in my documents are:

\newcommand{\abs}[1]{\left| {#1} \right|}
\newcommand{\Bern}[2]{{#1} \sim \operatorname{Bernoulli} ( {#2} )}
\newcommand{\Bin}[3]{{#1} \sim \operatorname{Binomial} ( {#2, #3} )}
\newcommand{\C}{\mathbf{C}}
\DeclareMathOperator\cis{cis}
\newcommand{\Cov}[1]{\operatorname{\mathbf{Cov}} ( {#1} )}
\newcommand{\dif}{\mathop{}\!\mathrm{d}}
\DeclareMathOperator{\dis}{d}
\DeclareMathOperator\dom{dom}
\newcommand{\E}{\mathrm{e}}
\newcommand{\Eval}[3]{\left[ #1 \right]_{#2}^{#3}}
\newcommand{\Exp}[1]{\operatorname{\mathbf{E}} ( {#1} )}
\DeclareMathOperator{\lcm}{lcm}
\newcommand{\divides}{\mid}
\let\Im\undefined
\DeclareMathOperator{\Im}{Im}
\newcommand{\keyword}{\textsf}
\newcommand{\mat}[1]{#1}
\newcommand{\mean}[1]{\overline{#1}}
\newcommand{\N}{\mathbf{N}}
\newcommand{\Norm}[3]{{#1} \sim \operatorname{\mathcal{N}} ( {#2, #3} )}
\newcommand{\notdivides}{\nmid}
\newcommand{\pfrac}[2]{\left( \frac{#1}{#2} \right)}
\newcommand{\Prob}[1]{\operatorname{\mathbf{P}} ( {#1} )}
\newcommand{\Q}{\mathbf{Q}}
\newcommand{\R}{\mathbf{R}}
\DeclareMathOperator\ran{ran}
\let\Re\undefined
\DeclareMathOperator{\Re}{Re}
\newcommand{\RNum}[1]{\uppercase\expandafter{\romannumeral #1\relax}}
\newcommand{\SD}[1]{\operatorname{\mathbf{SD}} ( {#1} )}
\newcommand{\Var}[1]{\operatorname{\mathbf{Var}} ( {#1} )}
\newcommand{\Z}{\mathbf{Z}}

Рекомендации по теме
Комментарии
Автор

It would be nice to see a video dedicated to asymptotes and how to deal with rational functions. I found a LaTeX package called asymptote but it is rather terse and the documentation is not very useful. It is not clear if the package works with tikz/pgf either. I do realize that we will still have to find the asymptotes using regular algebra techniques before we can include them in our plots.

haraldurkarlsson
Автор

Midway through the video these questions arose in my mind.
1) There is another command \bar{} that produces overstrike. It is a bit shorter 'strike' than \overline{} uses. Does it matter which one is used?
2) In the preamble I put mathmode inside the macros definition. For example: \newcommand{\mean}[1]{$ \overline{#1}$}.
Then I just call the macro with \mean{} rather than $\mean{x}$. You seem to prefer the latter. Why?
Thanks.

haraldurkarlsson
Автор

Learning LaTeX and it's associated "add-ons" is a truly humiliating experience. Every time I think I have learnt something well and my chest is starting to puff up along comes another package like tikz/pgf with its massive manual I am feel as if I am back to square one! Is anyone actually a complete LaTeX expert?

haraldurkarlsson
visit shbcf.ru