justinvh / Markdown-LaTeX

This Markdown extension adds inline LaTeX support without the need for external images.
Other
127 stars 15 forks source link

LaTeX parsing issues with current regular expressions #5

Closed rkiyanchuk closed 12 years ago

rkiyanchuk commented 12 years ago

Currently the placeholders used for marking latex code are too simple and often appear in other places besides LaTeX syntax (source code, currency, etc). That causes problems especially in combination with some other extensions. Though I do realize that it is quite complex to consider all possible cases in the regexp so I would suggest switch to some different LaTeX syntax placeholders.

Currently for my personal use I switched those to \%TEXT\%, \$MATH\$ and \%%PREAMBLE\%% respectively. Though I'm open for the discussion if there is a better solution. If my suggestion looks fine to you, I'll be happy to make a pull request (however the fix is trivial in this case).

justinvh commented 12 years ago

It's definitely worthwhile to experiment with it and look at the results; do you have changes that I can look at?

rkiyanchuk commented 12 years ago

For now I've just added backslashes to all placeholders and it works for now.


# %TEXT% mode which is the default LaTeX mode.
TEX_MODE = re.compile(r'(?=(?<!\\)\\\%).(.+?)(?<!\\)\\\%',
        re.MULTILINE | re.DOTALL)

# $MATH$ mode which is the typical LaTeX math mode.
MATH_MODE = re.compile(r'(?=(?<!\\)\\\$).(.+?)(?<!\\)\\\$',
        re.MULTILINE | re.DOTALL)

# %%PREAMBLE%% text that modifys the LaTeX preamble for the document
PREAMBLE_MODE = re.compile(r'(?=(?<!\\)\\\%\%).(.+?)(?<!\\)\\\%\%',
        re.MULTILINE | re.DOTALL)

But unfortunately the method used in markdown-latex does not exactly suit my needs­ — I can't change the background of the generated image, besides the inline math brakes the text flaw. So the result desn't look good. The best rendering I've seen is done by MathJax, but I can't find the way to use MathJax for page pre-rendering. Having static blog that is rendered by MathJax every time the page is loaded to process the math is foolish.

So I'm still in process of searching for a good math displaying tool for markdown.

justinvh commented 12 years ago

You can change the background of the generated images in the preamble. Just use the \pagecolor{declared-color} in the preamble.

justinvh commented 12 years ago

Output images now default to transparent backgrounds. You can run the tests. I have tested this under dvipng 1.14.