Skip to main content

TeXRenderer

ClassSource

TeXRenderer(
path_temp: str | PathLike[str] | None = None, verbose: bool = False
)

The LaTeX renderer.

Render the LaTeX equation to pixel image. The backend is implemented by calling the latex command. Therefore, using this renderer requires the installation of a LaTeX released version.

Arguments​

Requires​

NameTypeRequired
Description
path_tempstr | PathLike[str] | NoneThe path to the folder storing the temporary files. If not specified, will create a folder in the temp path,
verboseboolWhether to show the running details of LaTeX.

Methods​

get_template​

v_1: TeXTemplate = TeXRenderer.get_template(template: str | TeXTemplate = "default")

Get the LaTeX rendering template by specifying the template name.

Requires​

NameTypeRequired
Description
templatestr | TeXTemplateThe name of the template.

Returns​

NameType
Description
v_1TeXTemplateThe fetched LaTeX template.

render​

v_1: Image = self.render(equation: str, template: str | TeXTemplate = "default")

Render the equation into a pixel-based image.

Requires​

NameTypeRequired
Description
equationstr

The LaTeX equation. This equation is treated as a block equation.

Do not need to specify $ or $$ symbol.

templatestr | TeXTemplate

The LaTeX template used for rendering the equation. If using str, this value will be treated as the template name. Users can provide self-implemented template by instantiate TeXTemplate.

Check improc.variables.tex_templates to view the currently supported templates.

Returns​

NameType
Description
v_1ImageThe image rendered from the LaTeX equation.

render_png​

self.render_png(
out_file: str | PathLike[str],
equation: str,
template: str | TeXTemplate = "default",
bg_color: str | tuple[float, ...] = "#1b2838",
fg_color: str | tuple[float, ...] = "#ffffff",
out_width: int = 3000,
)

Render the equation as a PNG file.

This method is recommended for previewing the rendered equations.

Requires​

NameTypeRequired
Description
out_filestr | PathLike[str]The path to the output file.
equationstr

The LaTeX equation. This equation is treated as a block equation.

Do not need to specify $ or $$ symbol.

templatestr | TeXTemplate

The LaTeX template used for rendering the equation. If using str, this value will be treated as the template name. Users can provide self-implemented template by instantiate TeXTemplate.

Check improc.variables.tex_templates to view the currently supported templates.

bg_colorstr | tuple[float, ...]The background color of the rendered image.
fg_colorstr | tuple[float, ...]The foreground (text) color.
out_widthint

The width of the output image. If the rendered equation is not long enough, will place the equation in the center of the image.

This option ensures that every output file to have the same image width.