pygacity.pythontex.texutils module¶
TeX utility functions for pygacity
- pygacity.pythontex.texutils.Cp_as_tex(Cp_coeff: dict | list, decoration='*', sig: int = 5, inline: bool = False) str[source]¶
Formats a heat capacity polynomial as a LaTeX string.
- Parameters:
- Returns:
retstr – LaTeX formatted heat capacity polynomial string
- Return type:
- pygacity.pythontex.texutils.algebraify(expression: str, varvals: dict[str, any] | list[str], varsig: dict[str, int] = {}) str | tuple[str, str][source]¶
Substitute variables into an algebraic expression with intelligent formatting.
- Parameters:
expression (str) – Algebraic expression with variables in {varname} format
varvals (dict[str, any] or list[str]) – If list: variable names to substitute symbolically If dict: variable names mapped to their values (str for symbols, float for numerics)
varsig (dict[str, int], optional) – Variable names mapped to significant figures for numeric values
- Returns:
If varvals is a list: returns the symbolic expression If varvals is a dict: returns (symbolic_expression, numerical_expression)
- Return type:
- pygacity.pythontex.texutils.file_listing(filename: str, style: str = 'mypython') str[source]¶
Generates a LaTeX lstinputlisting command string for including a file.
- pygacity.pythontex.texutils.format_sig(x: float | Quantity, sig: int = 5, use_tex: bool = True) str[source]¶
Formats a floating point number to a specified number of significant figures.
- pygacity.pythontex.texutils.frac_or_int_as_tex(f: Fraction) str[source]¶
Formats a Fraction as a LaTeX string, using frac{}{} if necessary.
- Parameters:
f (fr.Fraction) – the fraction to format
- Returns:
LaTeX formatted string
- Return type:
- pygacity.pythontex.texutils.latex_quotes(s: str) str[source]¶
Converts straight double-quotes in a string to LaTeX-style curly quotes.
Each
"is replaced alternately with ` `` ` (opening) and''(closing).
- pygacity.pythontex.texutils.polynomial_as_tex(p: Polynomial, x: str = 'x', coeff_round: int = 0)[source]¶
Formats a numpy Polynomial as a LaTeX string.
- pygacity.pythontex.texutils.table_as_tex(table: dict | DataFrame, sig: int = 5, drop_zeros: list[bool] = None, total_row: list[str] = [], index: bool = False, use_tex: bool = True) str[source]¶
A wrapper to Dataframe.to_latex() that takes a dictionary of heading: column items and generates a table
- Parameters:
table (dict or pd.DataFrame) – dictionary of column_name: list_of_column_values or a ready DataFrame
sig (int, optional) – number of significant figures for floating point numbers; default is 5
drop_zeros (list of bool, optional) – list of booleans parallel to table keys indicating whether to drop rows with zero in that column; default is None
total_row (list, optional) – list of strings representing a total row to be added at the bottom of the table; default is empty list
index (bool, optional) – whether to include the DataFrame index in the LaTeX table; default is False
use_tex (bool, optional) – whether to format numbers using (…) so they appear in math mode; default is True
- Returns:
tablestring – LaTeX formatted table string
- Return type: