# plasma_posters.poster

*module*

A poster: blocks of text and figures in columns, written as LaTeX and compiled to PDF.

The LaTeX uses the `tikzposter <https://ctan.org/pkg/tikzposter>`_ class. Text, titles and
captions are LaTeX, so they can hold maths (``$E = mc^2$``) and commands; they are not escaped.

>>> poster = Poster("Negative ion beams", authors="Max Lindqvist", columns=2)
>>> poster.block("Motivation", r"Beams of $\mathrm{H}^-$ ions.")
>>> poster.figure("Domain", "domain.pdf", caption="The extraction region.", column=1)
>>> poster.to_latex().startswith(r"\documentclass")
True

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L1-L1)

## plasma_posters.poster.ORIENTATIONS

*attribute* · *module attribute*

```python
ORIENTATIONS = ('portrait', 'landscape')
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L29-L29)

## plasma_posters.poster.SIZES

*attribute* · *module attribute*

```python
SIZES = ('a0', 'a1', 'a2')
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L26-L26)

## plasma_posters.poster.Block

*class* · *dataclass*

```python
class Block
```

A titled block of a poster column.

**Attributes**

- `title` (`str`) — The block's heading (LaTeX).
- `body` (`str`) — The block's content (LaTeX).
- `column` (`int`) — The index of the column the block is in, from 0.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L122-L134)

### plasma_posters.poster.Block.body

*attribute* · *instance attribute*

```python
body: str
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L133-L133)

### plasma_posters.poster.Block.column

*attribute* · *class attribute* · *instance attribute*

```python
column: int = 0
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L134-L134)

### plasma_posters.poster.Block.title

*attribute* · *instance attribute*

```python
title: str
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L132-L132)

## plasma_posters.poster.Poster

*class* · *dataclass*

```python
class Poster
```

A scientific poster: a title, authors, and blocks of text and figures in columns.

**Attributes**

- `title` (`str`) — The poster's title (LaTeX).
- `authors` (`str`) — The authors, as one line (LaTeX).
- `institute` (`str`) — The authors' institute, below the authors (LaTeX); empty for none.
- `size` (`str`) — The paper size, one of :data:`SIZES`.
- `orientation` (`str`) — ``"portrait"`` or ``"landscape"``.
- `columns` (`int`) — The number of columns, of equal width.
- `blocks` (`list[Block]`) — The blocks, in the order they were added.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L171-L307)

### plasma_posters.poster.Poster.authors

*attribute* · *class attribute* · *instance attribute*

```python
authors: str = ''
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L186-L186)

### plasma_posters.poster.Poster.blocks

*attribute* · *class attribute* · *instance attribute*

```python
blocks: list[Block] = field(default_factory=list)
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L191-L191)

### plasma_posters.poster.Poster.columns

*attribute* · *class attribute* · *instance attribute*

```python
columns: int = 2
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L190-L190)

### plasma_posters.poster.Poster.institute

*attribute* · *class attribute* · *instance attribute*

```python
institute: str = ''
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L187-L187)

### plasma_posters.poster.Poster.orientation

*attribute* · *class attribute* · *instance attribute*

```python
orientation: str = 'portrait'
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L189-L189)

### plasma_posters.poster.Poster.size

*attribute* · *class attribute* · *instance attribute*

```python
size: str = 'a0'
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L188-L188)

### plasma_posters.poster.Poster.title

*attribute* · *instance attribute*

```python
title: str
```

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L185-L185)

### plasma_posters.poster.Poster.block

*method*

```python
def block(title: str, body: str, column: int = 0) -> None
```

Add a block of text.

**Parameters**

- `title` (`str`) — The block's heading (LaTeX).
- `body` (`str`) — The text (LaTeX); paragraphs are separated by blank lines. Its common indentation is removed, so it can be an indented triple-quoted string.
- `column` (`int`) (default: `0`) — The column to put the block in, from 0; blocks of a column are stacked in the order they are added.

**Raises**

- `ValueError` — If the column does not exist.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L204-L221)

### plasma_posters.poster.Poster.build

*method*

```python
def build(path: str | Path, engine: str = 'lualatex') -> Path
```

Write the poster's LaTeX next to ``path`` and compile it to a PDF.

**Parameters**

- `path` (`str | Path`) — The PDF to write, e.g. ``"poster.pdf"``; its ``.tex`` is written next to it.
- `engine` (`str`) (default: `'lualatex'`) — The LaTeX program, ``"lualatex"`` or ``"pdflatex"``.

**Returns**

- (`Path`) — The PDF's path.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L296-L307)

### plasma_posters.poster.Poster.figure

*method*

```python
def figure(title: str, path: str | Path, caption: str = '', width: float = 0.95, column: int = 0) -> None
```

Add a block with a figure.

**Parameters**

- `title` (`str`) — The block's heading (LaTeX).
- `path` (`str | Path`) — The figure file (PDF, PNG or JPEG), relative to the poster's ``.tex`` file or absolute.
- `caption` (`str`) (default: `''`) — The caption below the figure (LaTeX); empty for none.
- `width` (`float`) (default: `0.95`) — The figure's width as a fraction of the column's width.
- `column` (`int`) (default: `0`) — The column to put the block in, from 0.

**Raises**

- `ValueError` — If the width is not in (0, 1] or the column does not exist.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L223-L251)

### plasma_posters.poster.Poster.save

*method*

```python
def save(path: str | Path) -> Path
```

Write the poster's LaTeX to a file.

**Parameters**

- `path` (`str | Path`) — The ``.tex`` file to write.

**Returns**

- (`Path`) — The path written.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L283-L294)

### plasma_posters.poster.Poster.to_latex

*method*

```python
def to_latex() -> str
```

The poster as a LaTeX document.

**Returns**

- (`str`) — The complete document, for ``lualatex`` or ``pdflatex``.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L253-L281)

## plasma_posters.poster.compile_latex

*function*

```python
def compile_latex(tex: str | Path, engine: str = 'lualatex') -> Path
```

Compile a LaTeX file to a PDF next to it.

**Parameters**

- `tex` (`str | Path`) — The ``.tex`` file; figure paths in it are relative to its folder.
- `engine` (`str`) (default: `'lualatex'`) — The LaTeX program, ``"lualatex"`` or ``"pdflatex"``.

**Returns**

- (`Path`) — The PDF's path.

**Raises**

- `FileNotFoundError` — If the LaTeX program is not installed.
- `RuntimeError` — If LaTeX fails; the message ends with the end of its log.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L137-L168)

## plasma_posters.poster.preview

*function*

```python
def preview(pdf: str | Path, png: str | Path | None = None, dpi: int = 30, page: int = 1) -> Path
```

Render a page of a PDF as a PNG, to check its layout.

Uses ``pdftoppm`` from poppler (``poppler-utils`` on Debian and Ubuntu, ``poppler`` in
Homebrew).

**Parameters**

- `pdf` (`str | Path`) — The PDF, e.g. a poster's.
- `png` (`str | Path | None`) (default: `None`) — The PNG to write; next to the PDF with the same name when None.
- `dpi` (`int`) (default: `30`) — The resolution; 30 gives an A0 page about 1000 pixels high.
- `page` (`int`) (default: `1`) — The page to render, from 1.

**Returns**

- (`Path`) — The PNG's path.

**Raises**

- `ValueError` — If the page is less than 1.
- `FileNotFoundError` — If pdftoppm is not installed.
- `RuntimeError` — If pdftoppm fails, e.g. on a page the PDF does not have.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L46-L77)

## plasma_posters.poster.preview_pages

*function*

```python
def preview_pages(pdf: str | Path, folder: str | Path | None = None, dpi: int = 30) -> list[Path]
```

Render every page of a PDF as a PNG, e.g. the slides of a talk.

The PNGs are ``<name>-<page>.png`` (with pdftoppm's zero padding, ``talk-01.png`` for a
PDF of 10 to 99 pages); earlier PNGs of that name in the folder are removed first, so the
list holds only this PDF's pages.

**Parameters**

- `pdf` (`str | Path`) — The PDF.
- `folder` (`str | Path | None`) (default: `None`) — The folder for the PNGs; the PDF's folder when None.
- `dpi` (`int`) (default: `30`) — The resolution; 30 gives an A0 page about 1000 pixels high, a 16:9 slide (16 cm wide) about 190 pixels wide, 100 a slide about 630 pixels wide.

**Returns**

- (`list[Path]`) — The PNGs, in page order.

**Raises**

- `FileNotFoundError` — If pdftoppm is not installed.
- `RuntimeError` — If pdftoppm fails.

[View source](https://github.com/max-models/plasma-posters/blob/devel/src/plasma_posters/poster.py#L80-L119)
