research_helpers.textmath
This module sets the maths of a table or a caption as text, in the float’s own typeface. See Maths in the table’s typeface.
- exception research_helpers.textmath.UnsupportedMathError[source]
Bases:
ValueErrorRaised for maths outside the subset that can be set as text.
- research_helpers.textmath.render(items, *, script)[source]
Return parsed items as text, with TeX’s spacing between atoms.
- research_helpers.textmath.to_text(expression)[source]
Rewrite one maths expression as text set by
rhtextmath.sty.The supported subset: Latin letters, numbers (with
{,}as a thousands separator), Greek letters, the common relations (= < > \le \ge \ne \approx \sim \in \propto, and a few more), binary operators (+ - \times \cdot \pm), operator names (\log \max \min \exp,\operatorname{...}), text (\text \mathrm \mathit \mathbf), one level of sub- and superscript,\bar, absolute-value bars, brackets, and explicit spacing.\leftand\rightare dropped and their delimiters kept.- Parameters:
expression (
str) – the maths, without its delimiters, e.g.'Q_{ov}'or'9.8\times 10^{-4}'.- Return type:
- Returns:
Text-mode LaTeX, e.g.
'\textit{Q}\tmsubx{\textit{ov}}'or'9.8\tmmed{}×\tmmed{}10\tmsup{−4}'.- Raises:
UnsupportedMathError – if the expression uses anything outside the subset.
- research_helpers.textmath.convert(latex)[source]
Rewrite every inline maths expression in a piece of LaTeX as text.
Both
\(...\)and$...$are converted. A backslash is read with the character after it, as TeX reads it, so an escaped\$or the\\of a line break before a parenthesis opens no maths. Display maths is left alone.- Parameters:
latex (
str) – a cell, a caption, or a whole float.- Return type:
- Returns:
The same LaTeX, with no inline maths left in it.
- Raises:
UnsupportedMathError – if any expression uses anything outside the subset ‘to_text’ supports, or is not closed.