Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allowing inline LaTeX - that is, a $...$ string within a line

  • Loading branch information...
commit d37cacd2403a677afabadc08532338ca872c1b96 1 parent 6ca8952
@AlexNisnevich AlexNisnevich authored
Showing with 18 additions and 5 deletions.
  1. +10 −4 MarkdownPP/Modules/LaTeXRender.py
  2. +5 −1 readme.md
  3. +3 −0  readme.mdpp
View
14 MarkdownPP/Modules/LaTeXRender.py
@@ -7,8 +7,9 @@
from MarkdownPP.Module import Module
from MarkdownPP.Transform import Transform
-singlelinere = re.compile("^\$(\$?)..*\$(\$?)$") # $...$ (or $$...$$)
+singlelinere = re.compile("\$(\$?)..*\$(\$?)") # $...$ (or $$...$$)
startorendre = re.compile("^\$(\$?)|^\S.*\$(\$?)$") # $... or ...$ (or $$... or ...$$)
+codere = re.compile("^( |\t)")
fencedcodere = re.compile("^```\w*$")
class LaTeXRender(Module):
@@ -21,6 +22,7 @@ def render(self, formula):
formula = formula.replace("$", "")
encoded_formula = formula.replace("%","[comment]").replace("+","%2B")
display_formula = formula.replace("\n","")
+ print 'Rendering: %s ...' % display_formula
params = urllib.urlencode({'engine': 'quicklatex', 'input': encoded_formula})
headers = {"Content-type": "application/x-www-form-urlencoded",
@@ -49,15 +51,19 @@ def transform(self, data):
in_fenced_code_block = False
else:
in_fenced_code_block = True
-
- if not in_fenced_code_block:
+
+ is_code_block = codere.search(line)
+ if not in_fenced_code_block and not is_code_block:
if in_block:
transforms.append(Transform(linenum, "drop"))
current_block += "\n" + line
match = singlelinere.search(line)
if match:
- transforms.append(Transform(linenum, "swap", self.render(line)))
+ tex = match.group(0)
+ before_tex = line[0:line.find(tex)]
+ after_tex = line[(line.find(tex) + len(tex)) : len(line)]
+ transforms.append(Transform(linenum, "swap", before_tex + self.render(tex) + after_tex))
else:
match = startorendre.search(line)
if match:
View
6 readme.md
@@ -108,13 +108,17 @@ the document to be included in the list.
### 2.4\. LaTeX Rendering
+Lines and blocks of lines beginning and ending with $ are rendered as LaTeX,
+using [QuickLaTeX](http://www.holoborodko.com/pavel/quicklatex/).
+
For example,
$\displaystyle \int x^2 = \frac{x^3}{3} + C$
becomes
-![\displaystyle \int x^2 = \frac{x^3}{3} + C](http://quicklatex.com/cache3/ql_fdd0c74719ed21c7bfec724eceb1ceea_l3.png)
+![\displaystyle \int x^2 = \frac{x^3}{3} + C](http://quicklatex.com/cache3/ql_0fa1a137ae5e89171b4ecb24ce76998f_l3.png)
+
<a name="examples"></a>
View
3  readme.mdpp
@@ -88,6 +88,9 @@ the document to be included in the list.
### LaTeX Rendering
+Lines and blocks of lines beginning and ending with $ are rendered as LaTeX,
+using [QuickLaTeX](http://www.holoborodko.com/pavel/quicklatex/).
+
For example,
$\displaystyle \int x^2 = \frac{x^3}{3} + C$
Please sign in to comment.
Something went wrong with that request. Please try again.