Commit Graph

23 Commits

Author SHA1 Message Date
Kevin Barabash
14a58adb90 Migrate to eslint
Summary
We'd like contributors to use the same linter and lint rules that we use
internally.  This diff swaps out eslint for jshint and fixes all lint failures
except for the max-len failures in the test suites.

Test Plan:
- ka-lint src
- make lint
- make test

Reviewers: emily
2015-12-01 10:02:08 -08:00
Kevin Barabash
1573e1eed6 Add a build step to generate extended metrics that additionally contain glyph widths
Summary:
The ability to use pre-determined character widths will benefit alternative
layout engines such as gagern's canvas layout engine.  I would also like to
experiment would using CSS transforms to absolutely position each glyph.  This
diff adds a new make rule, make extended_metrics, which generates metrics that
also containing glyph widths.

Test Plan:
- run `make extended_metrics`
- verify that fontMetricsData.js contains entries with 5 numbers instead of 4

Reviewers: emily alpert
2015-10-16 14:31:08 -07:00
Kevin Barabash
6a10237017 Use an array of values instead of object literals to save space in fontMetricsData.js
Test Plan: make test

Reviewers: emily
2015-09-29 22:16:03 -07:00
Blai Pratdesaba
236b7925f1 Add missing semicolon at the end of fontMetricsData 2015-08-06 09:17:42 +01:00
Blai Pratdesaba
8cd71830c2 Generate fontMetricsData as JavaScript 2015-08-05 19:52:42 +01:00
Kevin Barabash
67147b18ac Adds font metrics to support font commands.
This is part 1 of 3.  Rendering, screenshots, MathML, and unit tests will
follow in susbequent pull requests.
2015-07-10 21:50:04 -06:00
Martin von Gagern
b290d4ad76 Switch from fontforge to fonttools
The dependencies of fonttools are much lighter than fontforge, and since all
we need are some metrics, fonttools is very much up to that task.

This addresses issue #288.
2015-07-10 14:32:02 +02:00
Martin von Gagern
d26a67f220 Avoid non-determinisms related to font metric generation
We had some duplicate mappings in mappings to start with.  Now we have some
code to complain loudly about these, and all currently existing duplicates
have been dealt with.

We also had a problem where in some Python dict, existing stuff was using
strings as keys while new data would use numeric indices, thus not
overwriting the previous value.  Now we always use strings as keys.

Along the road, the italic dotless i and j symbols were changed
so that they now are taken from cmmi10 instead of cmti10.
2015-07-10 14:30:42 +02:00
Martin von Gagern
86115b8fce Format font metrix data to have one row for each glyph
This will make reviewing modifications easier, since the affected glyphs
will be more readily visible in the diff.
The formatting tool was applied to the existing data, instead of
regenerating the data, so the semantic content should be unmodified.
2015-07-10 14:30:42 +02:00
Martin von Gagern
1603162267 Save auto-generated font metrics data to separate JSON file
This separates auto-generated code from manually created code.
We need a more recent version of browserify to directly require JSON.
Note that the data was copied, not recreated, so it has not been changed.
This addresses issue #301.
2015-07-10 14:30:41 +02:00
Emily Eisenberg
d61a04c80d Fix up small problems with #126
Summary:
 - Some of the symbols were of the wrong type (I wrote some scripts to
   search the TeX source for the correct types for the symbols; I should
   put these somewhere for future reference)
 - Some of the symbols had the incorrect unicode replacement value. I
   copied what MathJax used for the ones that were wrong. In one case,
   something had the wrong font, so I used the one MathJax used.
 - Some symbols were duplicates of existing symbols, those were removed.
 - Some symbols are text symbols that aren't usable in math mode (maybe
   they should be text symbols?) (`\aa`, `\AA`, etc.)
 - Some symbols didn't seem to work/I couldn't figure out how to make
   them work. For example, `\imath` and `\jmath` require an italic font
   in KaTeX_Main, but we don't have the ability to do that yet. `\dots`
   was removed because it's not an ordinary symbol. `\*vert` were
   removed because I don't understand what they're for, nor what they
   should look like.
 - Some symbols weren't actually in the KaTeX fonts; to make sure they
   don't fall back to something weird, I removed them. (`\S`, `\pounds`,
   etc.)

Test plan:
 - `make test`
 - See that all of the symbols in: `\equiv \prec \succ \sim \perp
   \preceq \succeq \simeq \mid \ll \gg \asymp \parallel \bowtie \smile
   \sqsubseteq \sqsupseteq \doteq \frown \ni \propto \vdash \dashv \owns
   \ldotp \cdotp \aleph \forall \hbar \exists \nabla \flat \ell \natural
   \clubsuit \wp \sharp \diamondsuit \Re \heartsuit \Im \spadesuit
   \rmoustache \lmoustache \rgroup \lgroup \mp \ominus \uplus \sqcap
   \ast \sqcup \bigcirc \bullet \ddagger \wr \amalg \longleftarrow
   \Leftarrow \Longleftarrow \longrightarrow \Rightarrow \Longrightarrow
   \leftrightarrow \longleftrightarrow \Leftrightarrow
   \Longleftrightarrow \mapsto \longmapsto \nearrow \hookleftarrow
   \hookrightarrow \searrow \leftharpoonup \rightharpoonup \swarrow
   \leftharpoondown \rightharpoondown \nwarrow \rightleftharpoons \nless
   \nleqslant \nleqq \lneq \lneqq \lvertneqq \lnsim \lnapprox \nprec
   \npreceq \precnsim \precnapprox \nsim \nshortmid \nmid \nvdash
   \nvDash \ntriangleleft \ntrianglelefteq \subsetneq \varsubsetneq
   \subsetneqq \varsubsetneqq \ngtr \ngeqslant \ngeqq \gneq \gneqq
   \gvertneqq \gnsim \gnapprox \nsucc \nsucceq \succnsim \succnapprox
   \ncong \nshortparallel \nparallel \nVDash \ntriangleright
   \ntrianglerighteq \nsupseteqq \supsetneq \varsupsetneq \supsetneqq
   \varsupsetneqq \nVdash \precneqq \succneqq \nsubseteqq \unlhd \unrhd
   \nleftarrow \nrightarrow \nLeftarrow \nRightarrow \nleftrightarrow
   \nLeftrightarrow \vartriangle \hslash \triangledown \lozenge
   \circledS \measuredangle \nexists \mho \Finv \Game \Bbbk \backprime
   \blacktriangle \blacktriangledown \blacksquare \blacklozenge \bigstar
   \sphericalangle \complement \eth \diagup \diagdown \square \Box
   \Diamond \beth \daleth \gimel \digamma \varkappa \ulcorner \urcorner
   \llcorner \lrcorner \leqq \leqslant \eqslantless \lesssim \lessapprox
   \approxeq \lessdot \lll \lessgtr \lesseqgtr \lesseqqgtr \doteqdot
   \risingdotseq \fallingdotseq \backsim \backsimeq \subseteqq \Subset
   \sqsubset \preccurlyeq \curlyeqprec \precsim \precapprox
   \vartriangleleft \trianglelefteq \vDash \Vvdash \smallsmile
   \smallfrown \bumpeq \Bumpeq \geqq \geqslant \eqslantgtr \gtrsim
   \gtrapprox \gtrdot \ggg \gtrless \gtreqless \gtreqqless \eqcirc
   \circeq \triangleq \thicksim \thickapprox \supseteqq \Supset
   \sqsupset \succcurlyeq \curlyeqsucc \succsim \succapprox
   \vartriangleright \trianglerighteq \Vdash \shortmid \shortparallel
   \between \pitchfork \varpropto \blacktriangleleft \therefore
   \backepsilon \blacktriangleright \because \llless \gggtr \lhd \rhd
   \eqsim \Join \Doteq \dotplus \smallsetminus \Cap \Cup \doublebarwedge
   \boxminus \boxplus \divideontimes \ltimes \rtimes \leftthreetimes
   \rightthreetimes \curlywedge \curlyvee \circleddash \circledast
   \centerdot \intercal \doublecap \doublecup \boxtimes \dashrightarrow
   \dashleftarrow \leftleftarrows \leftrightarrows \Lleftarrow
   \twoheadleftarrow \leftarrowtail \looparrowleft \leftrightharpoons
   \curvearrowleft \circlearrowleft \Lsh \upuparrows \upharpoonleft
   \downharpoonleft \multimap \leftrightsquigarrow \rightrightarrows
   \rightleftarrows \twoheadrightarrow \rightarrowtail \looparrowright
   \curvearrowright \circlearrowright \Rsh \downdownarrows
   \upharpoonright \downharpoonright \rightsquigarrow \leadsto
   \Rrightarrow \restriction \yen \dag \ddag` look the same as they do
   in LaTeX and don't print any warnings about unknown font metrics.

Auditors: alpert
2015-02-18 16:28:05 -08:00
Emily Eisenberg
b7e55607cc Add skew and italic metrics for ttfs
Summary:
Add the ability to base the metrics for a TTF character on the metrics
from one of the TFM characters.

Test Plan:
 - Make sure the tests still work
 - Make sure huxley tests didn't change

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D13217
2014-09-16 17:40:20 -07:00
Emily Eisenberg
e6b3cbe7c1 Add font metrics for \iint, \iiint
Also, fix the python dict keys so we actually get the metrics back into the
javascript correctly.

Fixes #56

Auditors: alpert
2014-09-16 16:00:30 -07:00
Emily Eisenberg
35d9d972fd Move js files into src/
Test plan:
- Make sure huxley tests, jasmine tests, make build, make metrics, make test all
  still work.

Auditors: alpert
2014-09-15 02:50:34 -07:00
Emily Eisenberg
0dca731da6 Add accents
Summary:
Add support for math-mode accents. This involves a couple changes.
First, in order to correctly position the accents, we must know the kern between
every character and the "skewchar" in that font. To do this, we improve our tfm
parser to run the mini-kern-language and calculate kerns. We then export these
into fontMetrics.js.

Then, we add normal support for accents. In particular, we do some special
handling for supsubs around accents. This involves building the supsub
separately without the accent, and then replacing its base with the built
accent.

Finally, the character in the fonts for the \vec command is a combining unicode
character, so it is shifted to the left, but none of the other characters do
this. We add some special handling for \vec to account for this.

Fixes #7

Test Plan:
 - Make sure tests pass
 - Make sure no huxley screenshots changed, and the new one looks good

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D13157
2014-09-13 21:30:35 -07:00
Emily Eisenberg
79ab06d88d Get rid of the lookahead-y dots
Summary:
The `\dots` and `\dots{c,o,b,i,m}` commands do more than just show characters,
they add extra space and `\dots` also looks ahead to determine what kind of
environment it is in (see [this math.sx post]
(http://tex.stackexchange.com/questions/122491/difference-of-the-dots)). We
can't support that yet, so remove them.

Also, add comments to the extract_ttf script to show what caracters we are
extracting metrics for.

Test Plan: - Make sure tests work

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D13151
2014-09-12 17:29:49 -07:00
Emily Eisenberg
6ee2ecf47e Add \dots commands
Add all of the \dots commands, and import their metrics from the ttf files.

Fixes #23

Auditors: alpert
2014-09-12 15:02:18 -07:00
Emily Eisenberg
71da6aa50f Add the ability to extract metrics from ttfs
Summary:
Upon switching over from ttf metrics to TeX metrics, we lost metrics for a
couple of the characters that are dynamically generated by TeX. Thus TeX doesn't
have metrics for them, but our fonts do have the characters because the MathJax
scripts also dynamically build them. This adds the ability to extract metrics
from the generated font files so that we can use the generated characters
correctly. A better solution would be to dynamically generate the characters
ourselves, but that is much harder, and will be left to a future time.

Test Plan:
 - Make sure typing "\neq \cong \text{ }" produces no warnings in the console.
 - Make sure huxley screenshots look the same

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D13107
2014-09-12 14:59:28 -07:00
Emily Eisenberg
c3f758c319 Add support for \left and \right
Summary:
Added stacked delimiter support for more delimiters. Split out delimiter
functions into its own file, and split out some tree building functions into a
common file. Supports the empty `.` delimiter with \left and \right, and doesn't
try to produce huge /, \backslash, <, or > delimiters. Depends on D7844

Test input:

\left( \left) \left[ \left\lbrack \left] \left\rbrack \left\{ \left\lbrace
\left\} \left\rbrace \left\lfloor \left\rfloor \left\lceil \left\rceil
\left\langle \left\rangle \left/ \left\backslash \left| \left\vert \left\|
\left\Vert \left\uparrow \left\Uparrow \left\downarrow \left\Downarrow
\left\updownarrow \left\Updownarrow {x^{x^{x^{x^{x^{x^{x^{x^{x^{x^x}}}}}}}}}}
\right.\right.\right.\right.\right.\right.\right.\right.\right.\right.
\right.\right.\right.\right.\right.\right.\right.\right.\right.\right.
\right.\right.\right.\right.\right.\right.\right.\right.

Test Plan:
 - Run the test input, see that it works
 - Run the tests, see that they work
 - Look at huxley screenshots (not here yet :( ) and make sure they look good

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D11602
2014-09-04 21:58:43 -07:00
Emily Eisenberg
e418fd9ee3 Update metrics using TeX metrics instead of TTF metrics
Summary:
Instead of using the metrics from our generated TTF files, use the fonts that
TeX ships with. Pull the mapping out of the MathJax-dev repo from makeFF to get
the correct mapping of metrics to font characters, and use our own tfm reader to
extract metrics out of the tfm files into a useable format. Add a README and
Makefile rule to make this process easier in the future.

Also remove the silly 0.05em we put on supsubs because our italic correction
works now.

Test Plan:
- Run huxley tests, see that changes are because of font metric changes.
- See that the extension piece of `\bigl |` now extends above the top, as it is
  supposed to.

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D12867
2014-09-03 20:12:00 -07:00
Ben Alpert
7f25fd7dc9 Parse metrics directly from .ttf files
Summary:
Fixes T1325.

This has the advantage of not having to do the mapping manually. Also it means that characters like \neq are included in the mapping, so this resolves T1323 as well.

I opted to group the metrics by character instead of by metric type because I think it'll gzip better and it makes getCharacterMetrics simpler anyway.

Test Plan: The test page looks identical to the pixel to my eye.

Reviewers: emily

Reviewed By: emily

Maniphest Tasks: T1323, T1325

Differential Revision: http://phabricator.khanacademy.org/D3535
2013-08-14 10:57:00 -07:00
Emily Eisenberg
9fc357b8a1 Add italic correction
Summary: Add margin to the right of characters that have italic correction.

Test Plan:
Look at `f'` and `C'` before and after. Note that they both now look
good at small font sizes (like 17pt).

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D3534
2013-08-14 10:51:09 -07:00
Emily Eisenberg
0a3a2271f4 Add ability to calculate heights/depths
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
2013-08-13 18:16:43 -07:00