From 5d3ab5b9642b3cf3ec557ff72fa72ec9e6ab5195 Mon Sep 17 00:00:00 2001 From: Barry Steyn Date: Wed, 19 Feb 2014 08:18:43 -0800 Subject: [PATCH 1/2] Logic for MathMl; Fixed Bug; Updated Readme --- latex/Readme.md | 40 ++++++++++++++++++++++++++--------- latex/latex.py | 56 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 68 insertions(+), 28 deletions(-) diff --git a/latex/Readme.md b/latex/Readme.md index 49888b8..8ee917d 100644 --- a/latex/Readme.md +++ b/latex/Readme.md @@ -1,10 +1,20 @@ Latex Plugin For Pelican ======================== -This plugin allows you to write mathematical equations in your articles using Latex. -It uses the MathJax Latex JavaScript library to render latex that is embedded in -between `$..$` for inline math and `$$..$$` for displayed math. It also allows for -writing equations in by using `\begin{equation}`...`\end{equation}`. +This plugin allows you to write mathematical equations in your articles using Latex and MathMl. +It uses the MathJax Latex JavaScript library to render *Latex* and *MathMl* that is embedded in +your site. + +### Latex +Anything between `$..$` (inline math) and `$$..$$` (displayed math) will be recognized as +Latex. In addition, anything between between `\begin` and `\end` macros will also be +recognized as Latex. For example, `\begin{equation}`...`\end{equation}` would be used to +render math equations with numbering. + +Within recognized Latex as described above, Latex macros can be used. + +### MathMl +Anything between `` and `` tags will be recognized as *MathMl*. Installation ------------ @@ -13,7 +23,7 @@ Then use as follows by adding the following to your settings.py: PLUGINS = ["latex"] -Your site is now capable of rendering latex math using the mathjax JavaScript +Your site is now capable of rendering math math using the mathjax JavaScript library. No alterations to the template file is needed. ### Typogrify @@ -22,15 +32,24 @@ and Latex will be rendered correctly). In order for this to happen, version 2.07 (or above) of typogrify is required. In fact, this plugin expects that at least version 2.07 is present and will fail without it. +### Summaries +Summaries that contain math are processed to ensure that math is not off. If +math is cut off, it will add it back into the summary. + +### Templates +No alteration is needed to a template for this plugin to work. Just install +the plugin and start writing your Math. + Usage ----- ### Backward Compatibility This plugin is backward compatible in the sense that it -accompishes what previous versions did without needing any setup in the -metadata or settings files. +will render previous setups correctly. This is because those +settings and metadata information is ignored by this version. Therefore +you can remove them to neaten up your site ### Settings File -Extra options regarding how mathjax renders latex can be set in the settings +Extra options regarding how mathjax renders math can be set in the settings file. These options are in a dictionary variable called `LATEX` in the pelican settings file. @@ -40,7 +59,8 @@ The dictionary can be set with the following keys: html. For example, setting `wrap` to `'mathjax'` would wrap all math inside `...` tags. If typogrify is set to True, then math needs to be wrapped in tags and `wrap` will therefore default to `mathjax` if not -set. +set. `wrap` cannot be set to `'math'` because this tag is reserved for +mathml notation * `align`: controls how displayed math will be aligned. Can be set to either `left`, `right` or `center` (default is `center`). * `indent`: if `align` not set to `center`, then this controls the indent @@ -51,7 +71,7 @@ level (default is `0em`). loading. * `color`: controls the color of the mathjax rendered font. -For example, in settings.py, the following would make latex render in blue and +For example, in settings.py, the following would make math render in blue and displaymath align to the left: LATEX = {'color':'blue','align':left} diff --git a/latex/latex.py b/latex/latex.py index b1022e0..f0570be 100644 --- a/latex/latex.py +++ b/latex/latex.py @@ -28,11 +28,12 @@ from pelican import contents import re # Global Variables +_TYPOGRIFY = False # used to determine if we should process typogrify _WRAP_TAG = None # the tag to wrap mathjax in (needed to play nicely with typogrify or for template designers) -_LATEX_REGEX = re.compile(r'(\$\$|\$|\\begin\{(.+?)\}).*?\1|\\end\{\2\}', re.DOTALL | re.IGNORECASE) # used to detect latex +_LATEX_REGEX = re.compile(r'(\$\$|\$|\\begin\{(.+?)\}|<(math).*?>).*?(\1|\\end\{\2\}|)', re.DOTALL | re.IGNORECASE) # used to detect latex _LATEX_SUMMARY_REGEX = None # used to match latex in summary _LATEX_PARTIAL_REGEX = None # used to match latex that has been cut off in summary -_MATHJAX_SETTINGS = {} # Settings that can be specified by the user, used to control mathjax script settings +_MATHJAX_SETTINGS = {} # settings that can be specified by the user, used to control mathjax script settings _MATHJAX_SCRIPT="""