A Dash wrapper around React Latex
Project description
DashLatex: Typeset LaTeX in Dash apps
dash-latex is a Dash component library. Specifically, DashLatex
is a light Dash wrapper for ReactLatex which is itself a wrapper for Katex.
DashLatex
allows the LaTeX markup language to be used in Dash apps.
Get started with:
- Install Dash and its dependencies: https://dash.plotly.com/installation
- Run
python usage.py
- Visit http://localhost:8050 in your web browser
Getting started
DashLatex works like any other Dash component:
import dash_latex as dl
import dash
app = dash.Dash(__name__)
app.layout = dl.DashLatex(
r"""
When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
""",
)
if __name__ == "__main__":
app.run_server(debug=True)
Note that if using inline strings to write LaTeX, using raw strings is recommended, as LaTeX markup contains character sequences which Python will interpret as escape sequences.
DashLatex exposes all of the declarative options available from Katex, which are documented here. You can run help(dl.DashLatex)
to see a list of parameters exposed in the Python API.
Reference
| DashLatex is a Dash wrapper for ReactLatex (https://github.com/zzish/react-latex) which is itself a wrapper for Katex (https://katex.org/docs/options.html).
|
| Keyword arguments:
|
| - children (a list of or a singular dash component, string or number; optional):
| React element to be rendered inside the GSK Button component.
|
| - id (string; optional):
| The ID used to identify this component in Dash callbacks.
|
| - displayMode (boolean; optional):
| displayMode: boolean (default: False). If True the math will be
| rendered in display mode. If False the math will be rendered in
| inline mode. Differences between the two modes include: Display
| mode starts in \displaystyle, so \int and \sum are large, for
| example; while inline mode starts in \textstyle, where subscripts
| and superscripts usually don't stack on top of operators like
| \sum. You can always manually switch between \displaystyle and
| \textstyle using those commands. Display mode centers math on its
| on line and disables automatic line breaking (though you can
| customize this behavior with custom CSS). In inline mode, KaTeX
| allows line breaks after outermost relations (like = or <) or
| binary operators (like + or \times), the same as TeX.
|
| - errorColor (string; optional):
| errorColor: string. A color string given in the format "#XXX" or
| "#XXXXXX". This option determines the color that unsupported
| commands and invalid LaTeX are rendered in when throwOnError is
| set to False. (default: #cc0000).
|
| - fleqn (boolean; optional):
| fleqn: boolean. If True, display math renders flush left with a
| 2em left margin, like \documentclass[fleqn] in LaTeX with the
| amsmath package.
|
| - globalGroup (boolean; optional):
| globalGroup: boolean (default: False). Place KaTeX code in the
| global group. As a consequence, \def and \newcommand persist in
| macros across render calls. In LaTeX, constructs such as
| \begin{equation} and $$ create a local group and prevent
| definitions from becoming visible outside of those blocks.
|
| - leqno (boolean; optional):
| leqno: boolean. If True, display math has \tags rendered on the
| left instead of the right, like \usepackage[leqno]{amsmath} in
| LaTeX.
|
| - macros (dict; optional):
| macros: object. A collection of custom macros. Each macro is a
| property with a name like \name (written "\\name" in
| JavaScript) which maps to a string that describes the expansion of
| the macro, or a function that accepts an instance of MacroExpander
| as first argument and returns the expansion as a string.
| MacroExpander is an internal API and subject to non-backwards
| compatible changes. See src/macros.js for its usage.
| Single-character keys can also be included in which case the
| character will be redefined as the given macro (similar to TeX
| active characters). This object will be modified if the LaTeX code
| defines its own macros via \gdef, which enables consecutive calls
| to KaTeX to share state.
|
| - maxExpand (number; optional):
| maxExpand: number. Limit the number of macro expansions to the
| specified number, to prevent e.g. infinite macro loops. If set to
| Infinity, the macro expander will try to fully expand as in LaTeX.
| (default: 1000).
|
| - maxSize (number; optional):
| maxSize: number. All user-specified sizes, e.g. in
| \rule{500em}{500em}, will be capped to maxSize ems. If set to
| Infinity (the default), users can make elements and spaces
| arbitrarily large.
|
| - minRuleThickness (number; optional):
| minRuleThickness: number. Specifies a minimum thickness, in ems,
| for fraction lines, \sqrt top lines, {array} vertical lines,
| \hline, \hdashline, \underline, \overline, and the borders of
| \fbox, \boxed, and \fcolorbox. The usual value for these items
| is 0.04, so for minRuleThickness to be effective it should
| probably take a value slightly above 0.04, say 0.05 or 0.06.
| Negative values will be ignored.
|
| - strict (boolean | string; optional):
| strict: boolean or string or function (default: "warn"). If
| False or "ignore", allow features that make writing LaTeX
| convenient but are not actually supported by (Xe)LaTeX (similar to
| MathJax). If True or "error" (LaTeX faithfulness mode), throw an
| error for any such transgressions. If "warn" (the default), warn
| about such behavior via console.warn. Provide a custom function
| handler(errorCode, errorMsg, token) to customize behavior
| depending on the type of transgression (summarized by the string
| code errorCode and detailed in errorMsg); this function can also
| return "ignore", "error", or "warn" to use a built-in
| behavior. A list of such features and their errorCodes:.
|
| - throwOnError (boolean; optional):
| throwOnError: boolean. If True (the default), KaTeX will throw a
| ParseError when it encounters an unsupported command or invalid
| LaTeX. If False, KaTeX will render unsupported commands as text,
| and render invalid LaTeX as its source code with hover text giving
| the error, in the color given by errorColor.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dash_latex-0.1.1.tar.gz
.
File metadata
- Download URL: dash_latex-0.1.1.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 908c595cf474c7503b35aa1acb60780c9de65df282c3859f4b8111c50e75020b |
|
MD5 | 07bb51499a38419061bd009ea1bc0b1f |
|
BLAKE2b-256 | dfc8f73656cfd20c066dff29b92af28bacad7f1dfc82a9780f00270d10a4b9ba |
File details
Details for the file dash_latex-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: dash_latex-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c73c6fff87e445a0da3cdd3fd0de77e88bfd8e5d7dff609730955b6e7d37d8fb |
|
MD5 | a8558217b4ede3ed6300d3239813fbe1 |
|
BLAKE2b-256 | f026a4dc79abecfbbf42e719824eca672a31e27688b3b64c52d16037b8970e10 |