How To Define And Use Macros In LaTeX

Описание к видео How To Define And Use Macros In LaTeX

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}}

https://www.overleaf.com
https://arxiv.org/

Комментарии

Информация по комментариям в разработке