Giter Club home page Giter Club logo

markdown-latex's Introduction

Markdown-LaTeX

This Markdown extension adds support for inline LaTeX expressions without the need for external images. The available modes are %TEXT%, $MATH$, and %%PREAMBLE%%.

Modes

Markdown-LaTeX can technically allow for any sort of LaTeX expression, but there are three main modes that make writing everything much easier.

%TEXT% mode

The most basic of the modes is %TEXT% mode. Any expression within %TEXT% will be parsed in a basic LaTeX text-mode, e.g. plain. For example, %``Justin Bruce Van Horne''%.

$MATH$ mode

Math mode is our second basic functionality of Markdown-LaTeX. It automatically puts LaTeX into math mode and allows for inline and multiline expressions. Let's say that we wanted to write Euler's formula: We would then write $e^{\imath x} = \cos{x} + \imath\sin{x}$.

%%PREAMBLE%% mode

Preamble mode is the only "complex" mode. It allows you to add to the preamble of the LaTeX template. So, if there are specific packages or commands you want for the HTML page, then this is where to do it. This is a global modifier and will affect the entire document. I haven't come up with an intuitive design for a per-expression basis.

Dependencies

Markdown-LaTeX depends on:

Installation

You can either copy it into the extensions sub-directory in your markdown folder (ex: /usr/lib/python2.7/site-packages/markdown/extensions/latex.py) or use it locally with the mdx_ prefix. See Markdown Extensions for more details.

Usage

markdown -x latex somefile.markdown > somefile.html

Configuration

This plugin uses dvipng in order to produce the output images. The arguments passed to dvipng are configurable, see tests/markdown-latex.cfg for an example. In particular, you may want to adapt the argument passed to the -D option in order to change output resolution resp. font size.

You may also change the delimiters used for text, math and preamble mode within the configuration file, see tests2/markdown-latex.cfg. When running this plugin on existing text you need to escape all occurrences of % and $. Changing delimiters may reduce this effort.


How does it work?

The LaTeX extension will search for either $text$ or %text% expressions. For each expression, it generates a tex file that is parsed by latex and then run through dvipng. The data is encoded via base64 and then inlined. A cache file (latex.cache) is used to store all expressions and their base64 counterparts. This is to prevent latex from being run each time.


Suggestions/Improvements:

markdown-latex's People

Contributors

adi- avatar justinvh avatar shuber2 avatar zeusttu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdown-latex's Issues

render the png as transparent background?

This module rocks! And the solution is so simple (in regard to what user need to do) that at first I didn't get it because I didn't believe this could be my solution. :) How I was wrong!

After playing around with the module for a few days, I do have a question.

I added

  -bg Transparent

to the dvipng cmd options in line 108 where it used to be

   # Extract the image
    cmd = "dvipng -q -bg -T tight -x 1200 -z 9 \
    %s -o %s" % (dvi, png)

hoping to get what I want.

It didn't work.

How to get a math png with transparent background. The current background is white.

I want to do this because the final output is html and white background doesn't play well with some page background.

Thank you!

how to install dependences?

Please tell me how to install the following dependeces?
1.LaTeX
2.dvipng
3.Python Markdown

I did:
1.pip install latex
2.sudo apt-get install dvipng
3.pip install markdown

but it still not work.

LaTeX parsing issues with current regular expressions

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).

how to type aligned equations

\begin{align} 
x + y = z \\
&= y + x 
\end{align}

if I surround the equations with $, then, error msg is: ! Package amsmath Error: \begin{align} allowed only in paragraph mode.

if I surround the equations with $$, then error msg is: ! Package amsmath Error: Erroneous nesting of equation structures;
(amsmath) trying to recover with `aligned'.

vertical alignment

The vertical alignments of the inlined images are not so good, they are a bit above the HTML texts. I propose the following addition:
IMG_EXPR = "<img style='vertical-align:middle;' ...
For other possible values refer to this page.

No Python3 support

Code only works in Python2. I need it to run in Python3 for a Gedit plugin.

Failed compilation of a latex document?

Here's the log file:

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=latex 2011.12.13)  8 JAN 2012 22:16
entering extended mode
 %&-line parsing enabled.
**tmpuBP4Sl
(./tmpuBP4Sl
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo
File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/share/texmf-texlive/tex/latex/amsmath/amsmath.sty
Package: amsmath 2000/07/18 v2.13 AMS math features
\@mathmargin=\skip43

For additional information on amsmath, use the `?' option.
(/usr/share/texmf-texlive/tex/latex/amsmath/amstext.sty
Package: amstext 2000/06/29 v2.01

(/usr/share/texmf-texlive/tex/latex/amsmath/amsgen.sty
File: amsgen.sty 1999/11/30 v2.0
\@emptytoks=\toks14
\ex@=\dimen103
))
(/usr/share/texmf-texlive/tex/latex/amsmath/amsbsy.sty
Package: amsbsy 1999/11/29 v1.2d
\pmbraise@=\dimen104
)
(/usr/share/texmf-texlive/tex/latex/amsmath/amsopn.sty
Package: amsopn 1999/12/14 v2.01 operator names
)
\inf@bad=\count87
LaTeX Info: Redefining \frac on input line 211.
\uproot@=\count88
\leftroot@=\count89
LaTeX Info: Redefining \overline on input line 307.
\classnum@=\count90
\DOTSCASE@=\count91
LaTeX Info: Redefining \ldots on input line 379.
LaTeX Info: Redefining \dots on input line 382.
LaTeX Info: Redefining \cdots on input line 467.
\Mathstrutbox@=\box26
\strutbox@=\box27
\big@size=\dimen105
LaTeX Font Info:    Redeclaring font encoding OML on input line 567.
LaTeX Font Info:    Redeclaring font encoding OMS on input line 568.
\macc@depth=\count92
\c@MaxMatrixCols=\count93
\dotsspace@=\muskip10
\c@parentequation=\count94
\dspbrk@lvl=\count95
\tag@help=\toks15
\row@=\count96
\column@=\count97
\maxfields@=\count98
\andhelp@=\toks16
\eqnshift@=\dimen106
\alignsep@=\dimen107
\tagshift@=\dimen108
\tagwidth@=\dimen109
\totwidth@=\dimen110
\lineht@=\dimen111
\@envbody=\toks17
\multlinegap=\skip44
\multlinetaggap=\skip45
\mathdisplay@stack=\toks18
LaTeX Info: Redefining \[ on input line 2666.
LaTeX Info: Redefining \] on input line 2667.
)
(/usr/share/texmf-texlive/tex/latex/amscls/amsthm.sty
Package: amsthm 2004/08/06 v2.20
\thm@style=\toks19
\thm@bodyfont=\toks20
\thm@headfont=\toks21
\thm@notefont=\toks22
\thm@headpunct=\toks23
\thm@preskip=\skip46
\thm@postskip=\skip47
\thm@headsep=\skip48
\dth@everypar=\toks24
)
(/usr/share/texmf-texlive/tex/latex/amsfonts/amssymb.sty
Package: amssymb 2009/06/22 v3.00

(/usr/share/texmf-texlive/tex/latex/amsfonts/amsfonts.sty
Package: amsfonts 2009/06/22 v3.00 Basic AMSFonts support
\symAMSa=\mathgroup4
\symAMSb=\mathgroup5
LaTeX Font Info:    Overwriting math alphabet `\mathfrak' in version `bold'
(Font)                  U/euf/m/n --> U/euf/b/n on input line 96.
))
(/usr/share/texmf-texlive/tex/latex/tools/bm.sty
Package: bm 2004/02/26 v1.1c Bold Symbol Support (DPC/FMi)
\symboldoperators=\mathgroup6
\symboldletters=\mathgroup7
\symboldsymbols=\mathgroup8
LaTeX Font Info:    Redeclaring math alphabet \mathbf on input line 138.
LaTeX Info: Redefining \bm on input line 204.
)
(/usr/share/texmf-texlive/tex/latex/graphics/color.sty
Package: color 2005/11/14 v1.0j Standard LaTeX Color (DPC)

(/etc/texmf/tex/latex/config/color.cfg
File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
)
Package color Info: Driver file: dvips.def on input line 130.

(/usr/share/texmf-texlive/tex/latex/graphics/dvips.def
File: dvips.def 1999/02/16 v3.0i Driver-dependant file (DPC,SPQR)
)
(/usr/share/texmf-texlive/tex/latex/graphics/dvipsnam.def
File: dvipsnam.def 1999/02/16 v3.0i Driver-dependant file (DPC,SPQR)
))
No file tmpuBP4Sl.aux.
\openout1 = `tmpuBP4Sl.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Try loading font information for U+msa on input line 10.
(/usr/share/texmf-texlive/tex/latex/amsfonts/umsa.fd
File: umsa.fd 2009/06/22 v3.00 AMS symbols A
)
LaTeX Font Info:    Try loading font information for U+msb on input line 10.

(/usr/share/texmf-texlive/tex/latex/amsfonts/umsb.fd
File: umsb.fd 2009/06/22 v3.00 AMS symbols B
)
! Display math should end with $$.
<to be read again> 

l.10 $$\frac{2}{3}$

Here is how much of TeX's memory you used:
 1581 strings out of 495062
 18727 string characters out of 1182643
 62706 words of memory out of 3000000
 4783 multiletter control sequences out of 15000+50000
 8096 words of font info for 31 fonts, out of 3000000 for 9000
 28 hyphenation exceptions out of 8191
 27i,2n,24p,220b,76s stack positions out of 5000i,500n,10000p,200000b,50000s

No pages of output.

I know where the problem is. Happened on:

data = self._latex_to_base64(expr, math_mode)

and for some reason the expr is u'$\\frac{2}{3}'

The original document is u'Hello World! You should setup your website.\r\n\r\n$$\\frac{2}{3}$$'

escape percentage sign?

consider the following text:

  from 40% to nearly 80%.  I am accidently entered tex mode.

  from 40\% to nearly 80\%.  I am accidently entered tex mode.

render it with markdown_py -x latex sample.md > sample.html gets:

  <p>from 40<img class='latex-inline math-false' alt='tonearly80' id='tonearly80' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFYAAAAQBAMAAAB+eZW1AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAdrsQie9mqyJEMplU3c0GZ1kGAAABc0lEQVQoz43SP0gCURwH8K93cv/UuPCoQQqjCIKgGyJo8gIhiQYhcipQEGsxhBoaGk4IIhelvbqmtpIKIVya2kqhkNpqbsgwspbo906NGix/y/3uvQ/H9/3eAW0rg45Lef5uY5oOLU6N2g4ftxrB5P2CIacAfzubbTUcsOqxMIfx8L+2K4+HgI4Kll5D6InrtLR7F0vBGVOlxCyuRqbJJt+kRQtwf25a+zpuIYfhupDKZOUFDGMUBc7wWO77I7JKFV724dILSsATs3SIAVqRajij3Wt3TjToyTJUEKUNfmYsX9IbNgmcMFtF0RFJ+JDuN5SwbVdkk+XVhY9mBqXvhyXjHHQZStm2gTSLcAhoWRMRsgJlGGpapQYpoIuhTMOKG8xuAZc0s3fw1UkxKt2wiyKLNUxkde58u5FBsQfKmTgV8jJdRK+KoI/NbKeenledU6qjsPy4V8/JY+uAwSwf1Ex023P9o+yjdVZFR+e/2oH31+sXpx1gwC/5fcgAAAAASUVORK5CYII='>.  I am accidently entered tex mode.</p>
  <p>from 40\% to nearly 80\%.  I am accidently entered tex mode.</p>          

What's the proper way to escape the % sign?

Plugin not found on Python 3.8

A simple copy of latex.py into the markdown/extensions/ directory is not enough in Markdown 3.1.1 on Python 3.8. The module is not found.

It looks like you are using an old registration method, perhaps that is the cause; the current procedure invokes registerExtension() on another class, markdown.extension.Extension, than you are using.

TypeError: 'NoneType' object is not iterable

Got an issue when configs in None:

/lib/python2.7/site-packages/markdown/extensions/__init__.py", line 75, in setConfigs
    for key, value in items:
TypeError: 'NoneType' object is not iterable

best way to escape dollar sign?

I am typesetting articles on pricing and economy. There are dollar signs with normal text. If I don't escape them, python would complain about

  UnicodeEncodeError: 'ascii' codec can't encode character u'\ufb00'

or something like that, different u'' characters. It's really misleading! I thought there were some characters that python can't handle or the file is encoded with BOM.

Meanwhile the latex tmp.log stops after \usepackage then \end{article}, nothing within

Until by some chance I got to see a real latex tmp log with:

  ! Missing $ inserted.
 <inserted text> 
              $

I knew it's something within equation or some missing $ . Of course, there are dollar signs all over the article.

Here is a sample:

  ## DEFINITION

  $ \displaystyle Value_a - Price_a \geq Value_b - Price_b $

  Rearranging gives:

  $ \displaystyle Price_a \leq (Value_a - Value_b) + Price_a Price_b \leq Differentiation Value_b + Price_b $

  - This suggests that the EVC of a server with the software is  $6,000 + $6,800 = $12,800. 

  - item 2 is  $6,000 + $6,800 = $12,800. 

Currently my way of dealing with this is to manually escape each $dollars. Because % $6,000 + $6,800 = $12,800. % inline won't work

My question is what's the best the to deal with it?

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.