跳转到主要内容

A Dash包装器,用于React Latex

项目描述

DashLatex:在Dash应用程序中排版LaTeX

dash-latex是一个Dash组件库。具体来说,DashLatexReactLatex的一个轻量级Dash包装器,而Katex则是ReactLatex的包装器。

demo-video

DashLatex允许在Dash应用程序中使用LaTeX标记语言。

入门

  1. 安装Dash及其依赖项: https://dash.plotly.com/installation
  2. 运行python usage.py
  3. 在您的网络浏览器中访问http://localhost:8050

入门

DashLatex就像其他任何Dash组件一样工作

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)

注意:如果使用内联字符串来编写LaTeX,建议使用原始字符串,因为LaTeX标记语言包含Python会解释为转义序列的字符序列。

DashLatex公开了Katex的所有声明性选项,这些选项在此处有文档说明。您可以通过运行help(dl.DashLatex)来查看Python API公开的参数列表。

参考

|  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.

项目细节


下载文件

为您的平台下载文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源分发

dash_latex-0.1.1.tar.gz (2.8 MB 查看哈希值)

构建分发

dash_latex-0.1.1-py3-none-any.whl (2.8 MB 查看哈希值)

上传于 Python 3

由以下组织支持