LaTeX: The theorem Like Environment
Tags: codenewbie, latex
Published: 2021-12-22 15:45:56

Hello, how are you? :) 

In this post I talk about
- How to declare *theorem* like environments 

## Introduction

In past post I have talked about macros, but these just are instructions, they are shortens to do something bigger and avoid writing the same instruction many times, what about if we want to create environments?

The *theorem* like environment is an environment which you can personalize to be numbered according to a certain enumeration, this is useful because you can have the same format to different mathematical proofs, theorems, lemmas, etc, and instead of declaring or writing the same instruction, you just call the environment and it's all 

## The `theorem` environment

> We say that it is a `theorem` environment because it is the name of the command, as you are about to notice, but you can create Lemmas, Proofs, and many other stuff, it is just a matter that you put the appropriate name to that

The general instruction is 

```LaTeX
\newtheorem{name}{print}[numbered]
```
Where 
- `name` is the name of the environment
- `print` is the word to be shown in the document
- `numbered` is the sectional unit based on
which the environments is to be numbered (this is optional, you can see it because it has `[]` instead of `{}`

An example 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3m2luz4x0px5syaryj8.png)
 
 
Produces 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uk5n7l9aje7ens3hbhti.png)

See? the environment puts a default enumeration, in this case, it has not any reference, but, in `numbered` we can put according to what we want that enumeration, for example
- `section` for section
- `subsection` for subsection 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ut901p7s8qzzm2xbjey.png)

Produces

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bpd1vuu2t9iukz777t4.png)

You can play with this!! 

## Referencing to a *theorem*

> Remember that we say *theorem* because it is the name of the command

Do you remember the instruction `ref` and `label`, if not you can check them [here](https://dev.to/latexteada/latex-cross-referencing-2jga) and [here](https://dev.to/latexteada/latex-cross-referencing-how-to-call-elements-1346), there are good news, you can refer theorems too, the suggested way to call theorems and mathematical stuff is 

```LaTeX
\eqref{name}
```
> Remember to import the `amsmath` package in the preamble

Where `name` is the name of the label, let's see some examples 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qtqfglwln9fh249ggof.png)

Produces

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2ibouzxlo5fvsb40g34.png)

Did you see, the `eqref` adds some parentheses
  
Some conventions to use while *labeling* the *theorem* are 

- `thm` theorem
- `prop` proposition
- `dfn` definition
- `prf` proof
- `cor` corollary
- `princ` principle
- `lem` lemma

## Useful Tricks 

### Names of the *theorems* 

What if we want to be more specific in a theorem? What if we want to add a *name*, well we have two options, use `[]` or `()`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/217kz7nc8zdrxn7u8epk.png)
 

Produces 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ihw5yxekq79ae7nxa5rj.png)

### Delete the cursive

When we are using any math theorem it puts the mathematical equations in cursive, and the *theorems* are in cursive, it is a mess because sometimes it is difficult to differentiate between normal text and math stuff, so, if we want to delete the cursive in the *theorems* we just need to add 

```LaTeX
\usepackage{amsthm}
\theoremstyle{definition}
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lhetwqt6dp1chymm36l.png)

Produces

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgj77qzjx0gpuspi66ja.png)

We need to import the `amsthm` package and if we put the environment before `\theoremstyle{definition}` it won't be affected, but if we put the environment after it it will be affected