-
-
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
Fix \mathit
font and italic correction and add \mathnormal
#1700
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1700 +/- ##
==========================================
+ Coverage 93.88% 93.89% +<.01%
==========================================
Files 78 78
Lines 4564 4569 +5
Branches 802 805 +3
==========================================
+ Hits 4285 4290 +5
Misses 246 246
Partials 33 33
Continue to review full report at Codecov.
|
\mathit
font and italic correction and add \mathnormal
@@ -85,7 +85,7 @@ export const getVariant = function( | |||
} | |||
|
|||
const font = options.font; | |||
if (!font) { | |||
if (!font || font === "mathnormal") { |
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.
I'm not sure what variant \mathnormal
should use, but as it acts similar to the default math font, I used null
(none).
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.
That should be fine.
fontName = fontData.fontName; | ||
fontClasses = [fontData.fontClass]; | ||
} else if (utils.contains(mathitLetters, text)) { | ||
fontName = "Main-Italic"; | ||
fontClasses = ["mathit"]; |
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.
This feels redundant. Shouldn't the mathdefault
call below take care of this case?
@@ -72,7 +72,7 @@ const makeSymbol = function( | |||
let symbolNode; | |||
if (metrics) { | |||
let italic = metrics.italic; | |||
if (mode === "text") { | |||
if (mode === "text" || (options && options.font === "mathit")) { | |||
italic = 0; |
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.
Interesting. The combining of text glyphs we do should have a similar affect, shouldn't it. I guess it still keeps the italic value from the last glyph so it still changing the spacing at the boundaries between font types whereas this won't.
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.
@kevinbarabash Should we remove mode === "text"
?
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.
Would this change affect the screenshots? I'm not exactly sure where we use .italic
, as we don't support \/
(but maybe we should). We probably use it in accent placement, so removing mode === "text"
might improve (or worsen) accents.
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.
Not sure, but it's something we could investigate.
fontClass: "mathit", | ||
}; | ||
} else if (/[0-9]/.test(value.charAt(0))) { |
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'd be nice to have some helper functions for some of these tests, maybe isLatinLetter
, isNumber
, etc.
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.
Even better (faster) would be to use hasOwnProperty
on an object with the appropriate keys. We should replace all/most uses of utils.contains
with this. But not necessarily for this PR.
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.
That's clever. We'd want to construct the object programmatically at load time though.
@@ -705,11 +734,17 @@ const fontMap: {[string]: {| variant: FontVariant, fontName: string |}} = { | |||
variant: "italic", | |||
fontName: "Main-Italic", | |||
}, | |||
"mathit": { | |||
variant: "italic", | |||
fontName: "Main-Italic", |
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.
What were you thinking in terms of renaming fonts?
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.
LGTM. Thanks for the PR.
|$\text{Ab0}$ `\text{Ab0}` |$\bm{Ab}$ `\bm{Ab}` |$\frak{Ab0}$ `\frak{Ab0}` | ||
|$\mathsf{Ab0}$ `\mathsf{Ab0}` |$\mathtt{Ab0}$ `\mathtt{Ab0}` |$\mathfrak{Ab0}$ `\mathfrak{Ab0}` | ||
|$\textsf{Ab0}$ `\textsf{Ab0}` |$\texttt{Ab0}$ `\texttt{Ab0}` |$\mathcal{AB0}$ `\mathcal{AB0}` | ||
|$\sf Ab0$ `\sf Ab0` |$\tt Ab0$ `\tt Ab0` |$\mathscr{AB}$ `\mathscr{AB}` |
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.
Any guesses why I'm not seeing these changes on https://deploy-preview-1700--katex.netlify.com/docs/supported.html ? Is there something wrong with our Netlify builds?
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.
@edemaine It's because versioned docs are not updated. You can check them in https://deploy-preview-1700--katex.netlify.com/docs/next/supported.html.
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.
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.
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.
Comparing more with LaTeX, everything seems like a good match. Which your texcmp outputs confirm. 😄
I do remain confused about what the initial/default mode of LaTeX is. I thought it was \mathnormal
, but that differs on numerals. Is there a name for it?
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.
\mathdefault
? I don't even though if that's a thing or not, but there must be some way of getting back to that mode from inside of \mathnormal
.
I'll merge this PR, as I'm planning to completely refactor font generation and selection. |
@ylemkimon what kinds of changes are you planning? |
Refer to KaTeX/KaTeX#1700 for additional details.
Refer to KaTeX/KaTeX#1700 for additional details.
Refer to KaTeX/KaTeX#1700 for additional details.
Fixes #584 and fixes #1250.
KaTeX uses the same font (
Math-Italic
, Computer Modern Math Italic[cmmi
], classmathit
for alphabets andMain-Regular
, Computer Modern Roman[cmr
] for digits) for math atoms outside font commands (default) and in\mathit
.However,
\mathit
in LaTeX uses text italic font (Main-Italic
, Computer Modern Text Italic[cmti
], classmainit
) for both alphabets and digits, which has narrow widths (spacing) and no italic correction, same as\textit
. This PR changes\mathit
font toMain-Italic
and remove its italic correction. (0d52009) This also fixes old font command\it
, as it usesmathit
class.(Green is LaTeX, red is KaTeX, aligned manually. The spacing around accent character seems to be still wrong but is in the right direction, I'll open an issue after this is merged. Wrong accent position is tracked by #1099, incorrect spacing around dotless i by #354, and \KaTeX mismatch by #1703)
Also, I've renamed the name
mathit
tomathdefault
andmainit
tomathit
to avoid confusion. (f354da8) We should consider changing the font name.Furthermore, I've added
\mathnormal
, which is similar to default math font but uses old style (Caligraphic
) font for digits and math italic (Math-Italic
) font for uppercase Greek alphabets as well as other letters that is in math italic font. (702c454)(Green is LaTeX, red is KaTeX, incorrect spacing around dotless i is tracked by #354 and \KaTeX mismatch by #1703)