Katex: Nested Math with Non Default Text results in an Error

Created on 27 Dec 2017  路  8Comments  路  Source: KaTeX/KaTeX

Example: \textsf{Hello $a+b$} results in an error.

Expected result: \textsf{Hello $a+b$} should render the a+b with the default Math font.

bug

All 8 comments

@rrandallcainc it should use the default math style. pdflatex renders the following:
screen shot 2017-12-26 at 5 24 15 pm

The error shows up on master, but not on the demo page. The error is:

TypeError: undefined is not an object (evaluating 'fontMap[fontFamily].fontName')

I swapped out \textbf for \textsf in the screenshot above.

Okay. I see the issue. I can implement a fix, but I'd be curious if there's a better way. Ideally I'd like to reset all font options when entering math mode. Could you think of a place where that could be implemented?

@rrandallcainc you could probably add a withMathMode method to Options that resets everything.

Nice find. Be sure to add a test for this too!

Just got back from a trip. I'll take a look at this soon.

@kevinbarabash Starting to look @ this now. Agreed that withMathMode() is probably the most elegant way to go.

Trying to think...where's the best entry point for when we enter math mode?

My first thought is around: https://github.com/Khan/KaTeX/blob/master/src/Parser.js#L486. I'm guessing I could leverage this.settings.options.withMathMode(). But would that be considered hacky?

@rrandallcainc maybe we could set a prop on the styling node that's created which could indicate to the HTML and MathML builders to call reset the fonts using withMathMode().

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oddhack picture oddhack  路  3Comments

mpolyak picture mpolyak  路  3Comments

ylemkimon picture ylemkimon  路  3Comments

pyramation picture pyramation  路  4Comments

sophiebits picture sophiebits  路  3Comments