-
Notifications
You must be signed in to change notification settings - Fork 38
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
Support to parsing incomplete Latex expressions #5
Comments
test case: import { expect } from "@jest/globals";
import { parse, serialize } from "@cortex-js/math-json";
function roundtrip(input: string) {
return serialize(parse(input));
}
describe("parse", () => {
it("changes input on roundtrip", () => {
expect(roundtrip("2\\times2=4")).toBe("2\\times2=4");
expect(roundtrip("2\\times2=")).toBe("2\\times2"); // misses trailing `=` sign
});
}); |
In general, there is no round-tripping guarantee. The Latex expression could include extra whitespace, comments or other syntactic idioms that are not preserved in the MathJSON expression. For example, both That said, in this particular example, I can see a case for attempting to preserve the "partial" expression. FYI, it currently returns a |
I see. Maybe this could be a configurable element. A placeholder has already different meaning and might be used for other purposes. Or - the missing operand could serialize to an space char. That would retain the input expression semantically. I think this would work out for my situation and would provide sound behavior. Wdyt? |
You can configure how the const customLatex = new LatexSyntax( { dictionary: [
...LatexSyntax.getDictionary(),
{ name: 'Missing', serialize: '\\placeholder'}
] } );
customLatex.serialize(['Equal', 'x', 'Missing']); Replace Does that work for you? |
Hey @arnog , it surely would! Only I'm not getting the "Missing" symbol, when I parse the expression let res = parse("2\\times2=")
// ["Multiply",{"num":"2"},{"num":"2"}] Do I have to configure something for this? |
No, that's the current behavior, but I'm going to change it to use the |
Parsing incomplete (mathematically) expressions seems to leave some parts outs, eg:
This has the implication that chained parse / serialize calls would alter the initial input...
Will this ever work with in-complete expressions?
The text was updated successfully, but these errors were encountered: