Commit Graph

252 Commits

Author SHA1 Message Date
Ron Kok
2aee354ca2 Support Reaction Arrows (#1078)
* Support Reaction Arrows

This PR is written to supply reaction arrows for a future `mhchem` extension. `mhchem` uses seven reaction arrows. Four of them correspond to extensible arrows already available in KaTeX. This PR creates the other three.

These arrows will also be useful to chemists writing about reactions when `mhchem` is unavailable.

Three new extensible arrows are introduced: `\xrightleftarrows`, `\xrightequilibrium`, and `\xleftequilibrium`.

These names are not `mhchem`’s user-facing function names. In `mhchem`, users would call these arrows with syntax such as: `\ce{A<-->B}`, or `\ce{A<=>>B}`, or `\ce{A<<=>B}`. I’ve provided names that look more like the other extensible arrow names. That’s probably worth some discussion.

* generate screenshots for ReactionArrows

* Increase overlap in arrow shaft

To prevent a small gap when rendering in very large font sizes.

* Adjust upper text vert alignment. Add warning.

* Limit alignment adjustment to \xleftequilibrium

* generate screenshots for reaction arrows
2018-02-04 15:52:22 -05:00
Ron Kok
ea3b6abe32 Enable spacing functions in text mode (#1139)
* Enable spacing functions in text mode

Spacing functions such as `\;` or `\quad` should be accepted in either math mode or text mode

* Add tests

* Fix tests

* Fix lint error
2018-02-04 13:58:04 -05:00
Kevin Barabash
603f12df8d add support for unicode angle brackets, single vertical bar, double vertical bar (#1123)
* add support for unicode angle brackets

* add tests, remove vertical bar changes

* fix 'message not a function' errors
2018-01-31 20:03:16 -05:00
Kevin Barabash
4bec90be0c extract font functions and implicit color function (#1119)
* extract font functions and implicit color function

* remove oldFontFuncs from Parser.js

* allow old font commands in text mode
2018-01-31 10:03:30 -05:00
Kevin Barabash
f80d0afee8 extract sizing and styling implicit functions (#1116)
* extract sizing and styling implicit functions

* add BreakToken type
2018-01-30 07:13:01 -05:00
Kevin Barabash
03c5ce7f87 add perf tests, fixes #1053 (#1054) 2018-01-29 20:38:14 -05:00
Ryan Randall
097d592b47 Merge branch 'master' into bolditalic 2018-01-28 14:54:35 -05:00
Kevin Barabash
c627de04d9 use correct spacing with tight styles (#1106) 2018-01-27 22:12:25 -05:00
Kevin Barabash
ea7a560191 add Main-BoldItalic font to allow nesting of \textit and \textbf 2018-01-27 11:32:14 -05:00
Kevin Barabash
f03849c831 update fonts and metrics so that accents are positioned correctly (#1094)
* update fonts and metrics so that accents are positioned correctly

* fix degree symbol, move more accents into the 0x2c0-0x2df range

* fix accents in Unicode screenshots

* update jest snapshots, update AccentsText to include requested characters

* update fonts submodule, add unicode chars to AccentsText test

* update submodules after merging its PR
2018-01-26 19:46:57 -05:00
David Flanagan
53203ed92c Add a screenshot test to ensure that we don't inherit svg-only CSS properties (#1092)
We want to inherit CSS properties that apply to both text and SVG
but we don't want to inherit styles that affect SVG without affecting text.

This patch adds a screenshot test to verify this.
2018-01-25 14:02:06 -05:00
Kevin Barabash
63f541b6e6 Use JS for spacing between atoms instead of CSS (#1070)
* Use JS for spacing between atoms instead of CSS

Summary:
This is the first step towards creating an intermediate representation
that can be used to generate HTML, SVG, and Canvas commands for rendering.
By generating spans that contain the width of the spaces instead of
relying on CSS sibling rules we'll be able to one day replaces the spans
with intermeidate 'Glue' nodes (in a later PR).

An added benefit of this approach is that is enables us to programmatically
change the values for thinspace, mediumspace, and thickspace which will
allow us to implement the \setlength command.

Test Plan:
- npm test
- dockers/Screenshotter/screenshotter.sh --verify

* fixed failures in BinCancellation, BoldSymbol, and OperatorName

* update screenshots

* don't use current size when determining size of spaces, update more screenshots

* fix spacing in SizingBaseline and StyleSwitching

* actually do the right thing for sizing groups

* fix \not for Chrome and Firefox

* do TODOs

* address feedback from the code review

* fix issue in delimsizing.js

* add TODO to think about a better solution in href.js

* fix typos, simplify href, be honest about paddingLeft for \not
2018-01-24 23:03:36 -05:00
David Flanagan
853e2a4fb7 Support more scripts in \text{} environments. (#1076)
* Support more scripts in \text{} environments.

This diff is a follow-up to PR #1060 which added support for Indic scripts.
In order to support Czech, Turkish and Hungarian text (at least) inside
\text{} environments, we need to recognize the Latin Extended A and B
Unicode blocks. The patch also adds support for Georgian, and enhances
support for Cyrillic by defining the entire Cyrillic unicode block instead
of defining symbols for a subset of Cyrillic letters as we did previously.

* Only return fontMetrics for supported Unicode scripts in text mode

The Unicode scripts listed in unicodeScripts.js are supported in text mode
but getCharacterMetrics() was returning fake metrics for them even in
math mode. This caused bad handling of \boldsymbol\imath

* use Mode from types.js
2018-01-22 00:53:17 -05:00
ylemkimon
5f32b71c85 Use webpack to build files and webpack-dev-server for testing (#1068)
* Create a separate entry point for webpack

Created a webpack entry point for KaTeX, which imports katex.less. As
flow[1] and jest[2] doesn't support CSS modules natively, a separate
entry point is used and it is not flowtyped.

[1] https://gist.github.com/lambdahands/d19e0da96285b749f0ef
[2] https://facebook.github.io/jest/docs/en/webpack.html

* Use webpack to build files

* Made webpack.config.js export valid webpack configuration
* Use:
browserify -> webpack
babelify -> babel-loader
UglifyJS CLI -> UglifyJsPlugin
Less CLI -> less-loader
cleancss -> cssnano in css-loader
build/fonts -> file-loader
* Inline CSS(Less) using style-loader and export them using
ExtractTextPlugin
* Add `watch` npm script calling `webpack --watch`

* Improve local testing(webpack-dev-server)

* Made webpackDevServer export a valid webpack configuration
* Compile Less and inline CSS using less-loader and style-loader
* Instead of copying files serve files from /static and use file-loader
* Remove old server.js and its dependencies

* Use webpack-dev-server in Screenshotter

* Include contrib in webpack-dev-server

+ Moved common configurations to webpack.common.js

* Rename webpackDevServer.js to webpack.dev...

to be consistent, avoid confusion with webpack-dev-server and follow
webpack configuration naming convention.

* Remove unnecessary conditional output.path

* Use map instead of reduce

+ Add comments regarding function arguments

* Remove unnecessary mkdir and clean build/* before build

* Use katex as external dependency instead of global variable in contrib

Fixes #692.

* Unblock codes as they are built as a module

* Update package-lock.json

* Add comments regarding devServer option

* Lint renamed webpack.dev.js

a0d8b33

* Export ES6 module and expose its default export

* Revert "Browserify hotfix (#1057)"

This reverts commit f6b509123b.

* Enables colors on the console when running the dev server in Screenshotter

* Add context to webpack configuration

Allows webpack to be run from other directories

* Move `rm -rf build/*` to npm scripts

* Check dependencies before build

* Move UglifyJsPlugin into config creation

* Let webpack handle ES6 modules

Do not transform modules to commonjs in Babel. However Jest doesn't not
support ES6 modules, so transfrom modules to commonjs when NODE_ENV is
`test`.

* Add documentation on testing in IE 9 and 10 using webpack-dev-server

Changed version range to include IE-compatible version
2018-01-21 19:48:25 -05:00
Erik Demaine
a32f82a8ea Add support for \aa, \AA, \lq, \rq, \lbrack, \rbrack (#1069)
* Add support for \aa, \AA, \lq, \rq, \lbrack, \rbrack

The lack of \aa and \AA was reported in #1066.  Added these
via simple macros, with supporting tests.  Also add \lq, \rq,
\lbrack, \rbrack as aliases for "`", "'", "[", "]" which were
in the same area of latex.ltx.

* removed duplicate comment
2018-01-16 12:07:50 -05:00
David Flanagan
7fe6af2a82 Add basic support for Indic scripts in addition to CJK. (#1060)
This patch just makes KaTeX recognize Unicode codepoints in the
range \u0900-\u109f so that those South and Southeast Asian scripts
do not get automatically rejected.

The patch also generalizes the way that Unicode blocks are handled
to make it easier to add support for new scripts in the future.
src/unicodeRegexes.js is replaced with the new file src/unicodeScripts.js
2018-01-12 19:14:31 -05:00
Erik Demaine
484d44ee70 Unicode accents (#992)
* Unicode accents

* Lexer now looks for combining dicritical marks and adds them to the same character
* Parser's `parseSymbol` now recognizes both combined and uncombined forms of Unicode accents, and builds accent objects just like the accent functions
* Added CJK support to math mode (not just text mode)

* Add invalid combining character test

* Add MathML test

* Add weak support for other Latin-1 characters

This maintains backwards compatibility, but it uses the wrong font.
There's a TODO to fix this later.

Also refactor symbol code to use for..of

* Update Unicode screenshot

* Remove dot from accented i and j (in math mode)

Also add dotless Unicode characters to support some accented i's and j's

* Fix \imath, \jmath, \pounds, and more tests

* Switch from for..of to .split().forEach()

Save around 800 bytes in minified code

* Fix split

* normalize() detection

* Convert back to vanilla for loops

* Fix merge

* Move normalize dependency to unicodeMake.js

* Make unicodeSymbols into a lookup table instead of macros

This is important for multi-accented characters.

* Add comments about when to run

* Move symbols definition into unicodeMake/Symbols.js

* Remove CJK support in text mode

* Add missing semicolon

* Refactor unicodeAccents to its own file

* Dotless i/j support in text mode

* Remove excess character mappings

* Fix Åå in math mode (still via Times)

* Update to support #1030

* Add accented Greek letter support (for supported Greek symbols)

* Update screenshot

* remove Æ, æ, Ø, ø, and ß from math mode test
2017-12-28 23:32:45 -07:00
Erik Demaine
d822f04b9b \kern generates right-margin instead of left-margin. Fix #995 (#1019)
* \kern generates padding instead of margin. Fix #995

* Switch to marginRight

* Add screenshot tests
2017-12-28 23:03:08 -07:00
Kevin Barabash
7229f02d8f Implement correct macros for liminf and limsup, fixes #111 (#887)
* Implement correct macros for liminf and limsup, fixes #111

* fix nits
2017-12-26 17:11:10 -07:00
Ron Kok
c62f814765 Fix frac-line (#1025)
* Fix frac lline

For frac-line, use an SVG line in an extra tall span.

I still need to think of a way to adust `vertical-separator`.

* Fix spaces in katex.less

* regenerate screenshots

* update HorizontalBraces and StrikeThrough screenshots
2017-12-26 16:17:06 -07:00
Erik Demaine
d6791b7961 Make accents zero width (#1033)
* Make accents zero width

Make the width of an accented character equal to the width of the character,
by making accents zero width.  In particular, fixes #1028 (`\ddot\imath`).

This involved reworking all of the accent offset machinery, in particular
skew and accent-hungarian.  A bit cleaner now.

Also added support for the new width character metrics in symbolNode.

* Update AccentsText test

* Fix comment
2017-12-25 11:48:32 -07:00
Kevin Barabash
522b238e20 add \ae, \AE, \oe, \OE, \o, \O, \ss with unicode support for those characters in text mode (#1030) 2017-12-22 12:42:43 -07:00
Kevin Barabash
2b2cf73f2e add \i and \j for text mode (#1029) 2017-12-22 13:57:31 -05:00
Erik Demaine
c30edaaf5b Implement \TextOrMath, \@secondoftwo (#1024)
* Implement \TextOrMath, \@secondoftwo

* Parser now tells MacroExpander about mode switching.  (This seems preferable
  to a circular reference between Parser and MacroExpander.)
* Implement \TextOrMath
* Improve when we switch modes so that this actually works,
  in all cases except single-symbol arguments.
* Add \@secondoftwo to match \@firstoftwo.
* Add comments documenting all the conditional macros

* Define type for switchMode

* Fix mode detection for ligatures

* Switch mode before the call to parseSymbol() in parseGroup

This fixes the Colorbox screenshot test.
2017-12-21 21:43:27 -07:00
Ron Kok
4410d48d5c Fix \vec (#1018)
* Fix \vec

In accent \vec, replace the combining font glyph with an SVG.

* Fix lint error

* update screenshots containing vectors

* update HorizontalBraces
2017-12-17 22:05:21 -07:00
Ryan Randall
50765a0ccd Stacking text commands (#1009)
* Adding support for SansSerif-Bold

* Updating to include SansSerif Italic.

* WIP

* Working text stacking

* More robust screenshot.

* Don't want to break users :)

* Updating per PR comments.

* Fixing Unicode and updating snapshots.

* Adding suggested tests.

* Opting to use old method for unit testing.

* Adding TODO
2017-12-13 09:10:23 -05:00
Alexander Terenin
cf23517499 Added support for bold italic symbols (#1011)
* added support for \boldsymbol

* added \boldsymbol tests

* added \boldsymbol screenshots

* added \bm, snapshot, updated screenshots

* updated snapshot for \boldsymbol

* properly display \imath and 2 in boldsymbol

* implemented \boldsymbol for +

* fix typo, remove boldsymbolLetters hardcode

* make comment about using Main-Bold more general

* fixed trailing space CI error
2017-12-12 23:09:52 -05:00
Ron Kok
46176c1d69 Support Unicode middle dot (#1015)
* Support Unicode middle dot

This PR adds support for Unicode characters U+00B7 MIDDLE DOT and U+22C5 DOT OPERATOR.

* Use escapes for tests. Edit macro comment.
2017-12-10 16:16:45 -05:00
Erik Demaine
7036eb85cd \kern fixes, \hskip support, \TeX, \LaTeX, \KaTeX (#974)
* Refactor \kern, proper \mkern support, add \hskip

* 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.)

* Render \kern etc. using MathML <mspace>

* Implement \TeX macro

* Implement \LaTeX

* New KaTeX logo \katex

* Rename hskip.js -> kern.js

* Tweak katex \kern to 0.16em

* \katex kern -.17em

* Compute A raise height in \LaTeX and \katex

* Switch mu unit errors to warnings

* LaTeX screenshot test

* Replace \KaTeX with macro definition

* Update screenshots with \KaTeX in them

* Fix font selection for \*TeX macros
2017-11-27 14:40:38 -05:00
Ron Kok
0bde52f04f Support Unicode \mid (#993)
Map ∣, U+2223, to `\mid`
2017-11-26 18:32:01 -05:00
Ron Kok
dc0c3970c2 Support Unicode ∴ and ∵ (#991)
* Support Unicode ∴ and ∵

* Add comments
2017-11-25 20:00:58 -05:00
Erik Demaine
c103693dce "use strict" in ss_data.js (#986) 2017-11-25 18:14:53 -05:00
Erik Demaine
e93668c666 \hspace*, \@ifstar, \@ifnextchar, \@firstoftwo (#975)
* \hspace*, \@ifstar, \@ifnextchar, \@firstoftwo

* Support both \hspace and \hspace* (still aliasing to \kern)
  using new \@ifstar
* \@ifstar is a macro using new \@ifnextchar and \@firstoftwo
  (same definition as LaTeX)
* \@firstoftwo and \@ifnextchar use available MacroParser features
  to act as they do in LaTeX.
* Also new method pushTokens (which I almost used but didn't end up),
  and moved pushToken next to it and popToken.

* Fix flow errors; generalize MacroDefinition

* Add tests for macros
2017-11-24 14:48:04 -05:00
Ron Kok
a02859033a Support Unicode Symbols (#950)
* Support Unicode Symbols

This is the third in a series of PRs to give KaTeX the ability to recognize Unicode character input. This one supports some but not all letter-like symbols and some other symbols. All the characters in this PR will produce `textord` atoms in `math` mode.

The list is not comprehensive. It’s a bit eclectic. Some of these characters are important. Others were just easy to include. A few important characters are omitted because it wasn’t clear to me which is the best way to implement them. I’ll address those characters in future PRs.

* Add comments. Remove RegEx.

* Fix omitted parens
2017-11-24 14:19:22 -05:00
Erik Demaine
ecad4de4ce Single-character macros like active characters (#973)
* Single-character macros like active characters

* Rewrite README according to @kevinbarabash's comment
2017-11-24 13:40:23 -05:00
Ron Kok
b2698d35ec Change frac-line from border to full span (#976)
* Change frac-line from border to full span

Change `frac-line`  and `vertical-separator`.  Instead of using span borders, fill entire span using a `box-shadow`.

This change will enable more dependable engagement of the `min-height` CSS.

* Fix indentation

* Fix indent again

* Change box shadow to inline SVG

* Fix lint error

* regenerate screenshots after switching to SVG for fraction bars
2017-11-24 11:41:53 -05:00
Hiromi Ishii
fd82c4fad0 Implemented `\href' command (#923)
* Implements `\href' command.

* Added `functions/href.js`.
* Added `domTree.anchor` and `buildCommon.makeAnchor` functions.
* Make `buildHTML.getTypeOfDomTree` exported.

* Reflects the code reviews

* Create new argType "url" to treat link string in math appropriately
* Stop using too shorten variable names
* Start using template strings

* Adopts template literal

* Elaborates on glueing

* If-clause restructuring

* Solved confusing explanation

* Allow balanced braces in url

* Adds unit-test for \href

* Adds snapshot tests
2017-11-23 23:23:35 -05:00
Ron Kok
75af19c5bb Change \undertilde to \utilde (#948)
* Change \undeertilde to \utilde

In PR #670, I made an error. The function that should have been `\utilde` I named instead `\undertilde`.

There is an `\undertilde` from the `wsuipa` package, but it is a text-mode non-stretchy function. The proper command name is `\utilde`, a math-mode, stretchy function from packge `undertilde`.

This PR fixes my error.

* Fix screenshotter test
2017-11-23 23:16:37 -05:00
Ron Kok
69aff05024 Support Unicode Big Operators (#961)
* Support Unicode Big Operators

This is the sixth in a series of PRs to give KaTeX the ability to recognize Unicode character input.

This is the final PR in this series that will submit characters in bulk. After this, there come some characters whose alias or atom type was not obvious. I'll turn in PRs for them, too, but only after they are vetted.

* Move constants outside of main functions

* Replace ∫ with \u222b

* Add backslash
2017-11-22 20:48:33 -05:00
Ron Kok
1f8a4f0490 Support Unicode Arrows (#947)
* Support Unicode Arrows

This is the second in a series of PRs to give KaTeX the ability to recognize Unicode character input.

All the characters in this PR will produce `rel` atoms.
2017-11-22 10:11:29 -05:00
Ron Kok
6325685a9f Support Unicode Negated Relations (#952)
* Support Unicode Negated Relations

This is the fifth in a series of PRs to give KaTeX the ability to recognize Unicode character input.

All the characters in this PR will produce `rel` atoms.

* Add parse tests

* Fix AMS functions

Fix a brain cramp.

* Add internal aliases to code comments
2017-11-22 08:37:53 -05:00
Ron Kok
22dd4f3a28 Append ApplyFunction to math functions (#960)
* Append ApplyFunction to math functions

As described at: https://www.w3.org/TR/REC-MathML/chap3_2.html#sec3.2.4

Character U+2061 is the same as &ApplyFunction;. Ref: https://www.w3schools.com/charsets/ref_html_entities_a.asp

* Add comment for \u2061
2017-11-22 08:21:56 -05:00
Hiromi Ishii
6f1661f7da Implements \mathchoice command (#969)
This PR implements `\mathchoice` function.
I once created PR on the wrong branch. Sorry for the mess.

This is particularly useful when one defines custom macro for "big operators".
For example:

```latex
\newcommand{\infdisj}{%
  \mathop{%
    \mathchoice{% display
      \bigvee\hspace{-2ex}\bigvee%
    }{          % inline
      \bigvee\hspace{-1.75ex}\bigvee%
    }{          % script
      \bigvee\hspace{-1.4ex}\bigvee%
    }{          % scriptscript
      \bigvee\hspace{-1ex}\bigvee%
}}}
```
2017-11-22 07:34:05 -05:00
Ron Kok
2d32263998 Support Unicode Binary Operators (#951)
This is the fourth in a series of PRs to give KaTeX the ability to recognize Unicode character input.

All the characters in this PR will produce `bin` atoms.
2017-11-21 12:20:56 -05:00
Ron Kok
839f872faa Fix linefeed test (#964)
I must have been asleep when I wrote the tests for PR#949.
2017-11-12 20:34:22 -05:00
Hiromi Ishii
1a640a465e Implements the alignedat environment for flexible math spacing (#930)
* Implements the alignat environment for flexible math spacing

* Renames alignat[*] to alignedat and factors out duplicate code of aligned and alignedat as alignedHandler

* Adds aligned at to screenshotter

* alignedat screenshots

* Implements the alignat environment for flexible math spacing

* Renames alignat[*] to alignedat and factors out duplicate code of aligned and alignedat as alignedHandler

* Adds aligned at to screenshotter

* alignedat screenshots

* fix style nit

* fix lint
2017-11-11 20:36:09 -05:00
Ron Kok
3e344535ff Fix #946 (#949)
* Fix #946

Issue #946 identified a case in which `array.js` ate the final row of a well-written `aligned` environment.

This PR modifies code from PR #479 to fix this problem and to also continue to eat a trailing `\\` submitted to any environment.

* Fix bug and add tests

* Add final newline to test.

Doh!
2017-11-11 19:12:13 -05:00
Hiromi Ishii
25db6095a1 Fixes #941 (#942) 2017-10-17 15:11:18 -04:00
Ron Kok
bd4e1464a0 Support Unicode relations (#933)
* Support Unicode relations

This is the first in a series of PRs to give KaTeX the ability to recognize Unicode character input. The code in this PR follows the style of PR #410.
All the characters in this PR will produce rel atoms. I’ll submit PRs for other atom types later.

* Fix lint error.

* Correct mapping errors

This commit fixes a brain cramp of mine.
2017-10-17 09:06:41 -04:00
Erik Demaine
3280652bd6 Fix space handling (#912)
Fixes several issues with space handling: (fix #910)
1. "Control symbols" (as they're called in the TeXbook), such as `\\`, should
   not have spaces eaten after them (only "control words" such as `\foo`).
2. In math mode, spaces should be consumed at the parser level, not the
   gullet level.  This enables `\\ [x]` to parse differently from `\\[x]`
3. Eat spaces between arguments, so `\frac x y` still works.
   (This used to work only because math mode ate all spaces.
    The analog in text mode wouldn't have worked.)

Also eat spaces in initial arguments in math mode, and before ^ and _ in atoms.
2017-10-10 10:09:37 -04:00