Scientific Latex
Here I gather usefull tips and tricks for writing scientific papers in LaTeX. Although I work in theoretical computer science (which has big influence on styles we use) this post may be useful for anyone writing papers in latex.
General
Technique
Given an issue this post shall mention one solution to it eventhough there may exist many different ways to solve the issue. I try to do things so that the process of writing is easier and mistakes are harder to do.
Tools
Compilation
The latex source which contains bibliography can be compiled with the following command.
pdflatex main.tex && pdflatex main.tex && bibtex main.aux && pdflatex main.tex
Editor
- Texmaker ↗ is a usable multiplatform latex editor.
Newlines
How the code is formatted has its advantages. Two main styles are
- one paragraph on one line,
- one sentence on one line,
newline when the line is too long.
A paragraph on a line has advantage, that the code looks like the final result.
I prefer one sentence on a line as
- it makes semantically sense,
- one can easily see if there are lines which are too long and should to be split into several sentences,
- working with sentences (e.g. reordering them) becomes easy,
- it is easy to comment with
\todo
between sentences, - as
git
versioning system sees differences per line the sentence-per line formatting helps to avoid merge conflicts, and it is easier to see what changed with diff.
Indentation
Versioning
You should always backup the project somewhere to ensure that we may not loose the paper progress if something (like PC) breaks. Another consideration whether you collaborate on the paper with someone. We can recommend Git, Dropbox, or Overleaf – each has its advantages and disadvantages.
Math
topic | code | result |
---|---|---|
basic math | 1 + y^{a+b} + \frac{a}{b} |
$1 + y^{a+b} + \frac{a}{b}$ |
dots | x_1,x_2,\dots,x_n |
$x_1,x_2,\dots,x_n$ |
basic logic | (x_1 \vee x_2) \wedge x_3 |
$(x_1 \vee x_2) \wedge x_3$ |
basic sets | A \cup (B \cap \{u,v\}) \setminus D |
$A \cup (B \cap {u,v}) \setminus D$ |
more set | \{(a,b) \mid a \in A, b\not\in B\} |
${(a,b) \mid a \in A, b\not\in B}$ |
rounding | \lfloor 3.2 \rfloor + \lceil 2.1 \rceil |
$\lfloor 3.2 \rfloor + \lceil 2.1 \rceil$ |
bracket sizes | ( \big( \Big( \bigg( \Bigg( |
$( \big( \Big( \bigg( \Bigg($ |
bracket types | ( \{ \lfloor \lceil [ |
$( { \lfloor \lceil [$ |
functions | f \colon \mathbb{R} \to \mathbb{N} |
$f \colon \mathbb{R} \to \mathbb{N}$ |
greek symbols | \alpha,\varepsilon,\Omega,\pi |
$\alpha,\varepsilon,\Omega,\pi$ |
basic spacing | ea\,b\ c\quad d\qquad e |
$ea,b\ c\quad d\qquad e$ |
known functions | \log 2, \sin \alpha |
$\log 2, \sin \alpha$ |
sums | \sum_{i=1}^n i^2, \prod_a^b |
$\sum_{i=1}^n i^2, \prod_a^b$ |
integrals | \int_{0}^{e} e^x \,dx |
$\int_{0}^{e} e^x ,dx$ |
The correct expression is always written first:
\colon
instead of:
in functions like $F \colon \mathbb{N} \rightarrow \mathbb{N}$.\bmod
instead of\mod
when used as an operator $A \bmod B$\mid
instead of|
or:
in sets ${ v \mid v \in V(G) \cap V(G’) }$
Problems
Enhancments
Custom labels
Taken from the stack exchange answer of Henrik Bøgelund Lavstsen ↗, the answer depends on if you use the hyperref
package.
If you use hyperref
package, then use:
\makeatletter
\newcommand{\customlabel}[2]{%
\protected@write \@auxout {}{\string \newlabel {#1}{{#2}{\thepage}{#2}{#1}{}} }%
\hypertarget{#1}{#2}
}
\makeatother