Summary:
In LaTeX, large delimiters are the same font size as they are at a normal size,
regardless of the actual size. This means that we need to scale up the font size
in the inner nodes, which is annoying because we run into the same problem we
had with \Huge, etc in those nodes. Thus, this fixes both problems at once.
The problem was that when we used our baseline-align-hack and then increased the
font size inside of one of the middle (display: block and height: 0) nodes, the
node with the increased font size would shift downards (misaligning its
baseline). To fix this, we add a method for calculating the maximum font size
used in each of the nodes, and adding a small node with this font size to each
of the other nodes (including the fix-ie node). This shifts all of the nodes
down the same amount, and gets their baselines aligned.
Test Plan:
- Do dumb things by putting \Huge and \big in places they shouldn't be, and
make sure they behave responsibly
- Do the same thing in IE 8, 9, 10, 11, Safari, Firefox, and make sure they all
behave the same (to some approximation)
- Make sure the new huxley image looks good, and the images that changed don't
have significant changes
Reviewers: alpert
Reviewed By: alpert
Differential Revision: http://phabricator.khanacademy.org/D12684
Summary:
Implicit groups are objects that act like groups but don't have brackets around
them. This is used for things like sizing functions or font-change functions
that can occur in the middle of the group, but act like they apply to a group
after them which stops when the current group stops. E.g. `Hello {world \Large
hello} world` produces normal, normal, Large, normal text. (Note, I just came up
with the name implicit group, I don't think this is actually how it is parsed in
LaTeX but it fits nicely with the current parsing scheme and seems to work
well).
For now, apply this to the sizing functions (we don't have any other functions
that act like this). Also note that this doesn't really do much practically
because we limit sizing functions to only be on the top level of the expression,
but it does let people do `\Large x` and get a large `x`, without having to add
braces.
Test Plan:
- Run the tests, see they work
- Make sure `abc \Large abc` looks correct
Reviewers: alpert
Reviewed By: alpert
Differential Revision: http://phabricator.khanacademy.org/D10876
Summary:
Keep track of the color inside the style now, and use that when we are
rendering things. Added a custom lexing mode to handle lexing colors correctly.
Prefixed the old katex colors (internally) with "katex-" to distinguish them
from CSS colors.
Test Plan:
- Run the normal tests, see they work
- Run the huxley tests, see that they didn't change except for the color one
which looks right
Reviewers: alpert
Reviewed By: alpert
Differential Revision: http://phabricator.khanacademy.org/D7763
Summary:
Right now, when the size gets bigger, this still doesn't work, so there's a
check to prevent that. However, functions that go smaller (like `\small`,
`\tiny`, etc) do work. Also, we can't seem to use the sizing functions inside
of fractions (so something like `\dfrac{\small\frac{x}{y}}{z}` doesn't work).
However, the most prominent use case is `\small` as the outer-most object, so
this is still helpful. This commit has the parsing and stuff to handle all of
it, but it'll throw an error if you try to do something that doesn't work. (For
the record, "doesn't work" means "looks bad", not "throws an unexpected
error").
Test Plan:
Make sure things like `\small x` work, and things like `\Huge x` and
`\frac{\small x}{y}` don't.
Reviewers: alpert
Reviewed By: alpert
Differential Revision: http://phabricator.khanacademy.org/D3619
Summary:
This diff does a couple different things:
- There is now a metrics/ folder, which contains the property files describing
the metrics if the fonts, as well as a script for reading and printing the
metrics in javascript.
- Fractions and superscripts/subscripts are now rendered in slightly different
ways now (notably, no use of inline-table). This allows for much more precise
positioning of the superscripts, subscripts, numerators, and denominators,
while still having an appropriate baseline. Also, there is no longer a
sup/sub/supsub distinction, there are only supsubs with null sup/sub.
- Using the new font metrics and by implementing the formulas found in The TeX
Book, Appendix G, the heights and depths of all of the sub-expressions in a
formula are now calculated. These are currently used to:
- Correctly position superscripts, subscripts, numerators, and denominators
- Adjust the height and depth of the overall expression so it takes up the
appropriate space
- Because we have to add attributes (height and depth) to every attribute, I
have changed the way DOM nodes are assembled. Now, instead of assembling the
DOM elements inline (which is a problem because we need to track
height/depth, and we shouldn't (and can't in IE 8) attach raw attributes to DOM
nodes), we assemble a pseudo-DOM structure with the extra information, and
then actually assemble it at the very end.
The main page also now has an updated expression to show off and test the new
and improved parsing.
Test Plan:
View the main page, make sure that the expression renders. Make sure
that the tests pass. Make sure that expressions have the correct calculated
height (this is most easily tested by viewing them on the main page and making
sure that the top of the expression lines up with the bottom of the input box).
Reviewers: alpert
Reviewed By: alpert
Differential Revision: http://phabricator.khanacademy.org/D3442