\kern fixes, \hskip support, \TeX, \LaTeX, \KaTeX#974
Conversation
|
Cool!
I think we'll need to bump the version again as this may break some math that was working for people.
Thanks for figuring this out.
Cool. I think some people will be pretty stoked about this.
I think the new \katex implementation is closer to the \LaTeX rendering, especially the kerning between the |
k4b7
left a comment
There was a problem hiding this comment.
The kern and skip changes look good. I think the \KaTeX macro needs a little tweaking, but not much.
| @@ -0,0 +1,65 @@ | |||
| //@flow | |||
| // Horizontal spacing commands | |||
There was a problem hiding this comment.
Maybe call this file kern.js b/c type: "kern" below... or maybe horizontal-spacing.js.
There was a problem hiding this comment.
Good point -- switched to kern.js.
| import { calculateSize } from "../units"; | ||
| import ParseError from "../ParseError"; | ||
|
|
||
| // TODO: \hskip and \mskip should support plus and minus in lengths |
There was a problem hiding this comment.
Good call splitting this out, tbh I'm not sure how to do this, at least for our current HTML layout strategy.
There was a problem hiding this comment.
Yeah, definitely for another time. Supporting fil/fill/filll units in plus at least should be possible using Flexbox. That'd be pretty useful -- but for another issue. I've opened #990 to track.
src/macros.js
Outdated
| // \kern-.15em% | ||
| // \TeX} | ||
| // This code roughly aligns the top of the A with the T. Here we approximate | ||
| // this vertical alignment with a \raisebox{.45ex}, which seems close. |
There was a problem hiding this comment.
What font size is being selected for the A? Perhaps we could compute the raisebox amount based on the difference in size between the A and the T.
There was a problem hiding this comment.
The A should be in the equivalent of \scriptsize, which has a scale of 70%. The height of a T is 0.68333em (according to fontMetricsData.js), so the raisebox should be 0.3 * 0.68333 = 0.204999em. I tried this, and it puts the A slightly higher than what I did, but it matches the LaTeX rendering better! Good thinking. I've pushed code that computes this automatically from the font data instead of hard-coding constants (other than 0.3 which seems safe enough).
src/macros.js
Outdated
|
|
||
| // New KaTeX logo based on tweaking LaTeX logo | ||
| defineMacro("\\katex", "\\text{K\\kern-.25em\\raisebox{.45ex}{\\scriptsize A}" + | ||
| "\\kern-.15em\\TeX}"); |
There was a problem hiding this comment.
Does K\\kern-.36em even out the spaces around the A?
There was a problem hiding this comment.
Nice objective to even out those top spaces. By manual search, I found K\\kern-.16em to balance it out pretty evenly:

http://localhost:7936/?text=%5Cbegin%7Barray%7D%7Br%7D%5Ckatex%5C%5C%5CLaTeX%5C%5C%5CKaTeX%5Cend%7Barray%7D
I feel like the this puts the bottom of the A a little far from the K, though. I tried tweaking the A slightly more to the left, with K\\kern-1.17em:
Preference? This may be nit-picky, but if we're redesigning the logo, we might as well try to get it right. I do find these far more readable than the old logo, which is nice (but also more readable than the LaTeX logo).
There was a problem hiding this comment.
I think the top one looks the best. In the bottom one the A is too cramped.
There was a problem hiding this comment.
Just to be clear, we're talking about the top logo in the top image vs. the top logo in the bottom image, right? (Bottom logo is the same in both images, the old KaTeX logo.)
There was a problem hiding this comment.
I can't tell the difference between the top logos in the two images... whichever you think is better.
I have, so far, purposely omitted |
|
I need to respond about the other issues (thanks for the review, @kevinbarabash!), but one question I have is whether the errors on misuse of |
* Move \kern, \mkern into functions directory * Add \hskip, \mskip support (but without supporting plus/minus) * Properly separate \kern, \hskip from \mkern, \mskip. (The former work in both modes, and don't support mu units. The latter work only in math mode and only support mu units.)
|
I addressed @kevinbarabash comments (thanks!) and switched from errors to warning when misusing This should be ready for review again, and maybe one more iteration on exact spacing of the logos. Then I'd suggest that I delete the old |
|
Here's a texdiff for It appears to me that the A is slightly smaller in KaTeX, which causes the horizontal shift of the L. I don't understand why; I confirmed that the A is in a font size exactly 70% of the T, and LaTeX says the same in its rendering: I also notice that there's some difference between Chrome vs. Firefox rendering (notice height of A): Personally I'd be OK with leaving it as is, as I'm running out of ideas (and time) for how to improve it, it matches the definition, and the rendering is reasonably close now. I've committed this as a new screenshot test so that it can be explored later. I also switched over |
k4b7
left a comment
There was a problem hiding this comment.
LGTM. I love how macros help reduce the amount of the code we have to ship!
|
@edemaine I'm not sure why all of the fonts screenshot tests are failing. 😕 |
|
@kevinbarabash Turns out those screenshots all have |
|
OK, should be all fixed now. |
|
@edemaine thanks for investing and fixing the issue. |
Update `test/screenshotter/test.tex`'s definition of `\KaTeX` macro to match the metrics of `src/macros.js`'s definition of `\KaTeX`, and thereby fix KaTeX#1703. I just changed the `\kern` metrics to match the update from KaTeX#974, and left the font selection code to match LaTeX's definition of `\LaTeX`.






This PR does a lot of cleanup on
\kern-related functions, and defines\TeXand\LaTeXmacros (fixing #224). It also proposes a possible replacement to\KaTeX(needs discussion).In more detail:
Move
\kern,\mkernintofunctionsdirectory (and use newdefineFuctioninterface)Add
\hskip,\mskipsupport (but without supporting plus/minus -- this should be a future issue)Properly separate
\kern,\hskipfrom\mkern,\mskip.(The former work in both modes, and don't support mu units.
The latter work only in math mode and only support mu units.)
Render horizontal spacing commands (such as
\kern) using MathML<mspace>.Previously this was rendered as an empty
<mrow>with a TODO by @kevinbarabash to figure it out.Implement
\TeXmacro identical to LaTeX's definition using\raiseboxand\kern.Implement
\LaTeXmacro roughly identical to LaTeX's definition (using\raiseboxinstead of a vertical box with a fill to get top alignment). Comments welcome, but I think this is a pretty good solution for now.I tried implementing a new
\KaTeXlogo using a similar macro (now that we have all these features), instead of the large body of code insrc/functions/katex.jsandstatic/katex.less. It's currently defined as\katexso that you can check out this branch and compare the two:I'd like to suggest that this definition replace the old
\KaTeX, to reduce code complexity, but this definitely needs discussion. Note the spacing is a little different, because it seemed natural to me to more closely match the spacing in\LaTeX. Feel free to disagree!Incidentally, this is also a step toward implementing
\KaTeXin LaTeX, as mentioned in List LaTeX packages that make LaTeX behave most like KaTeX #793. (The existing definition would be challenging to port.)