[Guide](https://komalang.org/guide/) · 6 of 8

# Figures, tables and math

Bring in pictures and data, and write math as you would in LaTeX.

## Bring in data

A figure can refer to an image file. A table can read a CSV. Paths are relative to the document’s folder.

```koma
[title: Three rooms]
[subtitle: Echo time after a balloon pop]
[main:
  [col:
    [figure:
      [image src="assets/decay.svg" alt="Sound level falling over time in three rooms":]
      Level after the balloon pop
    ]
  ]
  [col:
    [table src="assets/rooms.csv" widths=(2, 1, 1):
      The rooms we measured
    ]
  ]
]
```

> A chart and table compare how long sound takes to fade in three rooms.

## Write math

Type a formula between `$` signs within text, or use `$$` on separate lines to give it a line of its own.

```koma
[title: Break a wave into frequencies]
[subtitle: The Fourier transform]
[main:
  **Fourier transform** finds tones.[^f]

  - $f(t)$ is the signal in time.
  - $\hat{f}(\omega)$ is the spectrum.

  $$
  \hat{f}(\omega) = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^{\infty} f(t)\,e^{-i\omega t}\,dt
  $$

  [^f]: The inverse recovers $f(t)$.
]
```

> The Fourier transform, with a bold term, two bullet points, a footnote, and a displayed equation showing a fraction and an integral.

## Choose a math face

A theme draws its math in one face. `style="--math-font: fira"` on an element draws the math inside it in another (`fira`, `stix2` or `newcm`), nested elements included.

```koma
[title: One formula, two math fonts]
[subtitle: Pick the face by where the formula sits]
[main:
  [col style="--math-font: stix2":
    **STIX** — for the text

    $$
    \omega = \Omega\cos\varphi + \alpha
    $$
  ]
  [col style="--math-font: fira":
    **Fira** — for a figure

    $$
    \omega = \Omega\cos\varphi + \alpha
    $$
  ]
]
```

> A slide titled “One formula, two math fonts”: on the left, labelled STIX — for the text, the formula ω = Ω cos φ + α in serif STIX letters; on the right, labelled Fira — for a figure, the same formula in sans-serif Fira letters, Greek included.

## Write chemistry

Inside math, `\ce{…}` writes formulas and reactions as the mhchem package does: numbers become subscripts (`\ce{H2O}`), a charge follows `^` (`\ce{Fe^3+}`), and `->` is the arrow of a reaction.

For ring structures like the ones below, insert an SVG image. The formulas under the rings use `\ce{…}`.

```koma
[title: One aromatic ring, two molecules]
[subtitle: Phenol has a hydroxyl group in place of one hydrogen]
[main:
  [col:
    [figure h=480px:
      [image src="assets/benzene-ring.svg" alt="A hexagonal benzene ring with a circle inside":]
      Benzene · $\ce{C6H6}$
    ]
  ]
  [col:
    [figure h=480px:
      [image src="assets/phenol-ring.svg" alt="The same aromatic ring with one OH group bonded to a corner":]
      Phenol · $\ce{C6H5OH}$
    ]
  ]
]
```

> A slide compares benzene on the left and phenol on the right. Both are drawn as a hexagon with an inner circle. Phenol has an OH group bonded to one corner. The formulas beneath are C6H6 and C6H5OH.

## Related rules

- [Inline and display math](https://komalang.org/spec/lexical/#math-delimiters)
- [Code and math are isolated](https://komalang.org/spec/lexical/#isolation)

- [Text faces](https://komalang.org/spec/styles/#text-faces)
