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 Labels + Aria] Create math only parser to help parse TeX how we want #1890

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

nishasy
Copy link
Contributor

@nishasy nishasy commented Nov 20, 2024

Summary:

We want to be able to parse a string meant for TeX into its most basic
essential parts. To do this, we are creating a mathOnlyParser() parser.

Using the default parse() function from SimpleMarkdown breaks up
text into too many sections, and parsing from scratch can get very
complicated. The ideal way to do this is to use the existing parserFor()
function from SimpleMarkdown that lets us customize the parser.

This will be used in

  • Generating the TeX for Locked Labels and Locked Figure labels so that
    it shows up correctly on the graph. Non-TeX should show up with regular
    text styling and allow spaces.
  • Generating the aria label for locked figures with TeX labels. The speech
    rule engine will only be run on the math sections of the parsed output.

Issue: https://khanacademy.atlassian.net/browse/LEMS-2548
(and also https://khanacademy.atlassian.net/browse/LEMS-2591)

Test plan:

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

@nishasy nishasy self-assigned this Nov 20, 2024
@@ -81,7 +82,7 @@ export function isUnlimitedGraphState(
export function replaceOutsideTeX(mathString: string) {
// All the information we need is in the first section,
// whether it's typed as "blockmath" or "paragraph"
const firstSection = SimpleMarkdown.parse(mathString)[0];
const firstSection = parse(mathString)[0];
Copy link
Contributor Author

@nishasy nishasy Nov 20, 2024

Choose a reason for hiding this comment

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

Not making any changes here, just updating the import. This whole function will be updated in a different PR.

Copy link
Contributor

github-actions bot commented Nov 20, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR1890

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

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

Copy link
Contributor

github-actions bot commented Nov 20, 2024

Size Change: +251 B (+0.02%)

Total Size: 1.29 MB

Filename Size Change
packages/perseus/dist/es/index.js 423 kB +251 B (+0.06%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 38.9 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-editor/dist/es/index.js 697 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/strings.js 3.57 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 20, 2024 01:40
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/mighty-cobras-kick.md, packages/perseus/src/index.ts, packages/perseus/src/widgets/interactive-graphs/utils.test.ts, packages/perseus/src/widgets/interactive-graphs/utils.ts

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

Copy link
Contributor

@anakaren-rojas anakaren-rojas left a comment

Choose a reason for hiding this comment

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

Overall lgtm

@@ -148,3 +153,133 @@ describe("replaceOutsideTeX", () => {
expect(convertedString).toEqual("\\text{\\\\}");
});
});

describe("mathOnlyParser", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any edge cases we should consider adding?
A few that I'm wondering about are yippee $x^2, yippee x^2$ and yippee x^2.
I know you cover ^ and $ in the table tests, but I'm curious about capturing them in the context of a string with other text

@nishasy nishasy merged commit 0afb1a4 into main Nov 20, 2024
9 checks passed
@nishasy nishasy deleted the math-only-parser branch November 20, 2024 18:37
SonicScrewdriver added a commit that referenced this pull request Nov 22, 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]

### Major Changes

- [#1905](#1905)
[`9c225f936`](9c225f9)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - We're
reverting work done for the Server Side Scoring and Input Number
Conversion projects.

### Minor Changes

- [#1883](#1883)
[`adad642ab`](adad642)
Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Introduces a
validation function for the matrix widget (extracted from matrix scoring
function).


- [#1878](#1878)
[`a27f23bb4`](a27f23b)
Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Add expression
validator function

### Patch Changes

- [#1890](#1890)
[`0afb1a4f7`](0afb1a4)
Thanks [@nishasy](https://github.com/nishasy)! - [Locked Labels + Aria]
Create math only parser to help parse TeX how we want


- [#1889](#1889)
[`55a532175`](55a5321)
Thanks [@benchristel](https://github.com/benchristel)! - Internal:
enable strict typechecking of function parameters


- [#1852](#1852)
[`4b8836b84`](4b8836b)
Thanks [@catandthemachines](https://github.com/catandthemachines)! -
Adding open and closing behavior to unlimited polygon graph type.

- Updated dependencies
\[[`55a532175`](55a5321)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Major Changes

- [#1905](#1905)
[`9c225f936`](9c225f9)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - We're
reverting work done for the Server Side Scoring and Input Number
Conversion projects.

### Patch Changes

- [#1889](#1889)
[`55a532175`](55a5321)
Thanks [@benchristel](https://github.com/benchristel)! - Internal:
enable strict typechecking of function parameters

- Updated dependencies
\[[`adad642ab`](adad642),
[`0afb1a4f7`](0afb1a4),
[`55a532175`](55a5321),
[`9c225f936`](9c225f9),
[`4b8836b84`](4b8836b),
[`a27f23bb4`](a27f23b)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- [#1889](#1889)
[`55a532175`](55a5321)
Thanks [@benchristel](https://github.com/benchristel)! - Internal:
enable strict typechecking of function parameters

## @khanacademy/[email protected]

### Patch Changes

- [#1889](#1889)
[`55a532175`](55a5321)
Thanks [@benchristel](https://github.com/benchristel)! - Internal:
enable strict typechecking of function parameters

## @khanacademy/[email protected]

### Patch Changes

- Updated dependencies
\[[`55a532175`](55a5321)]:
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- [#1889](#1889)
[`55a532175`](55a5321)
Thanks [@benchristel](https://github.com/benchristel)! - Internal:
enable strict typechecking of function parameters

## @khanacademy/[email protected]

### Major Changes

- [#1905](#1905)
[`9c225f936`](9c225f9)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - We're
reverting work done for the Server Side Scoring and Input Number
Conversion projects.

### Patch Changes

- Updated dependencies
\[[`55a532175`](55a5321)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]
    -   @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