Support \gdef in multiple equations in auto-render (#1425)

Within a single call to `renderMathInElement`, default `macros` to a shared
empty object (same as if you specified an object) so that global macros
defined via `\gdef` can be defined and shared.
This commit is contained in:
Erik Demaine
2018-06-14 06:44:43 -04:00
committed by GitHub
parent 4a2903148e
commit ffe90a3ca1
2 changed files with 12 additions and 1 deletions

View File

@@ -91,6 +91,10 @@ in addition to two auto-render-specific keys:
- `errorCallback`: A callback method returning a message and an error stack
in case of an critical error during rendering. The default uses `console.error`.
Note that the `displayMode` property of the options object is ignored, and is
The `displayMode` property of the options object is ignored, and is
instead taken from the `display` key of the corresponding entry in the
`delimiters` key.
The same `options.macros` object (which defaults to an empty object `{}`)
is passed into several calls to `katex.render`, so that consecutive equations
can build up shared macros by `\gdef`.

View File

@@ -101,6 +101,13 @@ const renderMathInElement = function(elem, options) {
}
const optionsCopy = Object.assign({}, defaultAutoRenderOptions, options);
// Enable sharing of global macros defined via `\gdef` between different
// math elements within a single call to `renderMathInElement`.
if (!optionsCopy.macros) {
optionsCopy.macros = {};
}
renderElem(elem, optionsCopy);
};