research_helpers.latex

This module covers LaTeX table assembly. See LaTeX tables.

research_helpers.latex.table(*, spec, header_rows, body_rows, caption, label, wide=False, prologue=None, environment=DEFAULT_ENVIRONMENT, width=None, column_width_in=None, setup=None, style=DEFAULT_STYLE, chktex=True)[source]

Assemble one table as a LaTeX float.

Parameters:
  • spec (str) – column specification, e.g. ‘LRRCC’ for tabulary or ‘Xllrr’ for tabularx.

  • header_rows (list[list[str]]) – one list of already-formatted cells per header line.

  • body_rows (list[list[str]]) – the data rows, cells already formatted as strings.

  • caption (str) – caption text, as LaTeX.

  • label (str) – the ‘\label’ value, e.g. ‘tab:morph-curve’. Also the table’s identity.

  • wide (bool, default: False) – use ‘table*’, spanning both columns.

  • prologue (list[str] | None, default: None) – raw lines inserted after the first header row, e.g. a ‘\cmidrule’.

  • environment (str, default: DEFAULT_ENVIRONMENT) – the tabular environment, e.g. ‘tabulary’, ‘tabularx’ or ‘tabular’.

  • width (str | None, default: None) – explicit width for the environments that take one. Defaults to ‘\textwidth’ or column width.

  • column_width_in (float | None, default: None) – overrides the project’s ‘\columnwidth’ for this call.

  • setup (str | None, default: None) – raw commands emitted inside the float, before the tabular begins.

  • style (str, default: DEFAULT_STYLE) – font commands applied inside the float.

  • chktex (bool, default: True) – emit the chktex suppression comment after the label.

Return type:

str

Returns:

The complete float, ending in a newline.

research_helpers.latex.header(text, expand=None, size=DEFAULT_HEADER_SIZE)[source]

Format a header cell.

Parameters:
  • text (str) – the heading.

  • expand (str | None, default: None) – padding placed either side of a heading shorter than ‘SHORT_HEADER’ characters, e.g. ‘~’ or ‘~~~~’.

  • size (str, default: DEFAULT_HEADER_SIZE) – the size command applied, without its backslash.

Return type:

str

Returns:

The cell, as LaTeX.

research_helpers.latex.half_up(value, places=2)[source]

Round half away from zero, the way a reader expects and ‘format’ does not.

Parameters:
  • value (float) – the number to round.

  • places (int, default: 2) – decimal places to keep.

Return type:

str

Returns:

The rounded number, as a string with exactly ‘places’ decimals.

research_helpers.latex.bare(text)[source]

Drop the leading zero from every number in ‘text’.

Parameters:

text (str) – formatted text, e.g. ‘0.82’.

Return type:

str

Returns:

The text with leading zeroes removed, e.g. ‘.82’.

research_helpers.latex.dash_range(text, dash='--')[source]

Typeset a range with an en-dash.

Parameters:
  • text (str) – a range written with a hyphen, e.g. ‘1337-1362’.

  • dash (str, default: '--') – what to replace the hyphen with, e.g. ‘–’ (an en-dash in LaTeX).

Return type:

str

Returns:

The range, typeset.