Skip to content
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

[Locked Figures] Use $ symbols to denote TeX within locked labels and locked figure labels #1834

Merged
merged 4 commits into from
Nov 7, 2024

Conversation

nishasy
Copy link
Contributor

@nishasy nishasy commented Nov 7, 2024

Summary:

In the rest of the exercise editor, content authors need to surround text in $ for it to be denoted as TeX.

For consistency, we want to add that functionality to the interactive graph editor as well.

  • Update LockedLabelSettings to say "text" instead of "TeX" and have an infotip to explain it.
  • Update LockedLabel so that it surrounds the non-$ part of the string with \text{} before
    wrapping the whole thing in

Note: This is a prerequisite for auto-generating spoken math details with the MathJax speech engine
for the aria labels, because the non-TeX text needs to be differentiated in the label for the label
to be generated correctly for non-TeX text. If it's all TeX, the speech engine reads every letter
separately (example: "square A" ==> "s q u a r e upper A")

Issue: https://khanacademy.atlassian.net/browse/LEMS-2548

Test plan:

yarn jest packages/perseus/src/widgets/interactive-graphs/utils.test.ts

Storybook

@nishasy nishasy self-assigned this Nov 7, 2024
}

return result;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing some regex stuff along with mathString.replace() but it got convoluted and kept letting edge cases slip through the cracks. I decided to go back to basics and stick to what works, and this was the resulting code.

Copy link
Contributor

github-actions bot commented Nov 7, 2024

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (6bd18fb) and published it to npm. You
can install it using the tag PR1834.

Example:

yarn add @khanacademy/perseus@PR1834

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1834

Copy link
Contributor

github-actions bot commented Nov 7, 2024

Size Change: +393 B (+0.05%)

Total Size: 859 kB

Filename Size Change
packages/perseus-editor/dist/es/index.js 283 kB +148 B (+0.05%)
packages/perseus/dist/es/index.js 409 kB +245 B (+0.06%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 38.8 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.8 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/strings.js 3.54 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.4 kB

compressed-size-action

@nishasy nishasy marked this pull request as ready for review November 7, 2024 22:03
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/good-ghosts-invite.md, packages/perseus/src/widgets/interactive-graphs/interactive-graph.testdata.ts, packages/perseus/src/widgets/interactive-graphs/utils.test.ts, packages/perseus/src/widgets/interactive-graphs/utils.ts, packages/perseus/src/widgets/interactive-graphs/locked-figures/locked-label.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-ellipse-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-function-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-label-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-label-settings.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-line-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-point-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-polygon-settings.test.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-vector-settings.test.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

@@ -65,3 +65,58 @@ describe("normalizeCoords", () => {
expect(result).toEqual(expected);
});
});

describe("replaceOutsideTeX", () => {
test("no $s", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these tests do the same thing, using a table might make things easier since you won't need to redo the code for each test, just have a table of inputs
https://jestjs.io/docs/api#2-testeachtablename-fn-timeout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but I wanted the description of each test to be explicit!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think the table would get really long with some of the descriptions + math strings. It would definitely be fewer lines, but I think I prefer the deliberateness of having them be separate tests in this particular case.

packages/perseus/src/widgets/interactive-graphs/utils.ts Outdated Show resolved Hide resolved
packages/perseus/src/widgets/interactive-graphs/utils.ts Outdated Show resolved Hide resolved
@nishasy nishasy merged commit 429b9cc into main Nov 7, 2024
8 of 9 checks passed
@nishasy nishasy deleted the use-math-labels branch November 7, 2024 23:20
SonicScrewdriver added a commit that referenced this pull request Nov 7, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @khanacademy/[email protected]

### Minor Changes

- [#1834](#1834)
[`429b9cc15`](429b9cc)
Thanks [@nishasy](https://github.com/nishasy)! - [Locked Figures] Use
\\$ symbols to denote TeX within locked labels and locked figure labels

### Patch Changes

- [#1833](#1833)
[`122b3cc1b`](122b3cc)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! -
Removal of unused MathJax2 initialization

## @khanacademy/[email protected]

### Minor Changes

- [#1834](#1834)
[`429b9cc15`](429b9cc)
Thanks [@nishasy](https://github.com/nishasy)! - [Locked Figures] Use
\\$ symbols to denote TeX within locked labels and locked figure labels

### Patch Changes

- Updated dependencies
\[[`429b9cc15`](429b9cc),
[`122b3cc1b`](122b3cc)]:
    -   @khanacademy/[email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants