aboutsummaryrefslogtreecommitdiff
path: root/posts/latex.md
blob: 4234c8455462074aaefea7a86c8c2f034131cefe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
[meta]: <title> (My LaTeX setup)
[meta]: <subtitle> (How to set up a simple LaTeX environment with XeTeX and latexmk)
[meta]: <author> (Loek)
[meta]: <date> (January 24 2022)
[meta]: <tags> (software, latex, git)
[meta]: <cover> (/img/latex.png)

I started using LaTeX instead of MS Word about two years ago, and I've never
regretted the decision. I switched out of frustration because Word makes it
really easy to mess up your document structure without you noticing.

## Cool features LaTeX gets you

- Automatically numbered figures with references that automatically update
- Really simple bibliography management with `biblatex`
- Packages that help you typeset scientific things like chemistry or physics
- Professional looking output documents with very little effort
- Automation of repetitive things with macros
- It's a plain text format, so it works well with `git` or other version
	control software
- Probably more

## Installation

This guide is for Arch Linux and it's derivatives, but you can use
[pkgs.org](https://pkgs.org) to find the mentioned packages if they're under a
different name in your distro's package manager.

### Required packages

- `biber`
- `texlive-most`, containing:
	- `texlive-bibtexextra`
	- `texlive-core `
	- `texlive-fontsextra `
	- `texlive-formatsextra`
	- `texlive-games`
	- `texlive-humanities`
	- `texlive-latexextra`
	- `texlive-music`
	- `texlive-pictures`
	- `texlive-pstricks`
	- `texlive-publishers`
	- `texlive-science`
- `latex-mk`

tl;dr

```
# pacman -S texlive-most biber latex-mk
```

### Force XeTeX compiler with latexmk

To force latexmk to use the `xelatex` compiler instead of `pdflatex` you can
create `~/.config/latexmk/latexmkrc` with the following content:

```
$pdflatex = "xelatex %O %S";
$pdf_mode = 1;
$dvi_mode = 0;
$postscript_mode = 0;
```


## Hello world

LaTeX uses a lot of auxiliary files for compilation, so it's a good idea to
create a new directory for every document. After creating a new directory,
create a .tex file and open it with a text editor.

```tex
\documentclass[12pt, a4paper, dutch]{article}
\usepackage[margin=1in]{geometry}
\usepackage{babel}

\bigskipamount=7mm
\medskipamount=4mm
\parindent=0mm

\begin{document}
Hello world!
\end{document}
```

This is the starting point I generally use for all my documents. It uses a4
paper and 2.54cm margins, which is the default in Word (in Europe). Because
most of my documents are in Dutch, I add the `dutch` option to my document
class, and import the babel package for correct word breaking and built-in
latex heading translations. I also disable paragraph indenting, and modify the
`\bigskip` and `\medskip` distances.

After creating the .tex file, you can run `latexmk <your .tex file>` to compile
the document. When it's done, you should have a new .pdf file in your directory
with the same name as the .tex file.

Keep in mind that you can probably install an extension for your text editor to
have it automatically compile and refresh your document for you. If you're
using Visual Studio Code, you can use the [LaTeX
Workshop](https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop)
extension, and for vim I use [vimtex](https://github.com/lervag/vimtex) with
[coc-vimtex](https://github.com/neoclide/coc-vimtex) for
[coc](https://github.com/neoclide/coc.nvim).

## Notes

### LaTeX and git

Because LaTeX creates a lot of temporary files, you should add the following to
your repository's `.gitignore`:

```gitignore
**/*.aux
**/*.fdb_latexmk
**/*.fls
**/*.log
**/*.out
**/*.synctex.gz
```