Ziamath Classes¶
- class ziamath.zmath.Math(mathml: Union[str, Element], size: float = 24, font: Optional[str] = None)¶
MathML Element Renderer
- Parameters
mathml – MathML expression, in string or XML Element
size – Base font size, pixels
font – Filename of font file. Must contain MATH typesetting table.
- drawon(svg: Element, x: float = 0, y: float = 0, halign: Literal['left', 'center', 'right'] = 'left', valign: Literal['top', 'center', 'base', 'axis', 'bottom'] = 'base') Element ¶
Draw the math expression on an existing SVG
- Parameters
x – Horizontal position in SVG coordinates
y – Vertical position in SVG coordinates
svg – The image (top-level svg XML object) to draw on
halign – Horizontal alignment
valign – Vertical alignment
Note: Horizontal alignment can be the typical ‘left’, ‘center’, or ‘right’. Vertical alignment can be ‘top’, ‘bottom’, or ‘center’ to align with the expression’s bounding box, or ‘base’ to align with the bottom of the first text element, or ‘axis’, aligning with the height of a minus sign above the baseline.
- classmethod fromlatex(latex: str, size: float = 24, mathstyle: Optional[str] = None, font: Optional[str] = None, color: Optional[str] = None)¶
Create Math Renderer from a single LaTeX expression. Requires latex2mathml Python package.
- Parameters
latex – Latex string
size – Base font size
mathstyle – Style parameter for math, equivalent to “mathvariant” MathML attribute
font – Font file name
color – Color parameter, equivalent to “mathcolor” attribute
- classmethod fromlatextext(latex: str, size: float = 24, mathstyle: Optional[str] = None, textstyle: Optional[str] = None, font: Optional[str] = None, color: Optional[str] = None)¶
Create Math Renderer from a sentence containing zero or more LaTeX expressions delimited by $..$, resulting in single MathML element. Requires latex2mathml Python package.
- Parameters
latex – string
size – Base font size
mathstyle – Style parameter for math, equivalent to “mathvariant” MathML attribute
textstyle – Style parameter for text, equivalent to “mathvariant” MathML attribute
font – Font file name
color – Color parameter, equivalent to “mathcolor” attribute
- getsize() tuple[float, float] ¶
Get size of rendered text
- getyofst() float ¶
Y-shift from bottom of bbox to 0
- classmethod mathml2svg(mathml: Union[str, Element], size: float = 24, font: Optional[str] = None)¶
Shortcut to just return SVG string directly
- save(fname)¶
Save expression to SVG file
- svg() str ¶
Get expression as SVG string
- svgxml() Element ¶
Get standalone SVG of expression as XML Element Tree
- class ziamath.zmath.Text(s, textfont: Optional[str] = None, mathfont: Optional[str] = None, mathstyle: Optional[str] = None, size: float = 24, linespacing: float = 1, color: Optional[str] = None, halign: str = 'left', valign: str = 'base', rotation: float = 0, rotation_mode: str = 'anchor')¶
Mixed text and latex math, with math delimited by $..$. Drawn to SVG. Can contain multiple lines.
- Parameters
s – string to write
textfont – font filename or family name for text
mathfont – font filename for math
mathstyle – Style parameter for math
size – font size in points
linespacing – spacing between lines
color – color of text
halign – horizontal alignment
valign – vertical alignment
rotation – Rotation angle in degrees
rotation_mode – Either ‘default’ or ‘anchor’, to mimic Matplotlib behavoir. See: https://matplotlib.org/stable/gallery/text_labels_and_annotations/demo_text_rotation_mode.html
- bbox()¶
Get bounding box (xmin, xmax, ymin, ymax) of Text.
- drawon(svg: Element, x: float = 0, y: float = 0, halign: Optional[str] = None, valign: Optional[str] = None) Element ¶
Draw text on existing SVG element
- Parameters
svg – Element to draw on
x – x-position
y – y-position
halign – Horizontal alignment
valign – Vertical alignment
- getsize()¶
Get pixel width and height of Text.
- save(fname)¶
Save expression to SVG file
- svg() str ¶
Get expression as SVG string
- svgxml() Element ¶
Get standalone SVG of expression as XML Element Tree
- class ziamath.config.Config¶
Global configuration options for Ziamath
- minsizefraction¶
base size, for text such as subscripts and superscripts
- Type
Smallest allowed text size, as fraction of
- debug¶
- Type
Debug mode, draws bounding boxes around <mrows>
- svg2¶
at the expense of SVG size
- Type
Use SVG2.0. Disable for better browser compatibility,
- precision¶
- Type
SVG decimal precision for coordinates