markdown2Mathjax

Extend markdown2 for use with mathjax
Download

markdown2Mathjax Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL v3
  • Price:
  • FREE
  • Publisher Name:
  • Matthew Young
  • Publisher web site:
  • https://github.com/constantAmateur/

markdown2Mathjax Tags


markdown2Mathjax Description

markdown2Mathjax is a simple package that allows you to use latex style math generated by MathJax in conjunction with the popular markdown format. There are two implementations of markdown in python, this package is designed to be used with the more widely used and actively maintained of the two, called markdown2. Typical usage is as follows:#!/usr/bin/env pythonfrom markdown2Mathjax import sanitizeInput, reconstructMathfrom markdown2 import markdowntmp = sanitizeInput(sometxt)markdedDownText = markdown(tmp)finalOutput = reconstructMath(markedDownText,tmp)(where "sometxt" is a string containing the markdown+mathjax text.)Installationmarkdown2Mathjax is hosted on pypi, so can be installed either from source, using:tar zxvf markdown2Mathjax-x.x.x.tar.gzcd markdown2Mathjax-x.x.xpython setup.py installor using pip (or easy_install if you'd prefer):pip install markdown2MathjaxUsageBy default, math is marked by single $ signs for inline math and double $$ signs for equations. However, any delimiting strings may be used by changing the keyword arguments to the sanitizeInput and reconstructMath functions. Note that by default mathjax does NOT use single dollars signs to delimit inline math, so if you use the defaults for this package, you will have to instruct mathjax to treat it appropriately.ExplanationThe sanitizeInput function finds any instances of math (as determined by the supplied delimiters) and replaces them with a placeholder. This placeholder can be specified by the user, but it is recommended you use the supplied default of "$0$". The placeholder has to be something that won't be processed by markdown, and won't ever be PRODUCED by markdown. The first of these requirements is easy enough to meet, the second can be somewhat more subtle. If the placeholder already exists in the supplied user text, it is noted by sanitizeInput and will be left alone when reconstruction math after markdown processing.Each time a valid math block is encountered and replaced by a placeholder, the math is saved in a list (called codeblocks) which is then returned by the sanitizeInput function. Each entry in codeblocks is prefixed with either 0 (for a literal occurance of the placeholder in the text), a 1 for inline math or a 2 for a separate equation.The sanitized string from sanitizeInput can then be marked up by markdown without fear of your math being mangled. Finally, reconstructMath replaces each of the placeholders in the marked up text with the appropriate codeblock. This final html can then be displayed with appropriate mathjax javascript headers.Another way to think about this is than reconstructMath is basically the inverse of sanitizeInput. So without using markdown in between, nothing should change between the two (except when reconstructMath also does some extra cleanup of the math codeblocks). That is:tmp=sanitizeInput(test)reconstructMath(tmp,tmp)==testshould always evaluate to true.Product's homepage


markdown2Mathjax Related Software