---
title: "LaTeX II: Thesis Workflows, Bibliography, and Advanced Tools"
subtitle: "Multi-file Projects, Zotero, Quarto, and TikZ"
author:
  - name: "Job Schepens"
    id: js
    orcid: 0000-0003-1271-2526
    email: job.schepens@uni-koeln.de
    affiliation:
      - name: Universität zu Köln
        department: CRC 1252 Prominence in Language, Project S
        city: Cologne, Germany
        url: https://jobschepens.github.io/personal-page/
date: "17 June 2026"
date-format: "D MMMM YYYY"
format:
  revealjs:
    theme: [default, ../../stylesheets/mytheme.scss]
    logo: ../../logo.png
    slide-number: true
    scrollable: true
    mouse-wheel: true
    footer: "RDM Workshop Series · SFB 1252 Prominence in Language · Universität zu Köln"
    output-file: slides.html
    embed-resources: true
    transition: none
    background-transition: none
bibliography: "0. toread.bib"
csl: apa.csl
---

## Overview

Building on Session 1, this session covers:

- **Longer documents** — multi-file project structure for theses and dissertations
- **Bibliography management** — `.bib` files, `biblatex`, and citation commands
- **Zotero + BetterBibTeX** — reference management with continuous auto-export
- **Quarto** — literate programming combining R/Python code with LaTeX output
- **TikZ** — programmatic figures and diagrams written directly in LaTeX
- **Templates** — journal submission files and university thesis templates
- **Debugging** — reading error messages and fixing common problems

::: {.callout-tip}
**Prerequisites:** familiarity with LaTeX document structure, basic commands, and environments from Session 1.
:::


## Session 1 Recap {.smaller}

| Concept | Key points |
|---|---|
| Document structure | Preamble + body; `\documentclass`, `\usepackage` |
| Commands | `\command[opt]{arg}` — backslash notation |
| Environments | `\begin{name}` … `\end{name}` blocks |
| Text formatting | `\textbf`, `\textit`, `\section`, `\itemize` |
| Math | `$...$` inline; `\[...\]` display; `equation` for numbered |
| Figures and tables | `figure` and `table` float environments with `\label`/`\ref` |
| Distributions | TeX Live (recommended); MiKTeX; TinyTeX |
| Editors | Overleaf, Prism, TeXlyre, TeXstudio, VS Code |


## Document Classes for Longer Works {.smaller}

For documents longer than a typical journal article, choose the right `\documentclass`:

| Class | Use for | Key structure commands |
|---|---|---|
| `article` | Papers, short reports | `\section`, `\subsection` |
| `report` | Bachelor/master theses, technical reports | `\chapter`, `\section` |
| `book` | PhD theses, monographs | `\part`, `\chapter`, `\section` |
| [`beamer`](https://ctan.org/pkg/beamer) | Presentations | `\frame`, `\begin{block}` |

Most universities provide a custom class (e.g. `unikoeln-thesis`) that presets all formatting.

**Useful preamble options for longer documents:**

```latex
\documentclass[12pt, a4paper, twoside, openright]{report}
\usepackage{hyperref}     % clickable cross-references and PDF metadata
\usepackage{cleveref}     % smart refs: \cref{fig:x} → "Figure 1"
\usepackage{microtype}    % improved line breaking and spacing
\usepackage{setspace}     % line spacing (\onehalfspacing, \doublespacing)
```

[`hyperref`](https://ctan.org/pkg/hyperref) · [`cleveref`](https://ctan.org/pkg/cleveref) · [`microtype`](https://ctan.org/pkg/microtype) · [`setspace`](https://ctan.org/pkg/setspace)


## Multi-file Projects: `\input` and `\include` {.smaller}

For long documents, split your `.tex` source into multiple files.

**`\input{filename}` — inline inclusion:**

```latex
% main.tex
\documentclass{report}
\begin{document}
\input{chapters/introduction}
\input{chapters/methods}
\input{chapters/results}
\end{document}
```

- Inserts the file content directly — equivalent to copy-pasting
- Can be nested; no page break is forced

**`\include{filename}` — chapter inclusion with page break:**

```latex
\include{chapters/introduction}  % forces a new page before and after
```

- Supports `\includeonly{chapter1,chapter3}` to compile only selected chapters — faster iteration on large documents

::: {.callout-note}
Use `\input` for small fragments (preamble settings, custom commands). Use `\include` for major structural divisions like chapters.
:::


## Recommended Thesis Folder Structure

```
my-thesis/
├── main.tex              ← root document
├── preamble.tex          ← packages and settings (\input'd)
├── chapters/
│   ├── 01-introduction.tex
│   ├── 02-methods.tex
│   ├── 03-results.tex
│   └── 04-discussion.tex
├── appendices/
│   └── appendix-a.tex
├── figures/
│   ├── fig-methods.pdf
│   └── fig-results.pdf
├── references.bib        ← bibliography database
└── output/
    └── thesis.pdf
```

**Keep figures as vector PDFs** — they scale perfectly at any zoom level and stay sharp in print.

::: {.callout-tip}
Put this folder in a Git repository from day one. Version control for a thesis is invaluable — you can always go back to an earlier version.
:::


## LaTeX Engines {.smaller}

A **LaTeX engine** is the program that reads your `.tex` file and produces output. Several exist — choose based on your font and language needs:

| Engine (since) | Output | Unicode | System fonts | When to use |
|---|---|---|---|---|
| `pdflatex` (1997) | PDF directly | Partial (Latin extended) | No — TeX fonts only | Most journal templates; fastest compile; widest compatibility |
| `xelatex` (2004) | PDF via XDV | Full UTF-8 | Yes — any installed font | Non-Latin scripts; custom OpenType/TrueType fonts; multilingual documents |
| `lualatex` (2007) | PDF directly | Full UTF-8 | Yes — via `fontspec` | Same as XeLaTeX + Lua scripting for advanced customisation; slower compile |
| `latex` + `dvipdf` (1985) | DVI → PDF | No | No | Legacy workflows; rarely needed today |

**Browser-based engines (no installation):**

| Engine | How it works | Use case |
|---|---|---|
| **SwiftLaTeX** (2019) | Compiles entirely in the browser via WebAssembly; no server round-trip | Offline-capable web apps; embedding LaTeX in tools |
| **BusyTeX** (2022) | TeX Live compiled to WASM; runs `pdflatex`/`xelatex` client-side | Self-contained browser editors; privacy-sensitive workflows |

::: {.callout-tip}
For new documents: use `pdflatex` if the journal template requires it, otherwise `lualatex` for the most modern and flexible setup. Overleaf, Prism, and TeXlyre all support switching engines in project settings.
:::


## Bibliography: How It Works {.smaller}

LaTeX separates the bibliography **database** (a `.bib` file) from the **formatting style** (applied at compile time).

**Why multiple compilation passes?**

Each pass does something different:

```
pdflatex main.tex   → compiles document; writes citation keys to main.aux
biber main          → reads main.aux; looks up keys in main.bib;
                      writes formatted bibliography to main.bbl
pdflatex main.tex   → reads main.bbl; inserts bibliography into PDF
pdflatex main.tex   → resolves all cross-references (page numbers, labels)
```

Skipping passes is the most common reason references show as **[?]** or the bibliography is missing entirely.

The bibliography system has two independent layers:

- **Backend** — an *external program* invoked between LaTeX passes (e.g. `biber` or `bibtex` on the command line); reads the `.bib` database, resolves citation keys, and writes the formatted `.bbl` file that LaTeX then reads back in
- **Style package** — a *LaTeX package* declared in the **preamble** (the part of your `.tex` file before `\begin{document}`); defines the `\cite` commands available in your document and controls how the bibliography list is formatted when printed

The backend and the style package must be chosen as a matched pair — they communicate via the `.aux` and `.bbl` files and expect a compatible format.


## Bibliography: Choosing Packages {.smaller}

| Backend (since) | Style package (since) | When to use |
|---|---|---|
| [`biber`](https://ctan.org/pkg/biber) (2011) | [`biblatex`](https://ctan.org/pkg/biblatex) (2006) | **New projects and theses** — full Unicode; per-entry-type formatting; advanced sorting and filtering; large choice of maintained styles (APA, Chicago, linguistics-specific) |
| [`BibTeX`](https://ctan.org/pkg/bibtex) (1985) | [`natbib`](https://ctan.org/pkg/natbib) (1993) | **Publisher-mandated** — ACL, IEEE, Elsevier, Springer templates ship `.bst` files that require BibTeX; ASCII cite keys only; less flexible but universally supported |
| `BibTeX` (1985) | [`biblatex`](https://ctan.org/pkg/biblatex) (2006) | **Compatibility fallback** — set `backend=bibtex` in the preamble when `biber` is unavailable (e.g. restricted servers or CI); keeps `biblatex` syntax but loses Unicode sorting and some advanced features |
| `BibTeX` (1985) | [`apacite`](https://ctan.org/pkg/apacite) (1994) | **Avoid for new work** — implements APA 6th edition only (2009); unmaintained since ~2013; still found in older humanities templates but superseded by [`biblatex-apa`](https://ctan.org/pkg/biblatex-apa) |

**Preamble examples — the style package is where you declare the pairing:**

```latex
% Option 1: biblatex + biber + APA 7th (recommended for linguistics / social science)
% biblatex-apa requires babel (or polyglossia) and csquotes for correct
% localisation of quotes and date formats — load them BEFORE biblatex
\usepackage[american]{babel}
\usepackage{csquotes}                          % language-aware quotation marks
\usepackage[backend=biber, style=apa]{biblatex} % style=apa loads biblatex-apa
\addbibresource{references.bib}

% Option 1b: same but with polyglossia (XeLaTeX/LuaLaTeX)
\usepackage{polyglossia}
\setdefaultlanguage[variant=american]{english}
\usepackage{csquotes}
\usepackage[backend=biber, style=apa]{biblatex}
\addbibresource{references.bib}

% Option 2: natbib + BibTeX (journal template compatibility)
\usepackage[round, authoryear]{natbib}
% no \addbibresource — use \bibliography{references} at end of document

% Option 3: biblatex + BibTeX fallback (biber unavailable)
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[backend=bibtex, style=apa]{biblatex}
\addbibresource{references.bib}

% Option 4: apacite — AVOID (APA 6th only, unmaintained since ~2013)
\usepackage{apacite}
% no \addbibresource — use \bibliography{references} at end of document
```

::: {.callout-tip}
[`csquotes`](https://ctan.org/pkg/csquotes) is required by `biblatex-apa` for correct localisation of block quotes, in-text quotation marks, and date formatting. Without it you may get warnings or incorrect output. [`babel`](https://ctan.org/pkg/babel) / [`polyglossia`](https://ctan.org/pkg/polyglossia) sets the language so that `biblatex` applies the right hyphenation, month names, and punctuation rules.
:::


::: {.callout-note}
The `backend=` option inside `\usepackage[...]{biblatex}` tells `biblatex` which external program to expect. If this does not match the program your editor actually runs, you get missing-reference errors. Check your editor's build settings if references show as **[?]**.
:::


## APA Manuscript Layout {.smaller}

Citation style (`biblatex-apa`) and *document layout* are separate concerns. APA journals require specific formatting — double-spacing, running head, author note, abstract — that goes beyond citation style.

**Options for full APA 7th manuscript layout:**

| Option | Status | Notes |
|---|---|---|
| [`apa7`](https://ctan.org/pkg/apa7) document class | Last release July 2022; no updates since | Implements full APA 7th manuscript format; use with `biblatex-apa`; broadly functional but bug reports unaddressed |
| [`papaja`](https://github.com/crsh/papaja) R package | Actively maintained | Quarto/R Markdown wrapper around an APA 6th LaTeX template; integrates R output directly; ideal for empirical papers with analysis code |
| Overleaf APA template | Varies by template | Several community-maintained APA 7th templates on the [Overleaf Gallery](https://www.overleaf.com/gallery/tagged/apa); quality varies |
| Custom preamble | Maintained by you | Use `setspace`, `fancyhdr`, `geometry` etc. to replicate APA layout manually; full control |

**Minimal `apa7` setup (for manuscript submission):**

```latex
\documentclass[man, 12pt]{apa7}   % man = manuscript mode; also: jou, doc, stu
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=apa, backend=biber]{biblatex}
\addbibresource{references.bib}
```

::: {.callout-tip}
For **empirical linguistics or psychology papers** where you also need R/Python output in your manuscript, [`papaja`](https://github.com/crsh/papaja) with Quarto is the most practical fully-maintained solution. It generates APA 7th–formatted PDFs directly from `.qmd` or `.Rmd` files.
:::


## Configuring TeXstudio for Biber {.smaller}

TeXstudio defaults to **BibTeX** as the bibliography tool. When your document uses `biblatex` with `backend=biber`, you must change this setting — otherwise you get errors like:

```
I found no \citation commands---while reading file test.aux
I found no \bibdata command---while reading file test.aux
I found no \bibstyle command---while reading file test.aux
```

**Fix:**

**Options → Configure TeXstudio → Build → Default Bibliography Tool → `Biber`**

![TeXstudio Build settings](figures/texstudio-biber.png){width=60%}

**After changing the setting — compile in order:**

1. **PDFLaTeX** (F6) — generates `.aux` with citation keys
2. **Bibliography / Biber** (F8) — processes `.bib`, writes `.bbl`
3. **PDFLaTeX** (F6) — inserts bibliography
4. **PDFLaTeX** (F6) — resolves page numbers and cross-references

Or press **F5 (Build & View)** — TeXstudio runs the full sequence automatically.

::: {.callout-tip}
[`latexmk`](https://ctan.org/pkg/latexmk) (used by VS Code LaTeX Workshop and Overleaf) detects `biber` automatically from the preamble and runs the correct sequence without any configuration.
:::


## The `.bib` File {.smaller}

A `.bib` file is a plain-text database of references. Each entry has a **type**, a **cite key**, and **fields**:

```bibtex
@article{schepens2024prominence,
  author    = {Schepens, Job and Smith, Anna},
  title     = {Prominence in Language},
  journal   = {Language and Cognition},
  year      = {2024},
  volume    = {16},
  pages     = {123--145},
  doi       = {10.1017/langcog.2024.12},
}

@book{chomsky1965aspects,
  author    = {Chomsky, Noam},
  title     = {Aspects of the Theory of Syntax},
  publisher = {MIT Press},
  address   = {Cambridge, MA},
  year      = {1965},
}
```

Common entry types: `@article`, `@book`, `@incollection`, `@inproceedings`, `@phdthesis`, `@misc`

::: {.callout-note}
The cite key (e.g. `schepens2024prominence`) is what you use in `\cite{...}` commands. BetterBibTeX generates these automatically from Zotero.
:::


## Zotero: Building Your Reference Library {.smaller}

[**Zotero**](https://www.zotero.org) is a free, open-source reference manager widely used in academia.

**Collecting references:**

- **Browser connector** imports references from publisher websites, Google Scholar, PubMed with one click
- Drag-and-drop PDFs → Zotero extracts metadata automatically
- Add by DOI, ISBN, or arXiv ID directly

**Organising your library:**

- Collections and sub-collections (like folders)
- Tags for thematic grouping; related items for linking connected works

**Generating citations:**

- Word processor plugins (Word, LibreOffice) for inline citations
- Supports thousands of citation styles (APA, MLA, Chicago, linguistics styles …)

| | |
|---|---|
| Download | [zotero.org](https://www.zotero.org) |
| Browser connector | [zotero.org/download/connectors](https://www.zotero.org/download/connectors) |

::: {.callout-tip}
Overleaf, Prism (OpenAI), and TeXlyre all include Zotero integration panels for searching and importing references directly within the editor.
:::


## BetterBibTeX: Continuous Auto-export {.smaller}

[**BetterBibTeX**](https://retorque.re/zotero-better-bibtex/) (BBT) is a Zotero plugin that connects your Zotero library directly to your LaTeX project.

**Install:** Zotero → Tools → Plugins → Install from file (download `.xpi` from [retorque.re/zotero-better-bibtex](https://retorque.re/zotero-better-bibtex/))

**Cite keys:**

BBT generates a stable, customisable cite key for every item:

- Default pattern: `[auth:lower][year][veryshorttitle]` → `schepens2024prominence`
- Configure globally: Preferences → Better BibTeX → Citation Keys
- Pin individual keys to prevent them from changing

**Setting up auto-export — set it and forget it:**

1. Right-click a Zotero collection → **Export Collection…**
2. Format: **Better BibLaTeX** (or Better BibTeX)
3. Check **Keep updated**
4. Save as `references.bib` in your LaTeX project folder

::: {.callout-tip}
With **Keep updated** enabled, every time you add, edit, or delete a reference in Zotero, the `.bib` file regenerates automatically. Your LaTeX project always has fresh, correct references — no manual exports needed.
:::


## Citation Commands in `biblatex` {.smaller}

With `\usepackage[backend=biber, style=apa]{biblatex}` and `\addbibresource{references.bib}`:

| Command | Output |
|---|---|
| `\cite{key}` | (Author, Year) |
| `\parencite{key}` | (Author, Year) — parenthetical |
| `\textcite{key}` | Author (Year) — narrative |
| `\autocite{key}` | Style-determined; adapts to context |
| `\cites{key1}{key2}` | Multiple citations |
| `\footcite{key}` | Footnote citation |

**Example text:**

```latex
\textcite{schepens2024prominence} argue that prominence is cross-linguistic.
Several studies support this claim \parencite{chomsky1965aspects, schepens2024prominence}.
```

**Print the bibliography:**

```latex
\printbibliography                        % full bibliography
\printbibliography[heading=bibintoc]      % include in table of contents
\printbibliography[type=article]          % filter by entry type
```


## Citation in Practice: A Real Example {.smaller}

Using `burknerBrmsPackageBayesian2017` from our `.bib` file:

**The `.bib` entry (BibLaTeX format, auto-exported from Zotero):**

```bibtex
@article{burknerBrmsPackageBayesian2017,
  author  = {Bürkner, Paul-Christian},
  title   = {brms: {An} {R} Package for Bayesian Multilevel Models Using Stan},
  journal = {Journal of Statistical Software},
  year    = {2017},
  volume  = {80},
  pages   = {1--28},
  doi     = {10.18637/jss.v080.i01},
}
```

**In your `.tex` document:**

```latex
% Narrative citation — author as subject:
\textcite{burknerBrmsPackageBayesian2017} introduced the brms package for Bayesian multilevel modelling in R.

% Parenthetical citation — supporting claim:
Bayesian multilevel models can be fitted using Stan via R \parencite{burknerBrmsPackageBayesian2017}.

% Multiple citations:
\parencite{burknerBrmsPackageBayesian2017, gelmanRegressionOtherStories2020}
```

**Rendered output (APA 7th style):**

> @burknerBrmsPackageBayesian2017 introduced the `brms` package for Bayesian multilevel modelling in R.

> Bayesian multilevel models can be fitted using Stan via R [@burknerBrmsPackageBayesian2017].

::: {.callout-note}
The cite key `burknerBrmsPackageBayesian2017` is generated automatically by BetterBibTeX from the pattern `[auth:lower][Title:skipwords:lower:select=1,1][year]`. You never need to type or remember it — just search in your editor's Zotero panel or use autocomplete.
:::


## Quarto: Literate Programming Meets LaTeX {.smaller}

[**Quarto**](https://quarto.org) is a scientific publishing system that produces PDF output via LaTeX while keeping analysis code and prose in a single source file.

**A Quarto document (`.qmd`):**

````markdown
---
title: "My Analysis"
format: pdf
---

## Introduction

We analysed **N = 42** participants.

```{{r}}
#| label: fig-histogram
#| fig-cap: "Distribution of scores"
hist(rnorm(100))
```

As shown in @fig-histogram, scores are normally distributed.
````

- Write in **Markdown** (with LaTeX commands where needed)
- Embed **R, Python, or Julia** code chunks — output appears in the compiled PDF
- Cross-references (`@fig-histogram`), citations (`@key`), and equations all work out of the box

::: {.callout-note}
Quarto is the successor to R Markdown. It supports multiple languages and output formats (PDF, HTML, DOCX, slides) from the same source file.
:::


## Quarto PDF Output and LaTeX Options {.smaller}

Quarto converts `.qmd` → LaTeX → PDF via a TeX Live installation.

**Configure LaTeX in the YAML header:**

```yaml
---
title: "Thesis Chapter"
format:
  pdf:
    documentclass: report
    papersize: a4
    fontsize: 12pt
    geometry: margin=2.5cm
    keep-tex: true          # inspect the generated .tex file
    include-in-header: preamble.tex   # your custom packages
    cite-method: biblatex
    bibliography: references.bib
    biblio-style: apa
---
```

**Why `keep-tex: true`?**

- Lets you inspect and modify the generated LaTeX if something doesn't look right
- Some journals require a `.tex` submission file — Quarto can generate it

::: {.callout-tip}
Install Quarto from [quarto.org/docs/get-started](https://quarto.org/docs/get-started/). With TinyTeX (`tinytex::install_tinytex()` in R), PDF output works immediately — no separate TeX Live install needed.
:::


## Writing a Complete Thesis in Quarto {.smaller}

Quarto supports **multi-file book projects** — the natural structure for a thesis.

**Initialise a Quarto book:**

```bash
quarto create project book my-thesis
```

This generates a ready-to-use folder:

```
my-thesis/
├── _quarto.yml        ← project config: title, author, chapters, output
├── index.qmd          ← front matter / preface
├── chapters/
│   ├── 01-introduction.qmd
│   ├── 02-methods.qmd
│   ├── 03-results.qmd
│   └── 04-discussion.qmd
├── references.bib
└── _extensions/       ← optional: university theme extension
```

**`_quarto.yml` for a PDF thesis:**

```yaml
project:
  type: book

book:
  title: "My Thesis Title"
  author: "Your Name"
  date: "2026"
  chapters:
    - index.qmd
    - chapters/01-introduction.qmd
    - chapters/02-methods.qmd
    - chapters/03-results.qmd
    - chapters/04-discussion.qmd

bibliography: references.bib

format:
  pdf:
    documentclass: report
    papersize: a4
    fontsize: 12pt
    geometry: margin=2.5cm
    toc: true
    number-sections: true
    cite-method: biblatex
    biblio-style: apa
    include-in-header: preamble.tex   # custom LaTeX packages
```

**Render the whole thesis:**

```bash
quarto render          # builds PDF (and HTML if configured)
quarto render --to pdf # PDF only
```

::: {.callout-tip}
Each `.qmd` chapter file is an ordinary Quarto document — it can contain R/Python code chunks, figures, tables, and equations. Cross-references (`@fig-`, `@tbl-`, `@sec-`) resolve across chapter boundaries automatically.
:::

::: {.callout-note}
Quarto book projects also render to HTML (a website) and EPUB from the same source. Useful for sharing a web version alongside the submitted PDF.
:::


## TikZ: Programmatic Figures {.smaller}

[**TikZ**](https://ctan.org/pkg/pgf) ("TikZ ist kein Zeichenprogramm") is a LaTeX package for creating figures programmatically — directly in your `.tex` source.

**Why TikZ?**

- Figures are plain text — version-controlled alongside your paper
- Perfect vector output at any scale
- Consistent fonts and styling with the surrounding document
- Highly precise control over every element

**Minimal setup:**

```latex
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}  % load useful libraries
```

**Drawing shapes and paths:**

:::: {.columns}
::: {.column width="55%"}
```latex
\begin{tikzpicture}
  \draw[thick, fill=blue!20] (0,0) rectangle (3,2);
  \draw[red, ->, line width=1.2pt] (0,0) -- (3,2) node[right] {diagonal};
  \node[circle, draw, fill=green!30, minimum size=1cm] at (1.5,1) {center};
\end{tikzpicture}
```
:::
::: {.column width="45%"}
![](figures/tikz-shapes.svg){width=100%}
:::
::::

::: {.callout-note}
TikZ has a steep learning curve. [tikz.dev](https://tikz.dev) and the PGF/TikZ manual on CTAN are comprehensive references. Start small and build up.
:::


## TikZ: Flowcharts {.smaller}

:::: {.columns}
::: {.column width="55%"}
```latex
\usetikzlibrary{shapes.geometric, arrows.meta, positioning}
\begin{tikzpicture}[
  node distance=1.5cm,
  box/.style={draw, rectangle, minimum width=2.5cm,
              minimum height=0.8cm, align=center},
  decnode/.style={draw, diamond, aspect=2,
                  minimum width=2.5cm, align=center}
]
  \node[box] (A) {Step 1};
  \node[box, below of=A] (B) {Step 2};
  \node[decnode, below of=B] (C) {Decision?};
  \node[box, below right=0.8cm and 1.2cm of C] (D) {Yes};
  \node[box, below left=0.8cm and 1.2cm of C] (E) {No};
  \draw[->] (A) -- (B);
  \draw[->] (B) -- (C);
  \draw[->] (C) -- node[above right, font=\small] {yes} (D);
  \draw[->] (C) -- node[above left, font=\small] {no} (E);
\end{tikzpicture}
```
:::
::: {.column width="45%"}
![](figures/tikz-flowchart.svg){width=100%}
:::
::::

Named styles keep the node definitions clean and reusable. The `decnode` style uses TikZ's built-in `diamond` shape from `shapes.geometric`.


## TikZ: Plots with PGFPlots {.smaller}

:::: {.columns}
::: {.column width="55%"}
```latex
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{tikzpicture}
  \begin{axis}[
    xlabel={$x$}, ylabel={$f(x)$},
    grid=major, grid style={dashed, gray!30}
  ]
    \addplot[blue, thick, domain=-3:3, samples=60]{x^2};
    \addlegendentry{$x^2$}
    \addplot[red, thick, domain=-3:3, samples=60]{x^3/5};
    \addlegendentry{$x^3/5$}
  \end{axis}
\end{tikzpicture}
```
:::
::: {.column width="45%"}
![](figures/tikz-pgfplots.svg){width=100%}
:::
::::

PGFPlots can also read data from CSV files (`\addplot table {data.csv}`), making it suitable for publication-quality plots directly from experimental data.


## TikZ: Syntax Trees {.smaller}

:::: {.columns}
::: {.column width="55%"}
```latex
\usepackage{tikz-qtree}
\begin{tikzpicture}
  \Tree [.S
          [.NP Det N ]
          [.VP V
            [.NP Det N ]
          ]
        ]
\end{tikzpicture}
```
:::
::: {.column width="45%"}
![](figures/tikz-tree.svg){width=100%}
:::
::::

[`tikz-qtree`](https://ctan.org/pkg/tikz-qtree) uses a compact bracket notation. For more control (node styles, movement arrows, coindexation), use the full `tikz` library directly or [`forest`](https://ctan.org/pkg/forest) — a popular alternative for complex phrase structure trees.


## TikZ: Dependency Graphs and Glosses {.smaller}

The [`tikz-dependency`](https://ctan.org/pkg/tikz-dependency) package draws dependency arcs over interlinear glossed text — standard in typological and computational linguistics:

:::: {.columns}
::: {.column width="60%"}
```latex
\usepackage{tikz-dependency}

\begin{dependency}[theme=simple,
    label style={above, font=\small\itshape}]
  \begin{deptext}[column sep=1.2em]
    Der \& Mann \& gibt \& der \& Frau \& das \& Buch \\
    \textsc{det.m.nom} \& man.\textsc{nom} \& gives \&
      \textsc{det.f.dat} \& woman.\textsc{dat} \&
      \textsc{det.n.acc} \& book.\textsc{acc} \\
    `The \& man \& gives \& the \& woman \& the \& book' \\
  \end{deptext}
  \deproot{3}{root}
  \depedge{3}{2}{nsubj}
  \depedge{3}{5}{iobj}
  \depedge{3}{7}{obj}
  \depedge{2}{1}{det}
  \depedge{5}{4}{det}
  \depedge{7}{6}{det}
\end{dependency}
```
:::
::: {.column width="40%"}
![](figures/tikz-glosses.svg){width=100%}
:::
::::

::: {.callout-tip}
For complex figures, consider generating them in Python (`matplotlib` PGF backend) or R (`tikzDevice`) and importing the resulting `.tex` fragment.
:::


## Linguistics: Interlinear Glosses — [`gb4e`](https://ctan.org/pkg/gb4e) {.smaller}

The [`gb4e`](https://ctan.org/pkg/gb4e) package is the standard for numbered linguistic examples with interlinear glosses following the **Leipzig Glossing Rules**:

:::: {.columns}
::: {.column width="58%"}
```latex
\usepackage{gb4e}

\begin{exe}
  \ex \label{ex:german-dative}
  \gll Der Mann gibt    der   Frau   das   Buch. \\
       the.M man  gives the.F woman  the.N book \\
  \trans `The man gives the woman the book.'

  \ex[*]{
  \gll *Das Buch gibt der Frau der Mann. \\
        the.N book gives the.F woman the.M man \\
  \trans (ungrammatical word order)
  }

  \exi{(1a)}
  \gll \textsc{nom} \textsc{dat} \textsc{acc} \\
       subject indirect.object direct.object \\
  \trans Case roles in the German ditransitive construction.
\end{exe}

% Cross-reference later:
As shown in example (\ref{ex:german-dative}), ...
```
:::
::: {.column width="42%"}
**Rendered output:**

![](figures/gb4e-glosses.svg){width=100%}
:::
::::

- `\gll` starts the word-by-word alignment; `\\` separates tiers; `\trans` adds the free translation
- `\ex[*]` marks ungrammatical examples; `\exi` allows custom labels
- Alternative packages: [`linguex`](https://ctan.org/pkg/linguex) (more compact syntax), [`expex`](https://ctan.org/pkg/expex) (most flexible, recommended for complex data)

::: {.callout-tip}
Use `\textsc{nom}`, `\textsc{acc}`, `\textsc{dat}` etc. for Leipzig small-cap abbreviations. The [`leipzig`](https://ctan.org/pkg/leipzig) package provides pre-defined commands for all standard glossing abbreviations (`\Nom`, `\Acc`, `\Dat`, `\Sg`, `\Pl` …).
:::


## Linguistics: IPA Symbols {.smaller}

:::: {.columns}
::: {.column width="58%"}

**With XeLaTeX or LuaLaTeX — type Unicode directly:**

```latex
\usepackage{fontspec}
\setmainfont{Charis SIL}   % free SIL font with full IPA coverage
% alternatives: Doulos SIL, Gentium Plus, Linux Libertine

% In running text — paste Unicode IPA characters:
The high front vowel /iː/ contrasts with the lax /ɪ/ in English.
The retroflex stops [ʈ ɖ] are contrastive in Hindi.
Tone is marked with diacritics: /má/ (high) vs /mǎ/ (rising).

% Phonological rules:
/p, t, k/ → [pʰ, tʰ, kʰ] / _V  (aspirated before vowels)
```

**With pdfLaTeX — use [`tipa`](https://ctan.org/pkg/tipa):**

```latex
\usepackage{tipa}

\textipa{/\textphi \textbeta/}   % bilabial fricatives [ɸ β]
\textipa{[\textrtailt \textrtaild]}  % retroflex stops
\textipa{/m\'{a}/}               % high tone on /a/

% tipx extends tipa with additional symbols:
\usepackage{tipx}
```

:::
::: {.column width="42%"}

| Approach | Pro | Con |
|---|---|---|
| Unicode + [`fontspec`](https://ctan.org/pkg/fontspec) | Type IPA directly; readable source | Requires XeLaTeX/LuaLaTeX |
| [`tipa`](https://ctan.org/pkg/tipa) | Works with pdfLaTeX | Command-heavy; hard to read source |


**Rendered output:**

![](figures/ipa-symbols-render.svg){width=100%}
:::
::::

::: {.callout-note}
Most journal templates still require `pdflatex`. If you need IPA in a submission, use [`tipa`](https://ctan.org/pkg/tipa) for compatibility, or check if the journal accepts XeLaTeX/LuaLaTeX.
:::


## Linguistics: Optimality Theory Tableaux {.smaller}

The [`ot-tableau`](https://ctan.org/pkg/ot-tableau) package produces formatted OT constraint tableaux:

:::: {.columns}
::: {.column width="60%"}
```latex
\usepackage{ot-tableau}
\usepackage{pifont}  % for \HandRight winner symbol

% Column spec: c = solid border, : = dashed, | = solid between
\begin{tableau}{c:c:c|c}
\inp{/ɾ\textipa{E}to/}
  \const{*Complex} \const{Onset} \const{NoCoda} \const{Max}
\cand[\HandRight]{[ɾe.to]}
                              \vio{*}
\cand{[ɾet]}
               \vio{*}                           \vio{*}
\cand{[e.to]}
  \vio{*!}
\cand{[ɾ\textipa{E}.to]}
               \vio{*}        \vio{*!}
\end{tableau}
```

**Rendered output:**

![](figures/ot-tableau-render.svg){width=100%}

:::
::: {.column width="40%"}
**Key commands:**

| Command | Meaning |
|---|---|
| `\inp{...}` | Input form cell |
| `\const{...}` | Constraint header |
| `\cand{...}` | Candidate row |
| `\cand[\HandRight]{...}` | Optimal candidate |
| `\vio{*}` | One violation mark |
| `\vio{*!}` | Fatal violation |
| `\vio{**}` | Two violations |

Column spec characters: `c` (solid), `:` (dashed), `|` (solid within candidates)


:::
::::

::: {.callout-tip}
Load `\usepackage{tipa}` alongside [`ot-tableau`](https://ctan.org/pkg/ot-tableau) if your input/candidate cells contain IPA. The `\ipa{...}` shorthand in `ot-tableau` calls [`tipa`](https://ctan.org/pkg/tipa) internally.
:::


## Linguistics: Feature Structures (AVMs) {.smaller}

The [`langsci-avm`](https://ctan.org/pkg/langsci-avm) package typesets attribute-value matrices used in HPSG, LFG, and related frameworks:

:::: {.columns}
::: {.column width="55%"}
```latex
\usepackage{langsci-avm}

\avm{
  [ phon & < the, cat > \\
    synsem & [ local & [
      cat & [ head & noun \\
              valence & [ spr & < > \\
                          comps & < > ] ] \\
      cont & [ index & i \\
               restr & < [ reln & cat \\
                            arg0 & i ] > ] ] ]
}
```

**Structure:**

- `\avm{ ... }` — root AVM command
- `[ attr & val \\ attr2 & val2 ]` — attribute-value pairs
- `< ... >` — lists (sequences)
- Nested brackets for embedded feature structures
- Matrices nest freely for complex feature geometries

:::
::: {.column width="45%"}

**Rendered output:**

![](figures/avm-render.svg){width=100%}
:::
::::


## Linguistics: Formal Semantics {.smaller}

Lambda calculus and model-theoretic notation use standard LaTeX math mode — no special package needed for the core notation:

:::: {.columns}
::: {.column width="55%"}
```latex
\usepackage{stmaryrd}
\usepackage{amsmath,amssymb,mathtools}

\newcommand{\sv}[1]{\llbracket #1 \rrbracket}

% Lexical denotations:
\[
\sv{\textit{cat}} = \lambda x_e .\ \text{cat}(x)
\]
\[
\sv{\textit{runs}} = \lambda x_e .\ \lambda e_v .\
  	ext{run}(e) \wedge \text{Agent}(e,x)
\]

% Quantification:
\[
\sv{\textit{every cat}} =
  \lambda P_{\langle e,t \rangle} .\
  \forall x[\text{cat}(x) \rightarrow P(x)]
\]

% Type reminder:
\sv{\textit{runs}} : \langle e,\langle v,t\rangle\rangle
```
:::
::: {.column width="45%"}
**Structure:**

- `\sv{...}` shorthand for semantic brackets
- `\lambda x_e` typed lambda variables
- `\forall` and `\rightarrow` for generalized quantifier notation
- Angle-bracket types like `\langle e,t \rangle`

**Rendered output:**

![](figures/semantics-render.svg){width=100%}
:::
::::

::: {.callout-tip}
Key packages: [`stmaryrd`](https://ctan.org/pkg/stmaryrd) for `\llbracket`/`\rrbracket` brackets; [`amssymb`](https://ctan.org/pkg/amssymb) for logical operators (`\forall`, `\exists`, `\wedge` …); [`mathtools`](https://ctan.org/pkg/mathtools) for extended math syntax. For frequently used brackets, define shorthands: `\newcommand{\sv}[1]{\llbracket #1 \rrbracket}` so you can write `\sv{\text{runs}}` instead of the full bracket pair each time.
:::


## Templates: Journals and Theses {.smaller}


**Journal templates** provide `.cls` and `.sty` files that enforce house style:

| Source | What you get |
|---|---|
| [Overleaf Gallery — Journals](https://www.overleaf.com/gallery/tagged/academic-journal) | Templates for hundreds of journals |
| Publisher websites | ACL, IEEE, Springer, Elsevier all provide LaTeX kits |
| CTAN journal classes | [`elsarticle`](https://ctan.org/pkg/elsarticle), [`acmart`](https://ctan.org/pkg/acmart), [`IEEEtran`](https://ctan.org/pkg/ieeetran) and many more |

**Thesis templates:**

| Source | Link |
|---|---|
| Overleaf Thesis Gallery | [overleaf.com/gallery/tagged/thesis](https://www.overleaf.com/gallery/tagged/thesis) |
| Universität zu Köln | Check your faculty's doctoral office for approved templates |
| GitHub | Search `latex thesis template <university>` |

**Starting from a template:**

1. Download the template folder
2. Fill in `main.tex`; delete the placeholder content
3. Point `\addbibresource` to your Zotero-exported `.bib` file
4. Compile and iteratively fix errors


## Debugging LaTeX: Reading Error Messages {.smaller}

LaTeX error messages appear in the log file. The key pattern:

```
! LaTeX Error: File `missfont.fd' not found.
l.42 \begin{document}
```

- `!` marks the error type
- The next line describes the problem
- `l.42` tells you the source line where LaTeX stopped

**Common errors and fixes:**

| Error | Likely cause | Fix |
|---|---|---|
| `Undefined control sequence` | Typo in command or missing package | Check spelling; add the right `\usepackage` |
| `Missing $ inserted` | Math symbol outside math mode | Wrap in `$...$` |
| `File not found` | Missing image or `.bib` file | Check filename and path |
| `Runaway argument` | Unclosed `{` brace | Count `{` and `}` carefully |
| `Too many }'s` | Extra closing brace | Remove the extra `}` |

::: {.callout-tip}
Compile often — catching one error at a time is much easier than debugging 20 at once. Search the error message on [tex.stackexchange.com](https://tex.stackexchange.com) — most errors are already answered there.
:::


## Summary

:::: {.columns}
::: {.column}
**Document organisation**

- `report`/`book` class for long documents
- `\input` / `\include` for multi-file projects
- Recommended folder structure for theses

**Bibliography workflow**

- Zotero collects and organises references
- BetterBibTeX auto-exports a continuously updated `.bib` file
- `biblatex` + `biber` for modern citation management
:::
::: {.column}
**Advanced tools**

- **Quarto** — analysis + prose in one file; PDF via LaTeX
- **TikZ** — programmatic vector figures in LaTeX
- **Templates** — start from a journal or thesis template

**Debugging**

- Read the error message and the line number
- Compile often; fix one error at a time

::: {.callout-note .smaller}
All materials: [dkz2r.de/tags/latex](https://www.dkz2r.de/tags/latex/)
:::
:::
::::


## Resources

- [lshort — The Not So Short Introduction to LaTeX](https://www.ctan.org/pkg/lshort)
- [Zotero — Reference Manager](https://www.zotero.org)
- [BetterBibTeX for Zotero](https://retorque.re/zotero-better-bibtex/)
- [biblatex documentation (CTAN)](https://ctan.org/pkg/biblatex)
- [biblatex-apa — APA 7th edition style](https://ctan.org/pkg/biblatex-apa)
- [papaja — APA manuscripts with R/Quarto](https://github.com/crsh/papaja)
- [Quarto — Scientific Publishing](https://quarto.org)
- [TikZ & PGF documentation](https://ctan.org/pkg/pgf)
- [tikz.dev — TikZ reference](https://tikz.dev)
- [PGFPlots — plots in LaTeX](https://ctan.org/pkg/pgfplots)
- [Overleaf — Collaborative LaTeX Editor](https://www.overleaf.com)
- [Overleaf thesis templates](https://www.overleaf.com/gallery/tagged/thesis)
- [DKZ.2R: LaTeX for Novices — Academic Publishing](https://dkz2r.github.io/latex-novice-academic-publishing/)
- [Prism — OpenAI's AI-native LaTeX workspace](https://prism.openai.com)
- [TeXlyre — Open-source, local-first LaTeX editor](https://texlyre.github.io/texlyre/)
- [tex.stackexchange.com](https://tex.stackexchange.com)


## References
