diff --git a/.changeset/proud-donkeys-sip.md b/.changeset/proud-donkeys-sip.md new file mode 100644 index 0000000000..2dd6eac5ec --- /dev/null +++ b/.changeset/proud-donkeys-sip.md @@ -0,0 +1,6 @@ +--- +"@khanacademy/perseus": patch +--- + +Remove unused code related to KaTeX and MathJax 2. It's no longer needed +because all callers have upgraded to MathJax 3. diff --git a/packages/perseus/src/util/tex.ts b/packages/perseus/src/util/tex.ts index 77aca6e094..cb46519141 100644 --- a/packages/perseus/src/util/tex.ts +++ b/packages/perseus/src/util/tex.ts @@ -6,8 +6,6 @@ import {getDependencies} from "../dependencies"; import KhanMath from "./math"; import reactRender from "./react-render"; -declare const MathJax: any; - function findChildOrAdd(elem: any, className: string) { const $child = $(elem).find("." + className); if ($child.length === 0) { @@ -16,27 +14,6 @@ function findChildOrAdd(elem: any, className: string) { return $child; } -function doCallback( - elem: HTMLElement, - callback: (() => unknown) | (() => void), -) { - let tries = 0; - (function check() { - const height = elem.scrollHeight; - // Heuristic to guess if the font has kicked in - // so we have box metrics (magic number ick, - // but this seems to work mostly-consistently) - if (height > 18 || tries >= 10) { - callback(); - } else { - tries++; - // TODO(jeff, CP-3128): Use Wonder Blocks Timing API - // eslint-disable-next-line no-restricted-syntax - setTimeout(check, 100); - } - })(); -} - export default { // Process a node and add math inside of it. This attempts to use KaTeX to // format the math, and if that fails it falls back to MathJax. @@ -55,7 +32,7 @@ export default { // processed processMath: async function ( elem: HTMLElement, - text: string, + text: string | number, force?: boolean, callback?: () => unknown, ) { @@ -63,29 +40,14 @@ export default { // Only process if it hasn't been done before, or it is forced if ($elem.attr("data-math-formula") == null || force) { - const $katexHolder = findChildOrAdd($elem, "katex-holder"); - const $mathjaxHolder = findChildOrAdd($elem, "mathjax-holder"); - - // Search for MathJax-y script tags inside of the node. These are - // used by MathJax to denote the formula to be typeset. Before, we - // would update the formula by updating the contents of the script - // tag, which shouldn't happen any more, but we manage them just in - // case. - const script: HTMLElement | undefined = $mathjaxHolder.find( - "script[type='math/tex']", - )[0]; - - // If text wasn't provided, we look in two places - if (text == null) { - if ($elem.attr("data-math-formula")) { - // The old typeset formula - // @ts-expect-error - TS2322 - Type 'string | undefined' is not assignable to type 'string'. - text = $elem.attr("data-math-formula"); - } else if (script) { - // The contents of the