4.7 KiB
id, title, original_id
| id | title | original_id |
|---|---|---|
| version-0.10.1-options | Options | options |
You can provide an object of options as the last argument to katex.render and katex.renderToString. Available options are:
-
displayMode:boolean. Iftruethe math will be rendered in display mode, which will put the math in display style (so\intand\sumare large, for example), and will center the math on the page on its own line. Iffalsethe math will be rendered in inline mode. (default:false) -
leqno:boolean. Iftrue, display math has\tags rendered on the left instead of the right, like\usepackage[leqno]{amsmath}in LaTeX. -
fleqn:boolean. Iftrue, display math renders flush left, like\documentclass[fleqn]in LaTeX. -
throwOnError:boolean. Iftrue(the default), KaTeX will throw aParseErrorwhen it encounters an unsupported command or invalid LaTeX. Iffalse, 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 byerrorColor. -
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 whenthrowOnErroris set tofalse. (default:#cc0000) -
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 ofMacroExpanderas first argument and returns the expansion as a string.MacroExpanderis an internal API and subject to non-backwards compatible changes. Seesrc/macros.jsfor 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. -
colorIsTextColor:boolean. Iftrue,\colorwill work like LaTeX's\textcolor, and take two arguments (e.g.,\color{blue}{hello}), which restores the old behavior of KaTeX (pre-0.8.0). Iffalse(the default),\colorwill work like LaTeX's\color, and take one argument (e.g.,\color{blue}hello). In both cases,\textcolorworks as in LaTeX (e.g.,\textcolor{blue}{hello}). -
maxSize:number. All user-specified sizes, e.g. in\rule{500em}{500em}, will be capped tomaxSizeems. If set toInfinity(the default), users can make elements and spaces arbitrarily large. -
maxExpand:number. Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set toInfinity, the macro expander will try to fully expand as in LaTeX. (default: 1000) -
allowedProtocols:string[]. Allowed protocols in\href. Use_relativeto allow relative urls, and*to allow all protocols. (default:["http", "https", "mailto", "_relative"]) -
strict:booleanorstringorfunction(default:"warn"). Iffalseor"ignore", allow features that make writing LaTeX convenient but are not actually supported by (Xe)LaTeX (similar to MathJax). Iftrueor"error"(LaTeX faithfulness mode), throw an error for any such transgressions. If"warn"(the default), warn about such behavior viaconsole.warn. Provide a custom functionhandler(errorCode, errorMsg, token)to customize behavior depending on the type of transgression (summarized by the string codeerrorCodeand detailed inerrorMsg); this function can also return"ignore","error", or"warn"to use a built-in behavior. A list of such features and theirerrorCodes:"unknownSymbol": Use of unknown Unicode symbol, which will likely also lead to warnings about missing character metrics, and layouts may be incorrect (especially in terms of vertical heights)."unicodeTextInMathMode": Use of Unicode text characters in math mode."mathVsTextUnits": Mismatch of math vs. text commands and units/mode."commentAtEnd": Use of%comment without a terminating newline. LaTeX would thereby comment out the end of math mode (e.g.$), causing an error.
A second category of
errorCodes never throw errors, but their strictness affects the behavior of KaTeX:"newLineInDisplayMode": Use of\\or\newlinein display mode (outside an array/tabular environment). In strict mode, no line break results, as in LaTeX.
For example:
katex.render("c = \\pm\\sqrt{a^2 + b^2}\\in\\RR", element, {
displayMode: true,
macros: {
"\\RR": "\\mathbb{R}"
}
});