Skip to content
Projects

plasma_posters.poster

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 H−\mathrm{H}^- ions.”) poster.figure(“Domain”, “domain.pdf”, caption=“The extraction region.”, column=1) poster.to_latex().startswith(r”\documentclass”) True

Attributes

NameDescription
ORIENTATIONSNo description.
SIZESNo description.

Classes

NameDescription
BlockA titled block of a poster column.
PosterA scientific poster: a title, authors, and blocks of text and figures in columns.

Functions

NameDescription
compile_latexCompile a LaTeX file to a PDF next to it.
previewRender a page of a PDF as a PNG, to check its layout.
preview_pagesRender every page of a PDF as a PNG, e.g. the slides of a talk.

ORIENTATIONSattributemodule attribute#

ORIENTATIONS = ('portrait', 'landscape')

SIZESattributemodule attribute#

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

Blockclassdataclass#

class Block(title: str, body: str, column: int = 0)

A titled block of a poster column.

Attributes

NameTypeDescription
titlestrThe block’s heading (LaTeX).
bodystrThe block’s content (LaTeX).
columnintThe index of the column the block is in, from 0.

bodyattributeinstance attribute#

body: str

columnattributeclass attributeinstance attribute#

column: int = 0

titleattributeinstance attribute#

title: str

Posterclassdataclass#

class Poster(title: str, authors: str = '', institute: str = '', size: str = 'a0', orientation: str = 'portrait', columns: int = 2, blocks: list[Block] = list())

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

Attributes

NameTypeDescription
titlestrThe poster’s title (LaTeX).
authorsstrThe authors, as one line (LaTeX).
institutestrThe authors’ institute, below the authors (LaTeX); empty for none.
sizestrThe paper size, one of :data:SIZES.
orientationstr"portrait" or "landscape".
columnsintThe number of columns, of equal width.
blockslist[Block]The blocks, in the order they were added.

authorsattributeclass attributeinstance attribute#

authors: str = ''

blocksattributeclass attributeinstance attribute#

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

columnsattributeclass attributeinstance attribute#

columns: int = 2

instituteattributeclass attributeinstance attribute#

institute: str = ''

orientationattributeclass attributeinstance attribute#

orientation: str = 'portrait'

sizeattributeclass attributeinstance attribute#

size: str = 'a0'

titleattributeinstance attribute#

title: str

blockmethod#

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

Add a block of text.

Parameters

NameTypeDefaultDescription
titlestrrequiredThe block’s heading (LaTeX).
bodystrrequiredThe text (LaTeX); paragraphs are separated by blank lines. Its common indentation is removed, so it can be an indented triple-quoted string.
columnint0The 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.

buildmethod#

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

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

Parameters

NameTypeDefaultDescription
pathstr | PathrequiredThe PDF to write, e.g. "poster.pdf"; its .tex is written next to it.
enginestr'lualatex'The LaTeX program, "lualatex" or "pdflatex".

Returns

Path
The PDF’s path.

figuremethod#

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

Add a block with a figure.

Parameters

NameTypeDefaultDescription
titlestrrequiredThe block’s heading (LaTeX).
pathstr | PathrequiredThe figure file (PDF, PNG or JPEG), relative to the poster’s .tex file or absolute.
captionstr''The caption below the figure (LaTeX); empty for none.
widthfloat0.95The figure’s width as a fraction of the column’s width.
columnint0The column to put the block in, from 0.

Raises

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

savemethod#

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

Write the poster’s LaTeX to a file.

Parameters

NameTypeDescription
pathstr | PathThe .tex file to write.

Returns

Path
The path written.

to_latexmethod#

def to_latex() -> str

The poster as a LaTeX document.

Returns

str
The complete document, for lualatex or pdflatex.

compile_latexfunction#

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

Compile a LaTeX file to a PDF next to it.

Parameters

NameTypeDefaultDescription
texstr | PathrequiredThe .tex file; figure paths in it are relative to its folder.
enginestr'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.

previewfunction#

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

NameTypeDefaultDescription
pdfstr | PathrequiredThe PDF, e.g. a poster’s.
pngstr | Path | NoneNoneThe PNG to write; next to the PDF with the same name when None.
dpiint30The resolution; 30 gives an A0 page about 1000 pixels high.
pageint1The 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.

preview_pagesfunction#

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

NameTypeDefaultDescription
pdfstr | PathrequiredThe PDF.
folderstr | Path | NoneNoneThe folder for the PNGs; the PDF’s folder when None.
dpiint30The 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.