Commit Graph

406 Commits

Author SHA1 Message Date
Martin von Gagern
4debcb34af Avoid re-lexing, move position to internal state
Instead of passing around the current position as an argument, we now have a
parser property called pos to keep track of that.  Instead of repeatedly
re-lexing at the current position we now have a property called nextToken
which contains the token beginning at the current position.  We may need to
re-lex if we switch mode.  Since the position is kept in the parser state,
we don't need to return it from parsing methods, which obsoletes the
ParseResult class.
2015-11-23 17:40:56 +01:00
Kevin Barabash
5f275aa9c1 Merge pull request #385 from gagern/testErrors
Added unit tests for error messages
2015-11-21 08:54:50 -08:00
Martin von Gagern
e7195601e1 Added unit tests for error messages
This is an attempt to actually exercise all the code paths which can lead to
a ParserError exception (from malformed user input, without tinkering with
any KaTeX internals or exploiting a KaTeX bug).  It documents the current
state of affairs, without changing any error messages.  Comments indicate
future work, particularly with respect to the position often associated with
these error messages.
2015-11-21 15:38:26 +01:00
Kevin Barabash
4617f191e3 Merge pull request #389 from gagern/jasmine
Drop local copy of jasmine, multiple spec files in browser tests
2015-11-20 13:49:37 -08:00
Martin von Gagern
cc17f36edc Drop local copy of jasmine, multiple spec files in browser tests
Instead of having our own copy of jasmine in the repository, we use
jasmine-core as an npm dependency and load it from there.  That reduces the
size of the repository and helps keeping up to date.  We're not using the
transitive dependency on jasmine-core via jasmine, since the jasmine package
might change its dependency any day (although unlikely).

The katex-spec.js shipped from the server now includes all
`test/*[Ss]pec.js` (as matched via glob) so that additional spec files can
be created and will automatically get included in the browser-side test
suite.  The contrib specs are not included at this point.

Visit http://0.0.0.0:7936/test/test.html while running server.js to see this
in action and verify the lack of failures.
2015-11-12 18:34:31 +01:00
Kevin Barabash
bfb3827df1 Merge pull request #387 from gagern/jasmine
Switch from jasmine-node to jasmine itself
2015-11-12 08:56:06 -08:00
Kevin Barabash
1c50688cba Merge pull request #371 from stared/patch-1
Readme - set recent version (0.5.1) for CDN links
2015-11-12 08:16:30 -08:00
Martin von Gagern
92034c17f9 Switch from jasmine-node to jasmine itself
Jasmine supports node these days, so there is no longer a need to use a
separate (and unmaintained) package to provide such bindings.

Making the switch exposed several misuses of the `toMatch` assertion in the
existing specification.  Most of them were converted to `toEqual`, since
`toMatch` is only for matching against regular expressions.
2015-11-10 12:38:49 +01:00
Kevin Barabash
21a26b807c Merge pull request #381 from gagern/travisScreenshots
Check screenshots on Travis using Docker and Selenium
2015-11-07 11:04:24 -08:00
Martin von Gagern
9fb04dbb2e Add verification mode to screenshotter
Now Travis can run the screenshotter in verification mode.  The files in the
repository will be seen as the expected outcome, and if the actual result
differs from that, it might be attempted four more times before the test
case is actually deemed failed.  A timeout between page load and screenshot
should allow any possible font issues to settle down.
2015-11-07 16:32:02 +01:00
Martin von Gagern
5ecbcf6808 Check screenshots on Travis using Docker and Selenium
Thanks to the docker service provided by Travis CI, we should be able to
download and use the Selenium docker images in order to run our
screenshotter and check whether all the screenshots match the images from
the repository.
2015-11-06 13:02:53 +01:00
Kevin Barabash
c20b8f8456 Merge pull request #369 from utensil/master
Add a link to symbol/function support preview page
2015-10-20 08:21:12 -07:00
utensil
dcc3214527 Add a link to symbol/function support preview page 2015-10-20 16:25:02 +08:00
Kevin Barabash
c6800749ab Merge pull request #372 from Newman101/Issue370
Resolved Issue #370
2015-10-19 10:29:26 -07:00
newman101
f039068fae Updated link label 2015-10-19 18:18:18 +01:00
newman101
bc4693a71b Resolved Issue #370 2015-10-19 16:57:04 +01:00
Piotr Migdał
69130d6a19 Readme - set recent version (0.5.1) for CDN links 2015-10-19 16:53:05 +02:00
Kevin Barabash
d87ee4f78f Merge pull request #366 from Khan/add_width_to_font_metrics
Add a build step to generate extended metrics that additionally contain glyph widths
2015-10-16 14:41:31 -07: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
ee88cc3c11 Merge pull request #363 from gagern/modeStateful
Make mode part of the internal state of the parser
2015-10-05 16:36:05 +00:00
Kevin Barabash
9aab9c1efe Merge pull request #361 from crepererum/feature/gt_lt
Add \gt and \lt
2015-10-05 16:32:49 +00:00
Marco Neumann
95e568ed6b Add \gt and \lt 2015-10-05 08:34:03 +02:00
Martin von Gagern
cabc08598b Make mode part of the internal state of the parser
This is the first step towards #266.
2015-10-04 20:35:43 +02:00
Kevin Barabash
e9f4b07611 Merge pull request #364 from gagern/lexerRewrite
Refactor lexer, avoiding some mode-specific distinctions
2015-10-03 13:31:51 -07:00
Martin von Gagern
d423bec089 Rewrote lexer, avoiding some mode-specific distinctions
There are two main motivations for this commit.  One is unicode input, which
requires unicode characters to get past the lexer.  See discussion in #261.
The second is in preparation for #266, where we'd deal with one token of
look-ahead but might be lexing that token in an unknown mode in some cases.
The unit test shipped with this commit addresses the latter concern, since
it checks that a math-mode-only token may immediately follow some text mode
content group.

In this new implementation, all the various things that could get matched
have been collected into a single regular expression.  The hope is that
this will be beneficial for performance and keep the code simpler.
The code was written with Unicode input in mind, including non-BMP codepoints.

The role of the lexer as a gate keeper, keeping out invalid TeX syntax, has
been abandoned.  That role is still fulfilled by the symbols and functions
tables, though, since any input which is neither a symbol nor a command is
still considered invalid input, even though it lexes successfully.
2015-10-02 20:06:03 +02:00
Kevin Barabash
95e2f1c8d7 Merge pull request #356 from gagern/callingConvention
New calling convention for functions and environments
2015-10-01 08:42:52 -07:00
Martin von Gagern
30f7a1c5bf New calling convention for functions and environments
Fixes issue #255.

Mixing the variable number of arguments a function receives from TeX code
with the fixed arguments which the parser provides can cause some confusion.
After this change, a handler will receive exactly two arguments: one is a
context object from which things provided by the parser can be accessed by
name, which allows for simple extensions in the future.  The other is the
list of TeX arguments, passed as an array.

If we ever switch to EcmaScript 2015, we might want to use its destructuring
features to name the elements of the args array in the function head.  Until
then, destructuring that array manually immediately at the beginning of the
function seems like a useful convention to easily find the meaning of these
arguments.
2015-10-01 13:15:44 +02:00
Kevin Barabash
a81c4fe78d Merge pull request #362 from Khan/array_font_metrics
Use an array of values instead of object literals to save space in fontMetricsData.js
2015-09-30 10:00:23 -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
Kevin Barabash
fdbdb28617 Merge pull request #346 from gagern/splitSymbols
Reformat symbol table
2015-09-25 14:56:18 -07:00
Kevin Barabash
f25829df58 Redirect people to gitter instead of freenode 2015-09-25 14:35:23 -07:00
Kevin Barabash
8e54d6e365 Merge pull request #360 from gitter-badger/gitter-badge-1
Add a Gitter chat badge to README.md
2015-09-25 14:32:23 -07:00
The Gitter Badger
b9b8396b6f Add Gitter badge 2015-09-25 21:28:31 +00:00
Kevin Barabash
3203959b96 Merge pull request #352 from Khan/fix_font_greediness
Set the greedines of font functions to 2 so that e^\mathbf{x} will parse
2015-09-25 14:20:23 -07:00
Kevin Barabash
b98670b8ed Set the greedines of font functions to 2 so that e^\mathbf{x} will parse
Test Plan: make test

Reviewers: emily
2015-09-25 14:17:23 -07:00
Emily Eisenberg
961e1caba9 Merge pull request #359 from xymostech/fix-zero-rule-padding
Remove 3px border around rules.
2015-09-22 13:16:18 -07:00
Emily Eisenberg
252f6320ef Remove 3px border around rules.
Summary: For some reason, adding `border-style: solid` also adds a 3px
border around elements, which means that all of the rules that we
created are 3px too large. This sets the default size to 0 for all the
edges, which makes them correct.

Test plan:
 - See that `a\rule{0em}{0em}b` produces no visible rule.
 - See the new screenshots look reasonable.
2015-09-22 10:21:33 -07:00
Kevin Barabash
d7d1367558 Merge pull request #347 from gagern/splitEnvironments
Split up environments list into calls to defineEnvironment
2015-09-14 22:51:04 -06:00
Kevin Barabash
0fc77e2f40 Merge pull request #345 from gagern/splitFunctions
Split up functions list into calls to defineFunction
2015-09-14 22:44:21 -06:00
Kevin Barabash
112e6783b3 Merge pull request #349 from gagern/texcmpLogo
Make texcmp work again, including KaTeX logo
2015-09-11 11:43:28 -07:00
Martin von Gagern
2e0f11bdfa Reindent some comment code as well 2015-09-11 09:27:47 +02:00
Kevin Barabash
89e0d7950c Merge pull request #348 from gagern/splitBuildHandlers
Split groupType literals in buildHTML and buildMathML
2015-09-10 22:36:13 -07:00
Martin von Gagern
71881e3d36 Make texcmp work again, including KaTeX logo
Since all the math font test cases use the KaTeX logo, we need that.
I started with the definition of the logo from katex.less, but tweaked that
until it gave a good visual match, in particular a very similar logo width,
no matter the actual numbers.

With that logo, most tests can be compiled again, with the exception of the
one containing illegal functions to test visual error reporting.
That one needs to be explicitely disabled.
2015-09-10 16:05:23 +02:00
Martin von Gagern
d809f9c362 Reindent groupType definitions in buildHTML and buildMathML
Since the previous commit deliberately avoided reindenting, this one here
does just that: reindenting the existing code.  There are no other changes.
2015-09-10 11:47:47 +02:00
Martin von Gagern
6bc7cd574f Split up groupType map in buildHTML and buildMathML code
Having long object literals containing the code is problematic.
It makes it difficult to add auxiliary functions or data close to the
function inside the map where it is needed.
Building the map in several steps, repeating the map name at each step,
avoids that problem since it makes the definitions independent from one
another, so anything can go between them.

This commit deliberately avoided reindenting existing code to match the new
surroundings.  That way it is easier to see where actual changes happen,
even when not performing a whitespace-ignoring diff.
2015-09-10 11:34:34 +02:00
Martin von Gagern
dae3a14744 Reindent environments
Since the previous commit deliberately avoided reindenting, this one here
does just that: reindenting the existing code.
2015-09-10 11:18:11 +02:00
Martin von Gagern
2a31a719ec Split up environments list into calls to defineEnvironment
Having one long array literal to contain the code of all environment
implementations is problematic.  It makes it difficult to add auxiliary
functions or data close to the function inside the list where it is needed.

Now the functions are no longer defined using such a literal, but instead
using calls to a "defineEnvironment" function which receives all the
relevant data.  Since each function call is independent from the others,
anything can go in between.

This commit deliberately avoided reindenting existing code to match the new
surroundings.  That way it is easier to see where actual changes happen,
even when not performing a whitespace-ignoring diff.
2015-09-10 11:14:00 +02:00
Martin von Gagern
acfdc9f698 Rename declareFunction to defineFunction
https://github.com/Khan/KaTeX/pull/262#issuecomment-113981142 indicated a
preference for define over declare.
2015-09-10 10:23:58 +02:00
Martin von Gagern
414f9dd248 Reformat symbol table
Using function calls instead of one big object literal for the symbols makes
the notation far more concise and readable.  Having the actual symbol name
in the last position helps aligning the preceding columns, making the list
easier to read.

Another benefit is that all symbol definitions now pass through a single
function, where additional processing (e.g. for Unicode input) might take
place in a future commit.
2015-09-10 10:22:42 +02:00
Martin von Gagern
3e055f84e9 Reindent
Since the previous commit deliberately avoided reindenting, this one here
does just that: reindenting the existing code.  There are no other changes.
Notice how the new indentation leaves more room to function handlers.
2015-09-10 09:52:00 +02:00