-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 for \' \` \^ \~ \= \u \. \" \r \H \v text-mode accents #802
Conversation
Does this work properly on Safari? Issue #735 is a combining character problem. |
@ronkok Probably not -- should have the same issue. Another reason to "wonder whether this is worthwhile, or we should correct the font somehow to make non-combining characters for these accents like we have for math mode. On the other hand, this support is better than nothing for now." |
We should look at porting this fix https://github.com/mathjax/MathJax/pull/1775/files. I feel like that's a separate issue/PR. |
Yesterday, I tried inserting a non-breaking space:
... and then adjusting the advance value in CSS class |
Cool, I hadn't seen that. Now that I understand the accent generation code, I pushed a fix which ought to work for Safari. Can someone test? In my experiments, |
I got the 0.25 from http://glyphrstudio.com/online/. I don't take it as conclusive. |
@edemaine Instead of combining characters, could you use modifier characters? |
Hmm, not sure why that's not working. Perhaps the combination of |
The Chrome changes look good for me. I started playing around with the styles on Safari and it looks like The width of the space character is 0.250em according to opentype.js (I uploaded KaTeX_Main-Regular.ttf). For each of the accents the average of Chrome however treats the accent as a character with a real width from Notice that this doesn't quite fix the single dot accent to the left of the umlaut. This is because its This means that the solution is different for Safari and Chrome. The MathJax hack special cases Safari as well. The unfortunate result of this is that server side rendering will only work if you return different markup based on the browser's user agent. For client side rendering special casing shouldn't pose a problem. One last note: fontMetricsData.js doesn't actually contain the values we need for the accent characters to fix Safari so we're going to need to extract those from the font. |
@edemaine let's not worry about fixing Safari accent positioning in this diff. |
static/katex.less
Outdated
|
||
.accent-body.accent-text > span { | ||
position: relative; | ||
left: 0.262em; // width of space, apparently |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The width, at least for KaTeX_Main-Regular, is 0.250em. Thankfully it appears that this value is the same, at least for the fonts I checked which were KaTeX_Main-Bold and KaTeX_SansSerif-Regular.
src/buildHTML.js
Outdated
// Some browsers (Safari in particular) don't like combining | ||
// characters without a preceding character. For each such accent, | ||
// we add an artificial nonbreaking space with a negative margin | ||
// to compensate for its width. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably worth leaving this code in here with a TODO describe what's necessary to get the accents lining up on Chrome that way other contributors can build on top of the foundation you started here.
@kevinbarabash I'm a little confused about whether I should include the space hack in this patch at all. My impression was that it wasn't necessary at all for Chrome, but perhaps your investigation has found that it makes it easier to get the horizontal offset more consistent? Still grokking. |
@edemaine I didn't try removing the hack. If all the new accents work on Chrome without the hack, let's take it and get this merged and we can deal with Safari separately. |
opentype.js was insightful! I realized that most of these accent characters have noncombining versions in the current font. I switched to those, so they should work in Safari. The only missing one is I found that the width of a space (0.250em) looked best for Other changes:
|
To fix |
} else if (this.mode === "math" && | ||
funcData.allowedInMath === false) { | ||
throw new ParseError( | ||
"Can't use function '" + func + "' in math mode", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future diffs, this could be written as:
`Can't use function '${func}' in math mode`,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. (And thanks for teaching me ES interpolation strings in the first place!) You can tell I was copy/pasting from above. 😄
expect("\\'echec").toFailWithParseError( | ||
"Can't use function '\\'' in math mode" + | ||
" at position 1: \\̲'̲echec"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for enforcing this and writing a test to verify enforcement.
@kevinbarabash Thanks for the review! I agree that we don't need combining characters in the font, and it'd be nice to add |
I took a stab at implementing the text-mode accents that were easy to implement using current fonts, as outlined by @gagern in #638. Here's a sample screenshot:
This seems to work, but feels a bit hacky because the accents are combining characters so don't behave well in isolation, so there's a magic number in a CSS style (similar but different to the
\vec
accent). It also misses key accents like\c
because they're not in the font. Makes me wonder whether this is worthwhile, or we should correct the font somehow to make non-combining characters for these accents like we have for math mode. On the other hand, this support is better than nothing for now.