Skip to content

Commit 0b6c133

Browse files
committed
Update README
1 parent 944fa13 commit 0b6c133

File tree

1 file changed

+74
-31
lines changed

1 file changed

+74
-31
lines changed

README.md

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,15 @@
1313
- [Discussions](https://github.com/wagtail-nest/wagtail-polymath/discussions)
1414
- [Security](https://github.com/wagtail-nest/wagtail-polymath/security)
1515

16-
wagtail-polymath allows you to write equations in your
17-
[Wagtail](https://github.com/wagtail/wagtail) content using markup and
18-
render them beautifully.
16+
`wagtail-polymath` provides robust math typesetting capabilities in LaTeX syntax.
17+
This project supports multiple typesetting engines, including MathJax and KaTeX, allowing users to choose the one that best fits their needs.
1918

20-
wagtail-polymath provides a `MathBlock` so you can write equations in markup
21-
(TeX, MathML, ASCIIMath) and render them with MathJax. It features a
22-
live preview:
19+
- [LaTeX Syntax Support](https://en.wikibooks.org/wiki/LaTeX/Mathematics): Write complex mathematical expressions using familiar LaTeX syntax.
20+
- Multiple Typesetting Engines: Currently, [MathJax](https://www.mathjax.org/) (default) and [KaTeX](https://katex.org/) are supported.
21+
- Live preview.
2322

2423
![](https://github.com/wagtail-nest/wagtail-polymath/blob/main/docs/images/mathblock.png)
2524

26-
`MathBlock` uses MathJax for rendering so there is very little to do on
27-
the front end. Simply include the MathJax JS and render the raw
28-
`MathBlock` content as you would for any other streamfield plain text
29-
block.
30-
31-
wagtail-polymath even includes a template tag to include the MathJax JS for
32-
you from a CDN. By default, MathJax is configured to accept all
33-
recognised markup (TeX, MathML, ASCIIMath) and renders them to HTML. To
34-
change the configuration, you can pass the desired config command to the
35-
templatetag. See the [MathJax documentation](https://docs.mathjax.org/en/v2.7-latest/config-files.html#combined-configurations)
36-
for possible configurations.
37-
38-
For help on using the markup languages see the relevant MathJax
39-
documentation (e.g. https://docs.mathjax.org/en/v2.7-latest/tex.html) and
40-
the markup language-specific documentation (e.g. https://en.wikibooks.org/wiki/LaTeX)
41-
4225
## Quickstart
4326

4427
Install wagtail-polymath:
@@ -63,23 +46,83 @@ Use `MathBlock` in your `StreamField` content:
6346
from wagtail_polymath.blocks import MathBlock
6447

6548
class MyPage(Page):
66-
body = StreamField([
67-
('heading', blocks.CharBlock(classname="full title")),
68-
('paragraph', blocks.RichTextBlock()),
69-
('equation', MathBlock())
70-
])
49+
body = StreamField(
50+
[
51+
('heading', blocks.CharBlock(classname="full title")),
52+
('paragraph', blocks.RichTextBlock()),
53+
('equation', MathBlock())
54+
],
55+
use_json_field=True,
56+
)
57+
58+
content_panels = Page.content_panels + [FieldPanel("body")]
7159
```
7260

73-
Use the `mathjax` template tag in your front end template to load the
74-
MathJax library:
61+
Use the `polymath_js` template tag in your front-end template to load the typesetting library:
7562

7663
```django+html
7764
{% load wagtail_polymath %}
78-
...
7965
80-
<script src="{% mathjax %}"></script>
66+
{# include this line in css block #}
67+
{% polymath_css %}
68+
69+
{# include this line in js block #}
70+
{% polymath_js %}
71+
```
72+
73+
Now you can use LaTeX syntax in your StreamField editor to create mathematical expressions.
74+
By default, `wagtail-polymath` uses MathJax for rendering, but KaTeX is also supported (see below).
75+
76+
## Settings
77+
78+
### WAGTAILPOLYMATH_ENGINE
79+
80+
If you wants to use KaTeX instead of MathJax, simply add the following line to your Django settings:
81+
82+
```python
83+
WAGTAILPOLYMATH_ENGINE = "katex"
84+
```
85+
86+
This value is set to "mathjax" by default.
87+
88+
### WAGTAILPOLYMATH_SETTINGS
89+
90+
For those who want to specify the CDN provider or for internal site hosting.
91+
The rendering javascript library path can be customized for different use cases.
92+
93+
Default settings for `MathJax`:
94+
95+
```python
96+
WAGTAILPOLYMATH_SETTINGS = {
97+
"js": [
98+
"https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-MML-AM_CHTML",
99+
],
100+
}
101+
```
102+
103+
Default settings for `KaTeX`:
104+
105+
```python
106+
WAGTAILPOLYMATH_SETTINGS = {
107+
"js": [
108+
"https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js",
109+
"https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js",
110+
],
111+
"css": ["https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css"],
112+
}
81113
```
82114

115+
## Migration from `wagtail-math`
116+
117+
- Django settings:
118+
- Replace "wagtailmath" with "wagtail_polymath" in `INSTALLED_APPS`
119+
- Import section:
120+
- Replace "from wagtailmath.blocks import MathBlock" with "from wagtail_polymath.blocks import MathBlock"
121+
- HTML template:
122+
- Replace "wagtailmath" with "wagtail_polymath" in the load section
123+
- Add "{% polymath_css %}" to the css block
124+
- Replace "<script src={% mathjax %}></script>" with "{% polymath_js %}" in the js block
125+
83126
## Contributing
84127

85128
All contributions are welcome! See [CONTRIBUTING.md](https://github.com/wagtail-nest/wagtail-polymath/blob/main/CONTRIBUTING.md)

0 commit comments

Comments
 (0)