# Adding section numbers to LaTeX floats numbering and other tips

I have been learning to use LaTeX for some time. Now I do most of my homework assignments in LaTeX. It wears quite well on me. I have encountered some issues, but most of the time I was able to find elegant solutions on TeX StackExchange. Here are a few tips I learned recently.

## 1. Show chapter or section numbers in equation/figure/table numbering

By default, LaTeX assigns equation numbers continually across different sections. If you need the equation to be numbered like “Eq. (3.5)” for the 5th equation in section 3, add this to the preamble:

```
\usepackage{amsmath}
\numberwithin{equation}{section}
```

To include also the subsection number, change the second line to

```
\numberwithin{equation}{subsection}
```

For figures and tables, it is similar.

```
\usepackage{amsmath}
\numberwithin{table}{section}
\numberwithin{figure}{section}
```

## 2. Scientific notation

The most elegant solution for scientific notation of numbers is to use the
`siunitx`

package.

```
\usepackage{siunitx}
...
\num{6.022e23}
```

`\num{6.022e23}`

will be rendered as “6.022 × 10^{23}”.

An alternative solution that does not depend on `siunitx`

is:

```
\newcommand{\e}[1]{\ensuremath{\times 10^{#1}}}
```

This new command can be used like `6.022\e{23}`

to produce “6.022 ×
10^{23}”.

## 3. Upright differential operator

The differential operator `d`

in `dy / dx`

should be typeset in upright not
italic shape, because it is not a variable (Beccari, 1997, *TUGboat*). The
upright differential operator is not provided by the `amsmath`

package, and to
do it properly requires much low-level TeX programming due to spacing
requirements. An out-of-the-box solution is to use the `commath`

package, which
provides the following commands:

`\dif`

: This produces an upright`d`

.`\Dif`

: This produces an upright`D`

(e.g., for Lagrangian derivative).`\od`

: This takes two arguments for the function and the variable, respectively, and an optional argument for the order, e.g.,`\od[2]{f}{x}`

produces $\dfrac{\mathrm{d}^2 f}{\mathrm{d} x^2}$.`\pd`

: This works similarly to`\od`

but produces partial derivatives.

There are also many other useful commands in this package.

Alternatively, a minimalist and nearly as good solution without using `commath`

can be

```
\newcommand{\dif}{\mathrm{d}}
\newcommand{\Dif}{\mathrm{D}}
\newcommand{\od}[3][]{\ensuremath{\dfrac{\dif^{#1}#2}{\dif #3^{#1}}}}
\newcommand{\pd}[3][]{\ensuremath{\dfrac{\partial^{#1}#2}{\partial #3^{#1}}}}
```

## References

- Beccari, C. (1997). Typesetting mathematics for science and technology
according to ISO 31/XI.
*TUGboat*, 18(1), 39–48. [link]