Coder Social home page Coder Social logo

wagtail-nest / wagtail-polymath Goto Github PK

View Code? Open in Web Editor NEW
35.0 11.0 14.0 136 KB

Beautiful equations in your StreamField content.

License: MIT License

Makefile 15.08% Python 48.30% JavaScript 25.43% HTML 11.19%
wagtail django python cms django-application wagtail-cms mathjax

wagtail-polymath's Introduction

WagtailMath

WagtailMath allows you to write equations in your Wagtail content using markup and render them beautifully.

WagtailMath provides a MathBlock so you can write equations in markup (TeX, MathML, ASCIIMath) and render them with MathJax. It features a live preview:

MathBlock in the Wagtail admin

MathBlock uses MathJax for rendering so there is very little to do on the front end. Simply include the MathJax JS and render the raw MathBlock content as you would for any other streamfield plain text block.

WagtailMath even includes a template tag to include the MathJax JS for you from a CDN. By default, MathJax is configured to accept all recognised markup (TeX, MathML, ASCIIMath) and renders them to HTML. To change the configuration, you can pass the desired config command to the templatetag. See http://docs.mathjax.org/en/latest/config-files.html#combined-configurations for possible configurations.

For help on using the markup languages see the relevant MathJax documentation (e.g. http://docs.mathjax.org/en/latest/tex.html) and the markup language-specific documentation (e.g. https://en.wikibooks.org/wiki/LaTeX)

Quickstart

Install wagtailmath:

pip install wagtailmath

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'wagtailmath',
    ...
)

Use MathBlock in your StreamField content:

from wagtailmath.blocks import MathBlock

class MyPage(Page):
    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('equation', MathBlock())
    ])

Use the mathjax template tag in your front end template to load the MathJax library:

{% load wagtailmath %}
...

<script src="{% mathjax %}"></script>

wagtail-polymath's People

Contributors

jamesramm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wagtail-polymath's Issues

Detailed Documentation

Hi!

This is a well-developed tool, yet it is lacking good documentation, a bit more detailed documentation might have helped people better. (plus it will be a better representation)

Discussion: Join Wagtail Nest / merge with Wagtail Katex

Hi. I'm not sure if this is something that would be worth discussing but would there be interest for this package to move to Wagtail Nest. I'm on the Wagtail core team and see that this kind of package looks useful to the community and may need a bit more community support to keep updated.

Additionally, there is a similar package Wagtail Katex that maybe could be merged together when bringing into the Nest group.

There may even be a desire to support multiple 'text to diagram' engines like Mermaid / Pintora under one package banner.

Let me know if you would be interested. The Wagtail Nest documentation explains what this would mean.

https://github.com/wagtail-nest

MathJax streamblock widget initially works, then doesn't

Hey there, great work on this plugin! It worked great as I edited and published my first test post using equations and the MathJax streamblock widget.

Unfortunately, after I saved a draft of the page for the first time, I went back to edit the test page (add another MathJax widget instance) and observed the following symptoms:

  • Live preview window in the existing MathJax widget instance non-responsive
  • Live preview window in the new MathJax widget non-responsive
  • An extra / phantom stream field appears below the new MathJax widget. It has no content, just shows up as black when moused over, background color otherwise
  • Delete and up/down arrows in the MathJax streamblock widget do nothing (on the newly created widget instance) and work normally (on the old widget instance)
  • Saving the page in this state (draft or publish) results in the error below
  • Waiting some length of time (on the order of 10s of minutes) resolves the problem temporarily
  • MathJax expressions still render properly on the live pages when I introduce it as RawHTML streamblock content (so I don't think it's a browser issue with MathJax)

The problem is not universal to all cases with multiple MathJax widgets on one page. I had live previews of two MathJax widgets working at the same time on one occasion.

I think the problem may be related to the GUI changes introduced in wagtail 1.12 but I could easily be wrong about that.

Stack trace:
invalid literal for int() with base 10: ''

Traceback:

File "/opt/bitnami/apps/django/lib/python2.7/site-packages/Django-1.11.4-py2.7.egg/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/opt/bitnami/apps/django/lib/python2.7/site-packages/Django-1.11.4-py2.7.egg/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/opt/bitnami/apps/django/lib/python2.7/site-packages/Django-1.11.4-py2.7.egg/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/opt/bitnami/apps/django/lib/python2.7/site-packages/Django-1.11.4-py2.7.egg/django/views/decorators/cache.py" in _cache_controlled
  43.             response = viewfunc(request, *args, **kw)

File "/opt/bitnami/python/lib/python2.7/site-packages/wagtail/wagtailadmin/decorators.py" in decorated_view
  31.             return view_func(request, *args, **kwargs)

File "/opt/bitnami/python/lib/python2.7/site-packages/wagtail/wagtailadmin/views/pages.py" in edit
  321.         if form.is_valid() and not page.locked:

File "/opt/bitnami/python/lib/python2.7/site-packages/modelcluster/forms.py" in is_valid
  259.         form_is_valid = super(ClusterForm, self).is_valid()

File "/opt/bitnami/apps/django/lib/python2.7/site-packages/Django-1.11.4-py2.7.egg/django/forms/forms.py" in is_valid
  183.         return self.is_bound and not self.errors

File "/opt/bitnami/apps/django/lib/python2.7/site-packages/Django-1.11.4-py2.7.egg/django/forms/forms.py" in errors
  175.             self.full_clean()

File "/opt/bitnami/apps/django/lib/python2.7/site-packages/Django-1.11.4-py2.7.egg/django/forms/forms.py" in full_clean
  384.         self._clean_fields()

File "/opt/bitnami/apps/django/lib/python2.7/site-packages/Django-1.11.4-py2.7.egg/django/forms/forms.py" in _clean_fields
  396.                 value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))

File "/opt/bitnami/python/lib/python2.7/site-packages/wagtail/wagtailcore/blocks/base.py" in value_from_datadict
  523.         return self.block_def.value_from_datadict(data, files, name)

File "/opt/bitnami/python/lib/python2.7/site-packages/wagtail/wagtailcore/blocks/stream_block.py" in value_from_datadict
  165.                     int(data['%s-%d-order' % (prefix, i)]),

Exception Type: ValueError at /admin/pages/5/edit/
Exception Value: invalid literal for int() with base 10: ''

Do not work with wagtail 2.13

I am trying to use this package with wagtail 2.13 but it throws following error:

UnpackableTypeError at /admin/pages/6/edit/
don't know how to pack object: <wagtailmath.blocks.MathJaxWidget object at 0x000001B764F265B0>

I couldn't figure out what is the issue here?

Django Template support

Nice library!

I'm getting this error when trying to load an admin page:

"Unused 'is' at end of if expression".

And it points me to this line:

{% for name, value in widget.attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value }}"{% endif %}{% endif %}{% endfor %}

Is this library Jinja-only?

Doesnt work if more than 1 equation used in streamfield

If you and more than 1 equation block in the streamfield, only the first block shows the render preview.

I believe this is because of conflicting ID's. - There needs to be a way of uniquely identifying each input and preview div and initialising them separately with mathjax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.