Skip to content

Commit dec6308

Browse files
committed
fix #5620 -- sometimes no math at all gets rendered if katex is disabled --> solution: get rid of the option to disable katex
- the disable katex option is now gone - however, if this causes an uprising, with a 1-line change we can re-enable the option
1 parent 65e24b6 commit dec6308

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

src/packages/frontend/account/account-preferences.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { Form, Switch, Tooltip } from "antd";
77
import { join } from "path";
8-
98
import { Col, Row } from "@cocalc/frontend/antd-bootstrap";
109
import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";
1110
import { A, Loading } from "@cocalc/frontend/components";
@@ -29,7 +28,7 @@ export const AccountPreferences: React.FC = () => {
2928
const email_address = useTypedRedux("account", "email_address");
3029
const email_address_verified = useTypedRedux(
3130
"account",
32-
"email_address_verified"
31+
"email_address_verified",
3332
);
3433
const passports = useTypedRedux("account", "passports");
3534
const sign_out_error = useTypedRedux("account", "sign_out_error");
@@ -95,7 +94,7 @@ export const AccountPreferences: React.FC = () => {
9594
.getActions("account")
9695
.set_other_settings(
9796
"dark_mode",
98-
!other_settings.get("dark_mode")
97+
!other_settings.get("dark_mode"),
9998
);
10099
}}
101100
style={{

src/packages/frontend/account/other-settings.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { Card, InputNumber } from "antd";
77
import { Map } from "immutable";
8-
98
import { Checkbox, Panel } from "@cocalc/frontend/antd-bootstrap";
109
import { Rendered, redux, useTypedRedux } from "@cocalc/frontend/app-framework";
1110
import {
@@ -35,6 +34,19 @@ import Tours from "./tours";
3534
import { useLanguageModelSetting } from "./useLanguageModelSetting";
3635
import { UserDefinedLLMComponent } from "./user-defined-llm";
3736

37+
// See https://github.com/sagemathinc/cocalc/issues/5620
38+
// There are weird bugs with relying only on mathjax, whereas our
39+
// implementation of katex with a fallback to mathjax works very well.
40+
// This makes it so katex can't be disabled.
41+
const ALLOW_DISABLE_KATEX = false;
42+
43+
export function katexIsEnabled() {
44+
if (!ALLOW_DISABLE_KATEX) {
45+
return true;
46+
}
47+
return redux.getStore("account")?.getIn(["other_settings", "katex"]) ?? true;
48+
}
49+
3850
interface Props {
3951
other_settings: Map<string, any>;
4052
is_stripe_customer: boolean;
@@ -110,7 +122,10 @@ export function OtherSettings(props: Readonly<Props>): JSX.Element {
110122
}
111123
}
112124

113-
function render_katex(): Rendered {
125+
function render_katex() {
126+
if (!ALLOW_DISABLE_KATEX) {
127+
return null;
128+
}
114129
return (
115130
<Checkbox
116131
checked={!!props.other_settings.get("katex")}

src/packages/frontend/components/math/katex-and-mathjax2.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { math_escape, math_unescape } from "@cocalc/util/markdown-utils";
1515
import { remove_math, replace_math } from "@cocalc/util/mathjax-utils";
1616
import { latexMathToHtmlOrError } from "@cocalc/frontend/misc/math-to-html";
1717
import { replace_all } from "@cocalc/util/misc";
18-
import { redux } from "@cocalc/frontend/app-framework";
1918
import { replaceMathBracketDelims } from "./util";
19+
import { katexIsEnabled } from "@cocalc/frontend/account/other-settings";
2020

2121
interface Props {
2222
data: string;
@@ -44,10 +44,7 @@ export default function KaTeXAndMathJaxV2({ data, inMarkdown }: Props) {
4444
return <>{data}</>;
4545
}
4646

47-
if (
48-
inMarkdown &&
49-
redux.getStore("account")?.getIn(["other_settings", "katex"])
50-
) {
47+
if (inMarkdown && katexIsEnabled()) {
5148
const __html = attemptKatex(text, math);
5249
if (__html != null) {
5350
// no error -- using katex is allowed and fully worked.

src/packages/frontend/jquery-plugins/katex-plugin.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ is explicitly known and set to false.
1313
*/
1414

1515
import { stripMathEnvironment } from "@cocalc/frontend/editors/slate/elements/math/index";
16-
16+
import { katexIsEnabled } from "@cocalc/frontend/account/other-settings";
1717
export const jQuery = $;
1818
declare var $: any;
1919
import { tex2jax } from "./tex2jax";
20-
2120
import { macros } from "./math-katex";
22-
import { redux } from "../app-framework";
2321

2422
// gets defined below.
2523
let renderToString: any = undefined;
@@ -54,8 +52,7 @@ function katex_plugin(elt, preProcess): void {
5452
}
5553
// console.log("katex_plugin", elt.html());
5654

57-
const always_use_mathjax: boolean =
58-
redux.getStore("account")?.getIn(["other_settings", "katex"]) === false;
55+
const always_use_mathjax: boolean = !katexIsEnabled();
5956

6057
// Select all the math and try to use katex on each part.
6158
elt.find("script").each(async function () {
@@ -96,7 +93,7 @@ function katex_plugin(elt, preProcess): void {
9693
console.log(
9794
"WARNING -- ",
9895
err.toString(),
99-
" (will fall back to mathjax)"
96+
" (will fall back to mathjax)",
10097
); // toString since the traceback has no real value.
10198
// fallback to using mathjax on this -- should be rare; not horrible if this happens...
10299
// Except for this, this katex pluging is synchronous and does not depend on MathJax at all.

0 commit comments

Comments
 (0)