Notes/README.md

181 lines
5.3 KiB
Markdown
Raw Normal View History

2019-09-17 20:42:36 +03:00
# CKEditor 5 mathematical feature
2019-10-01 18:18:13 +03:00
This is the best* TeX-based mathematical plugin for CKEditor 5. You can use it to insert, edit and view mathematical equation and formulas. This plugin supports MathJax, KaTeX and custom typesetting engines.
2019-09-17 21:06:18 +03:00
2019-10-03 18:36:34 +03:00
## Table of contents
- [Features](#features)
- [Screenshots](#screenshots)
- [Examples](#examples)
- [Installation](#installation)
2019-10-03 21:21:00 +03:00
* [Styles for Lark theme](#styles-for-lark-theme)
2019-10-03 18:39:46 +03:00
- [Configuration & Usage](#configuration--usage)
2019-10-03 21:21:00 +03:00
* [Plugin options](#plugin-options)
* [Available typesetting engines](#available-typesetting-engines)
* [Supported input and output formats](#supported-input-and-output-formats)
2019-10-03 18:36:34 +03:00
- [Paste support](#paste-support)
2019-10-03 21:21:00 +03:00
* [From plain text](#from-plain-text)
* [From Microsoft Word](#from-microsoft-word)
2019-10-03 18:36:34 +03:00
- [Preview workaround](#preview-workaround)
- [Todo](#todo)
## Features
- TeX syntax
- Inline and display equations
- Preview view
- Multiple typesetting engines
- Have multiple input and output format
- Paste support
2019-10-03 21:21:00 +03:00
- from plain text
- from Microsoft Word
2019-10-03 18:36:34 +03:00
## Screenshots
![Screenshot 1](/screenshots/1.png?raw=true "Screenshot 1")
![Screenshot 2](/screenshots/2.png?raw=true "Screenshot 2")
2019-10-01 18:18:13 +03:00
## Examples
[Link to examples repository](https://github.com/isaul32/ckeditor5-math-examples)
2019-09-17 21:06:18 +03:00
## Installation
2019-10-03 18:36:34 +03:00
Use official classic or inline build as a base:
- [CKEditor 5 classic editor build](https://github.com/ckeditor/ckeditor5-build-classic)
- [CKEditor 5 inline editor build](https://github.com/ckeditor/ckeditor5-build-inline)
2019-09-17 21:06:18 +03:00
Install plugin with NPM or Yarn
2019-09-17 21:09:08 +03:00
2019-09-17 21:06:18 +03:00
`npm install ckeditor5-math --save-dev`
Add import into ckeditor.js file
```js
import Mathematics from 'ckeditor5-math/src/math';
```
2019-10-03 18:51:24 +03:00
Add it to built-in plugins
2019-09-17 21:06:18 +03:00
```js
InlineEditor.builtinPlugins = [
// ...
Mathematics
2019-09-17 21:06:18 +03:00
];
```
2019-10-03 18:51:24 +03:00
__Add math button to toolbar__
2019-09-17 21:06:18 +03:00
```js
InlineEditor.defaultConfig = {
toolbar: {
items: [
// ...
'math'
2019-09-17 21:06:18 +03:00
]
}
2019-09-17 21:06:18 +03:00
};
```
2019-10-03 18:36:34 +03:00
### Styles for Lark theme
2019-10-03 18:51:24 +03:00
__Copy theme/ckeditor5-math folder__ from [https://github.com/isaul32/ckeditor5-theme-lark](https://github.com/isaul32/ckeditor5-theme-lark) to your lark theme repository or install
2019-10-03 18:36:34 +03:00
2019-10-01 18:58:18 +03:00
`npm install @ckeditor/ckeditor5-theme-lark@https://github.com/isaul32/ckeditor5-theme-lark --save-dev`
2019-08-31 20:48:37 +03:00
2019-10-03 18:36:34 +03:00
Styles requires PostCSS like official CKEditor 5 plugins.
2019-09-17 21:12:20 +03:00
## Configuration & Usage
2019-09-17 20:42:36 +03:00
2019-10-03 03:44:28 +03:00
### Plugin options
```js
InlineEditor.defaultConfig = {
2019-10-03 21:21:00 +03:00
// ...
math: {
engine: 'mathjax', // or katex or function (equation, element, display) => { ... }
outputType: 'script', // or span or math
2019-10-03 03:44:28 +03:00
forceOutputType: false, // forces output to use outputType
enablePreview: true // Enable preview view
2019-10-03 21:21:00 +03:00
}
2019-10-03 03:44:28 +03:00
}
```
### Available typesetting engines
__MathJax__
2019-10-03 18:51:24 +03:00
- Tested by using __latest 2.7__
- Has experimental (__CHTML__, __SVG__) support for __3.0.0__ or newer version
- Use only __\\( \\)__ delimiters for inline and __\\[ \\]__ delimiters for display
2019-10-03 18:36:34 +03:00
[<img src="https://www.mathjax.org/badge/badge-square.svg" width="130" alt="KaTeX">](https://www.mathjax.org/)
__KaTeX__
2019-09-17 20:42:36 +03:00
- Tested by using version __0.11.0__
2019-10-03 18:36:34 +03:00
[<img src="https://katex.org/img/katex-logo-black.svg" width="130" alt="KaTeX">](https://katex.org/)
__Custom typesetting__
It's possible to implement with engine config. For example, this feature can be used when use back end rendering.
```js
InlineEditor.defaultConfig = {
// ...
math: {
2019-10-03 12:43:58 +03:00
engine: (equation, element, display, preview) => {
// ...
}
}
}
```
2019-10-01 18:18:13 +03:00
- __equation__ is equation in TeX format without delimiters.
- __element__ is DOM element reserved for rendering.
- __display__ is boolean. Typesetting should be inline when false.
2019-10-03 18:51:24 +03:00
- __preview__ is boolean. Rendering in preview when true.
2019-09-17 20:42:36 +03:00
2019-08-31 20:48:37 +03:00
### Supported input and output formats
Supported input and output formats are:
```html
<!-- MathJax style http://docs.mathjax.org/en/v2.7-latest/advanced/model.html#how-mathematics-is-stored-in-the-page -->
<script type="math/tex">\sqrt{\frac{a}{b}}</script>
<script type="math/tex; mode=display">\sqrt{\frac{a}{b}}</script>
<!-- CKEditor 4 style https://ckeditor.com/docs/ckeditor4/latest/features/mathjax.html -->
<span class="math-tex">\( \sqrt{\frac{a}{b}} \)</span>
<span class="math-tex">\[ \sqrt{\frac{a}{b}} \]</span>
```
2019-10-01 18:18:13 +03:00
### Paste support
2019-10-03 18:36:34 +03:00
#### From plain text
Paste TeX equations with __delimiters__. For example:
2019-10-03 18:51:24 +03:00
2019-10-01 18:18:13 +03:00
__\\[__ x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} __\\]__
2019-10-03 18:51:24 +03:00
2019-10-01 18:18:13 +03:00
or
2019-10-03 18:51:24 +03:00
2019-10-01 18:18:13 +03:00
__\\(__ x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} __\\)__
2019-10-03 18:36:34 +03:00
#### From Microsoft Word
2019-10-03 18:51:24 +03:00
Use [__paste from office__](https://github.com/isaul32/ckeditor5-paste-from-office) fork instead of official. This feature is __experimental__ and might not work always (look source codes).
2019-10-01 18:18:13 +03:00
Install paste from office fork
2019-10-03 18:36:34 +03:00
2019-10-01 18:18:13 +03:00
`npm install @ckeditor/ckeditor5-paste-from-office@github:isaul32/ckeditor5-paste-from-office --save-dev`
```js
import PasteFromOffice from '@ckeditor/ckeditor5-paste-from-office/src/pastefromoffice';
import Mathematics from 'ckeditor5-math/src/math';
// ...
InlineEditor.builtinPlugins = [
// ...
PasteFromOffice,
Mathematics
];
```
2019-09-17 21:12:20 +03:00
2019-10-03 18:36:34 +03:00
## Preview workaround
__.ck-reset_all *__ css rules from ckeditor5-ui and ckeditor5-theme-lark break rendering in preview mode.
My solution for this is use rendering element outside of CKEditor DOM and place it right place by using absolute position. Alternative solution could be using iframe, but then we have to copy typesetting engine's scripts and styles to child document.
2019-09-17 21:06:18 +03:00
## Todo
2019-09-28 13:02:32 +03:00
- MathML input and output when using MathJax version 3
2019-09-28 19:21:38 +03:00
- Make tests
2019-10-01 18:18:13 +03:00
2019-10-03 18:36:34 +03:00
[*] at least in my opinion 😄