# #Tricks

Here are some LaTeX tricks or commands I've found useful.

# Math Papers

Here are commands that I like to add to the start of math papers.

## Theorems

```
\newtheorem{theorem}{Theorem}[subsection]
\newtheorem{lemma}{Lemma}[subsection]
\newtheorem{corollary}{Corollary}[subsection]
```

This is pretty straightforward. Each of these creates a theorem namespace which can be used as follows.

```
\begin{theorem}
...
\end{theorem}
\begin{lemma}
...
\end{lemma}
\begin{corollary}
...
\end{corollary}
```

These namespaces are numbered under the current subsection. For instance:

```
\subsection{Lorem Numbers} //3.2
\begin{theorem} //Theorem 3.2.1
\end{theorem}
\begin{theorem} //Theorem 3.2.2
\end{theorem}
\begin{corollary} //Corollary 3.2.1
\end{corollary}
```

# Journal Articles

Here are commands that I like to add to the start of journal articles. These are found in this gist.

## Sections

This is what I use for section numbering in journal articles.

```
\newcounter{ms}
\newcounter{mss}
\newcounter{msss}
\newcommand{\mysection}[1]{\stepcounter{ms}\noindent\textbf{\arabic{ms}. {#1}}\setcounter{mss}{0}\\}
\newcommand{\mysubsection}[1]{\stepcounter{mss}\noindent\textbf{\arabic{ms}.\arabic{mss}. {#1}}\setcounter{msss}{0}\\}
\newcommand{\mysubsubsection}[1]{\stepcounter{msss}\noindent\textbf{\arabic{ms}.\arabic{mss}.\arabic{msss}. {#1}}\\}
\setcounter{ms}{0}
\setcounter{mss}{0}
\setcounter{msss}{0}
```

Let's break down what each of these does. We're defining 3 sets of commands here: `\mysection{}`

, `\mysubsection{}`

, and `\mysubsubsection{}`

. We redefine the section counters so that we can make them look exactly as we want to.

Our goal is to have our sections display as: **1. My Section**, **1.1 My Subsection**, **1.1.1 My Subsubsection**.

We start off by declaring counters for section number, subsection number, and subsubsection number. We then reset those counters to 0. Now, let's take a look at the first command.

`\newcommand{\mysection}[1]{\stepcounter{ms}\noindent\textbf{\arabic{ms}. {#1}}\setcounter{mss}{0}\\}`

We can separate this into two components:

```
\newcommand{\mysection}[1]{
\stepcounter{ms}\noindent\textbf{\arabic{ms}. {#1}}
\setcounter{mss}{0}\\
}
```

The command takes one argument, which is the section name. It increases the displays the section number, then displays the section name in boldface. Finally, it resets the subsection counter. This last step ensures that we get **1.3** followed by **2.1** rather than **1.3** followed by **2.4**.

The subsection command is extremely similar:

```
\newcommand{\mysubsection}[1]{
\stepcounter{mss}\noindent\textbf{\arabic{ms}.\arabic{mss}. {#1}}\setcounter{msss}{0}\\
}
```

The way to reason about this code is to pretend that the section is not there - in other words, each section is its own mini-document. The start of each section resets the subsection counter to 0, so we can essentially use exactly the same code. The only difference is that we go down one level (section becomes subsection, subsection becomes subsubsection) and display the section counter in addition to the subsection counter (`\arabic{ms}`

).

Again, the subsubsection command is essentially the same thing, except that there are no more lower levels to reset, so it's essentially one part instead of two.

```
\newcommand{\mysubsubsection}[1]{
\stepcounter{msss}\noindent\textbf{\arabic{ms}.\arabic{mss}.\arabic{msss}. {#1}}\\
}
```

## Endnotes

I use these commands for endnotes:

```
\newcounter{enc}
\newcommand{\enote}{\stepcounter{enc}\textcolor{blue}{[\arabic{enc}]}}
\newcommand{\num}{\textcolor{blue}{[\arabic{enc}]}}
```

This is really a pretty straightforward set of commands. The end goal is to keep a running endnote counter which is displayed blue and in brackets: [1], [2], and so on.

The first command just creates a new counter, which is the current endnote number. Now, let's break down the second command:

```
\newcommand{\enote}{ % define a new command
\stepcounter{enc} % add 1 to the endnote count
\textcolor{blue}{ % set color to blue
[\arabic{enc}] % display the endnote count in brackets[]
}
}
```

The second command is exactly the same, but without the `\stepcounter`

.

I use these to refer to citations. I use `\enote`

to refer to a citation for the first time. I use `\num`

to refer to the last citation/endnote created. For instance, I might cite a figure in an endnote, then refer to that last endnote.

```
Blue watermelons were introduced in \enote, but were only properly researched in \enote.
> Blue watermelons were introduced in [1], but were only properly researched in [2].
FIG. 1. Graph from \num, demonstrating how the watermelon is blue.
> Graph from [2], demonstrating how the watermelon is blue.
```