How to use the katex.ParseError function in katex

To help you get started, we’ve selected a few katex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MatejBransky / react-katex / index.js View on Github external
{},
        {
          displayMode: !!props.block,
          errorColor: props.errorColor,
          throwOnError: !!props.renderError
        },
        // you can rewrite all KaTeX options directly
        props.settings
      )
    );

    return (
      
    );
  } catch (error) {
    if (error instanceof KaTeX.ParseError || error instanceof TypeError) {
      return props.renderError ? (
        props.renderError(error)
      ) : (
        
      );
    }

    throw error;
  }
}
github KaTeX / KaTeX / contrib / auto-render / auto-render.js View on Github external
for (let i = 0; i < data.length; i++) {
        if (data[i].type === "text") {
            fragment.appendChild(document.createTextNode(data[i].data));
        } else {
            const span = document.createElement("span");
            let math = data[i].data;
            // Override any display mode defined in the settings with that
            // defined by the text itself
            optionsCopy.displayMode = data[i].display;
            try {
                if (optionsCopy.preProcess) {
                    math = optionsCopy.preProcess(math);
                }
                katex.render(math, span, optionsCopy);
            } catch (e) {
                if (!(e instanceof katex.ParseError)) {
                    throw e;
                }
                optionsCopy.errorCallback(
                    "KaTeX auto-render: Failed to parse `" + data[i].data +
                    "` with ",
                    e
                );
                fragment.appendChild(document.createTextNode(data[i].rawData));
                continue;
            }
            fragment.appendChild(span);
        }
    }

    return fragment;
};
github serlo / editor-plugins / plugins / text-renderer / src / katex / math.component.tsx View on Github external
static getDerivedStateFromProps(
      props: MathComponentProps
    ): Partial {
      try {
        const { errorColor, renderError } = props

        const html = KaTeX.renderToString(props.math, {
          displayMode,
          errorColor,
          throwOnError: !!renderError
        })

        return { html, error: undefined }
      } catch (error) {
        if (error instanceof KaTeX.ParseError || error instanceof TypeError) {
          return { error }
        }

        throw error
      }
    }
  }