1

I am django newbie and working on a math based project. I need to save texts involving mathematical symbols like integral, sigma, product etc. At the same time, I also need to emphasize or bold some texts (and do all kinds of rich text editing) and include figures that explains a mathematical concept.

At present, I am just saving all the fields in a CharField (with dummy texts and without including any mathematical symbol) and have no idea how to include such a field. If you have any idea/hint or you have worked on similar projects, please help.

inquilabee
  • 713
  • 1
  • 11
  • 23
  • Trying to do math typesetting with Unicode (which you seem to be trying to do) is an exercise in frustration which leads to poor results. It would be better to find a way to embed LaTex into your page. See this: https://stackoverflow.com/q/116054/4996248 – John Coleman Jan 18 '18 at 12:21
  • @John, thank you. You provided me an idea where I should have started with. Starting with the same idea, I found a library called 'Django Markdownx' which allows writing in markdown syntax and converting the same into html. I then integrated 'python-markdown-math' based on MathJax in the same app to write and fetch texts written in markdown and having maths symbols in them. – inquilabee Jan 19 '18 at 18:27
  • @Inquilabi, Can you please help me with the same? I am stuck. Thank you, – Dhaval Savalia Jun 17 '18 at 10:40
  • 1
    @Dhaval, Sure, I will. – inquilabee Jun 17 '18 at 10:58
  • 1
    @Inquilabi are you on Discord? if yes, add me @dhaval#5782 Thank you – Dhaval Savalia Jun 17 '18 at 11:35

1 Answers1

4

The most obvious way to do that in Django is indeed to use a CharField and use it to store some LaTeX fragments like:

x=\frac{-b+\sqrt{b^2-4ac}}{2a}

which represents the following expression:enter image description here

LaTeX can also be used to style your texts very easily. You can integrate a free editor for typing expressions of this kind like mathquill if you plan to store long fragments, use a Django TextField. LaTeX expressions can also be beautifully rendered by Mathjax or KaTeX Edit: You can also use math.stackexchange.com editor: stackedit. It's opensource and you find it there: github.com/benweet/stackedit. It uses KaTeX to render LaTeX math expressions.

Gerard Rozsavolgyi
  • 4,834
  • 4
  • 32
  • 39
  • Thank you. Actually I wanted to have a http://math.stackexchange.com/ like editor which can help me write both texts and math related stuffs at the same time. I have implemented a ''Django Markdownx' plus 'python-markdown-math' (based on MathJax) solution seems to be working fine (with a few issues). – inquilabee Jan 19 '18 at 18:33
  • the editor for math.stackexchange.com is https://stackedit.io/. It's also opensource and you find it there: https://github.com/benweet/stackedit. it uses KaTeX under the hood. – Gerard Rozsavolgyi Jan 19 '18 at 19:34