-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove 'katex' from @khanacademy/perseus #1428
base: main
Are you sure you want to change the base?
Conversation
@@ -1,7 +1,6 @@ | |||
import * as React from "react"; | |||
|
|||
import Graph from "../graph"; | |||
// TODO(scottgrant): Katex is unavailable here. Fix! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't even make sense of what was to be done here so I'm deleting this comment.
// support (yet) with \begin{aligned}...\end{aligned} which renders | ||
// the same is supported by KaTeX. It does the same for align*. | ||
// TODO(kevinb) update content to use aligned instead of align. | ||
const tex = node.content.replace(/\{align[*]?\}/g, "{aligned}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MathJax supports the \begin{align}
macro just fine (tested in Storybook).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this code might break the exercise editor, which still uses KaTeX behind the scenes to validate that the input TeX can render with KaTeX. This gets complicated to reason about, because the reason the editor does that is to ensure that TeX written by content creators is compatible with old versions of the mobile app, which use KaTeX (and old versions of Perseus which have this replacement logic, so \begin{align}
will work fine there).
I think we could move this logic to the exercise editor and it would be fine. But I'd lean toward keeping this code the same until we can remove KaTeX everywhere. If you agree, can you restore this code and add a TODO comment here referencing LEMS-1608?
Size Change: -292 B (-0.03%) Total Size: 854 kB
ℹ️ View Unchanged
|
@@ -318,7 +318,6 @@ export type APIOptions = Readonly<{ | |||
|
|||
type TeXProps = { | |||
children: string; | |||
katexOptions?: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked and this prop/string is not used in webapp anywhere!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Git(hub) doesn't seem to recognize that this is a rename.
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing the \begin{align}
replacement will break the exercise editor. I left a note inline. So we either need to keep the replacement code, or move it to the exercise editor. Otherwise, this looks good!
* If the type of contents is string, the contents will be rendered with | ||
* KaTeX. Otherwise, the content will be assumed to be a DOM node and will | ||
* be appended inside the tooltip. | ||
* If the type of contents is string, the contents will be rendered as TeX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: TeX is the input language, so I think it would be more accurate to say that "the contents will be interpreted as TeX and rendered as DOM elements"
// support (yet) with \begin{aligned}...\end{aligned} which renders | ||
// the same is supported by KaTeX. It does the same for align*. | ||
// TODO(kevinb) update content to use aligned instead of align. | ||
const tex = node.content.replace(/\{align[*]?\}/g, "{aligned}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this code might break the exercise editor, which still uses KaTeX behind the scenes to validate that the input TeX can render with KaTeX. This gets complicated to reason about, because the reason the editor does that is to ensure that TeX written by content creators is compatible with old versions of the mobile app, which use KaTeX (and old versions of Perseus which have this replacement logic, so \begin{align}
will work fine there).
I think we could move this logic to the exercise editor and it would be fine. But I'd lean toward keeping this code the same until we can remove KaTeX everywhere. If you agree, can you restore this code and add a TODO comment here referencing LEMS-1608?
@@ -15,8 +15,8 @@ function findChildOrAdd(elem: any, className: string) { | |||
} | |||
|
|||
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. | |||
// Process a node and add math inside of it. This uses MathJax |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Process a node and add math inside of it. This uses MathJax | |
// Process a node and add math inside of it. This uses MathJax to |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1428 +/- ##
==========================================
+ Coverage 69.62% 71.30% +1.67%
==========================================
Files 504 508 +4
Lines 105597 105669 +72
Branches 7650 11489 +3839
==========================================
+ Hits 73521 75345 +1824
+ Misses 31960 30324 -1636
+ Partials 116 0 -116
... and 125 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Summary:
KaTeX was retired from use in Perseus in 2023. Today, I noticed that we still reference the
katex
package in the perseuspackage.json
, but we never import it anywhere in the code.So I'm removing that dependency. I've also updated some code comments and storybook references to not mention KaTeX anymore. I've left some references to CSS classes and the KaTeX_Main font ref. I'm unsure if they might be important somewhere (especially if host applications may still set it outside of Perseus).
So this doesn't fully remove all references to katex, but it moves us another step closer.
Issue: "none"
Test plan:
yarn tsc
yarn lint
I ran storybook and opened the
ZoomableTex
stories and played with them.I also went to the
EditorPage
story and pasted in the following Tex into the Question field (which uses the macro that we used to have to replace for KaTeX, but MathJax supports properly: switching\begin{align}
to\begin{aligned}
).