Skip to content
Snippets Groups Projects

D-SI Parser

This library converts D-SI unit strings to Latex.

Usage

Set up a parser (with optional arguments for default latex values): parser = dsiParser(latexDefaultWrapper='$', latexDefaultPrefix=r'\mathrm{Prefix}', latexDefaultSuffix=r'\mathrm{Suffix}'). Create a D-SI tree with the D-SI unit string as an argument: tree = parser.parse("\mega\hertz").

  • To validate the D-SI unit string, inspect the valid property: print(tree.valid)
    • To see any warning messages generated while parsing the string, inspect the warnings property: print(tree.warnings)
  • To generate the corresponding LaTeX code, call the toLatex function: latexString = tree.toLatex()
    • Optional arguments for the toLatex function:
      • wrapper: appears at the beginning and end of the string. Defaults to "$$".
      • prefix: appears et the beginning of the string, after the wrapper. Defaults to "".
      • suffix: appears at the end of the string, before the wrapper. Defaults to "".
    • If the string would only consist of the wrappers, an empty string is returned instead.