Giter VIP home page Giter VIP logo

readme2tex's Introduction

readme2tex

Renders LaTeX for Github Readmes

$$
\huge\text{Hello \LaTeX}
$$

\begin{tikzpicture}
\newcounter{density}
\setcounter{density}{20}
    \def\couleur{blue}
    \path[coordinate] (0,0)  coordinate(A)
                ++( 60:6cm) coordinate(B)
                ++(-60:6cm) coordinate(C);
    \draw[fill=\couleur!\thedensity] (A) -- (B) -- (C) -- cycle;
    \foreach \x in {1,...,15}{%
        \pgfmathsetcounter{density}{\thedensity+10}
        \setcounter{density}{\thedensity}
        \path[coordinate] coordinate(X) at (A){};
        \path[coordinate] (A) -- (B) coordinate[pos=.15](A)
                            -- (C) coordinate[pos=.15](B)
                            -- (X) coordinate[pos=.15](C);
        \draw[fill=\couleur!\thedensity] (A)--(B)--(C)--cycle;
    }
\end{tikzpicture}

Make sure that pdflatex is installed on your system.


readme2tex is a Python script that "texifies" your readme. It takes in Github Markdown and replaces anything enclosed between dollar signs with rendered $\text{\LaTeX}$.

In addition, while other Github TeX renderers tend to give a jumpy look to the compiled text,

readme2tex ensures that inline mathematical expressions are properly aligned with the rest of the text to give a more natural look to the document. For example, this formula $\frac{dy}{dx}$ is preprocessed so that it lines up at the correct baseline for the text. This is the one salient feature of this package compared to the others out there.

Installation

Make sure that you have Python 2.7 or above and pip installed. In addition, you'll need to have the programs latex and dvisvgm on your PATH. In addition, you'll need to pre-install the geometry package in $\text{\LaTeX}$.

To install readme2tex, you'll need to run

sudo pip install readme2tex

or, if you want to try out the bleeding edge,

git clone https://github.com/leegao/readme2tex
cd readme2tex
python setup.py develop

To compile INPUT.md and render all of its formulas, run

python -m readme2tex --output README.md INPUT.md

If you want to do this automatically for every commit of INPUT.md, you can use the --add-git-hook command once to set up the post-commit hook, like so

git stash --include-untracked
git branch svgs # if this isn't already there

python -m readme2tex --output README.md --branch svgs --usepackage tikz INPUT.md --add-git-hook

# modify INPUT.md

git add INPUT.md
git commit -a -m "updated readme"

git stash pop

and every git commit that touches INPUT.md from now on will allow you to automatically run readme2tex on it, saving you from having to remember how readme2tex works. The caveat is that if you use a GUI to interact with git, things might get a bit wonky. In particular, readme2tex will just assume that you're fine with all of the changes and won't prompt you for verification like it does on the terminal.

You can uninstall the hook by deleting .git/hooks/post-commit. See python -m readme2tex --help for a list of what you can do in readme2tex.

Examples:

Here's a display level formula

$$
\frac{n!}{k!(n-k)!} = {n \choose k}
$$

The code that was used to render this formula is just

$$
\frac{n!}{k!(n-k)!} = {n \choose k}
$$

Note: you can escape $ so that they don't render.

Here's an inline formula.

It is well known that if $ax^2 + bx + c =0$, then $x = \frac{-b \pm \sqrt{b^2- 4ac}}{2a}$.

The code that was used to render this is:

It is well known that if $ax^2 + bx + c = 0$, then $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$.

Notice that the formulas line up with the baseline of the text, even when the height of these two images are different.

Sometimes, you might run into formulas that are bottom-heavy, like $x^2\sum\limits_{3^{n^{n^{n}}}}$. Here, readme2tex can compute the correct offset to align this formula to the baseline of your paragraph of text as well.

Tikz (Courtesy of http://www.texample.net/)

Did you notice the picture at the top of this page? That was also generated by $\text{\LaTeX}$. readme2tex is capable of handling Tikz code. For reference, the picture

\begin{tikzpicture}
\newcounter{density}
\setcounter{density}{20}
    \def\couleur{red}
    \path[coordinate] (0,0)  coordinate(A)
                ++( 60:6cm) coordinate(B)
                ++(-60:6cm) coordinate(C);
    \draw[fill=\couleur!\thedensity] (A) -- (B) -- (C) -- cycle;
    \foreach \x in {1,...,15}{%
        \pgfmathsetcounter{density}{\thedensity+10}
        \setcounter{density}{\thedensity}
        \path[coordinate] coordinate(X) at (A){};
        \path[coordinate] (A) -- (B) coordinate[pos=.15](A)
                            -- (C) coordinate[pos=.15](B)
                            -- (X) coordinate[pos=.15](C);
        \draw[fill=\couleur!\thedensity] (A)--(B)--(C)--cycle;
    }
\end{tikzpicture}

is given by the tikz code

\begin{tikzpicture}
\newcounter{density}
\setcounter{density}{20}
    \def\couleur{red}
    \path[coordinate] (0,0)  coordinate(A)
                ++( 60:6cm) coordinate(B)
                ++(-60:6cm) coordinate(C);
    \draw[fill=\couleur!\thedensity] (A) -- (B) -- (C) -- cycle;
    \foreach \x in {1,...,15}{%
        \pgfmathsetcounter{density}{\thedensity+10}
        \setcounter{density}{\thedensity}
        \path[coordinate] coordinate(X) at (A){};
        \path[coordinate] (A) -- (B) coordinate[pos=.15](A)
                            -- (C) coordinate[pos=.15](B)
                            -- (X) coordinate[pos=.15](C);
        \draw[fill=\couleur!\thedensity] (A)--(B)--(C)--cycle;
    }
\end{tikzpicture}

We can see a few other examples, such as this graphical proof of the Pythagorean Theorem.

\begin{tikzpicture}
\newcommand{\pythagwidth}{3cm}
\newcommand{\pythagheight}{2cm}
  \coordinate [label={below right:$A$}] (A) at (0, 0);
  \coordinate [label={above right:$B$}] (B) at (0, \pythagheight);
  \coordinate [label={below left:$C$}] (C) at (-\pythagwidth, 0);

  \coordinate (D1) at (-\pythagheight, \pythagheight + \pythagwidth);
  \coordinate (D2) at (-\pythagheight - \pythagwidth, \pythagwidth);

  \draw [very thick] (A) -- (C) -- (B) -- (A);

  \newcommand{\ranglesize}{0.3cm}
  \draw (A) -- ++ (0, \ranglesize) -- ++ (-\ranglesize, 0) -- ++ (0, -\ranglesize);

  \draw [dashed] (A) -- node [below] {$b$} ++ (-\pythagwidth, 0)
            -- node [right] {$b$} ++ (0, -\pythagwidth)
            -- node [above] {$b$} ++ (\pythagwidth, 0)
            -- node [left]  {$b$} ++ (0, \pythagwidth);

  \draw [dashed] (A) -- node [right] {$c$} ++ (0, \pythagheight)
            -- node [below] {$c$} ++ (\pythagheight, 0)
            -- node [left]  {$c$} ++ (0, -\pythagheight)
            -- node [above] {$c$} ++ (-\pythagheight, 0);

  \draw [dashed] (C) -- node [above left]  {$a$} (B)
                     -- node [below left]  {$a$} (D1)
                     -- node [below right] {$a$} (D2)
                     -- node [above right] {$a$} (C);
\end{tikzpicture}

How about a few snowflakes?

\begin{center}
\usetikzlibrary{lindenmayersystems}

\pgfdeclarelindenmayersystem{A}{
    \rule{F -> FF[+F][-F]}
}

\pgfdeclarelindenmayersystem{B}{
    \rule{F -> ffF[++FF][--FF]}
}

\pgfdeclarelindenmayersystem{C}{
    \symbol{G}{\pgflsystemdrawforward}
    \rule{F -> F[+F][-F]FG[+F][-F]FG}
}

\pgfdeclarelindenmayersystem{D}{
    \symbol{G}{\pgflsystemdrawforward}
    \symbol{H}{\pgflsystemdrawforward}
    \rule{F -> H[+HG][-HG]G}
    \rule{G -> HF}
}

\tikzset{
    type/.style={l-system={#1, axiom=F,order=3,step=4pt,angle=60},
      blue, opacity=0.4, line width=.5mm, line cap=round   
    },
}

\newcommand\drawsnowflake[2][scale=0.2]{
    \tikz[#1]
    \foreach \a in {0,60,...,300}  {
    \draw[rotate=\a,#2] l-system;
    };
}

\foreach \width in {.2,.4,...,.8} 
{  \drawsnowflake[scale=0.3]{type=A, line width=\width mm} }

\foreach \width in {.2,.4,...,.8} 
{  \drawsnowflake[scale=0.38]{type=A, l-system={angle=90}, line width=\width mm} }    

\foreach \width in {.2,.4,...,.8} 
{  \drawsnowflake[scale=0.3]{type=B, line width=\width mm} }

\foreach \width in {.2,.4,...,.8} 
{  \drawsnowflake{type=B, l-system={angle=30}, line width=\width mm} }

\drawsnowflake[scale=0.24]{type=C, l-system={order=2}, line width=0.2mm}
\drawsnowflake[scale=0.25]{type=C, l-system={order=2}, line width=0.4mm}
\drawsnowflake[scale=0.25]{type=C, l-system={order=2,axiom=fF}, line width=0.2mm}
\drawsnowflake[scale=0.32]{type=C, l-system={order=2,axiom=---fff+++F}, line width=0.2mm}

\drawsnowflake[scale=0.38]{type=D, l-system={order=4,angle=60,axiom=GF}, line width=0.7mm}
\drawsnowflake[scale=0.38]{type=D, l-system={order=4,angle=60,axiom=GfF}, line width=0.7mm}
\drawsnowflake[scale=0.38]{type=D, l-system={order=4,angle=60,axiom=FG}, line width=0.7mm}
\drawsnowflake[scale=0.38]{type=D, l-system={order=4,angle=60,axiom=FfG}, line width=0.7mm}
\end{center}

Usage

python -m readme2tex --output README.md [READOTHER.md]

It will then look for a file called readother.md and compile it down to a readable Github-ready document.

In addition, you can specify other arguments to render.py, such as:

  • --readme READOTHER.md The raw readme to process. Defaults to READOTHER.md.
  • --output README.md The processed readme.md file. Defaults to README_GH.md.
  • --usepackage tikz Addition packages to use during $\text{\LaTeX}$ compilation. You can specify this multiple times.
  • --svgdir svgs/ The directory to store the output svgs. The default is svgs/
  • --branch master Experimental Which branch to store the svgs into, the default is just master.
  • --username username Your github username. This is optional, and render.py will try to infer this for you.
  • --project project The current github project. This is also optional.
  • --nocdn Ticking this will use relative paths for the output images. Defaults to False.
  • --htmlize Ticking this will output a md.html file so you can preview what the output looks like. Defaults to False.
  • --valign Ticking this will use the valign trick (detailed below) instead. See the caveats section for tradeoffs.
  • --rerender Ticking this will force a recompilation of all $\text{\LaTeX}$ formulas even if they are already cached.
  • --bustcache Ticking this will ensure that Github renews its image cache. Github may sometimes take up to an hour for changed images to reappear. This is usually not necessary unless you've made stylistic changes.
  • --add-git-hook Ticking this will generate a post-commit hook for git that runs readme2tex with the rest of the specified arguments after each git commit.
  • --pngtrick Ticking this will generate png files instead of svgs for the formulas.

My usual workflow is to create a secondary branch just for the compiled svgs. You can accomplish this via

python -m readme2tex --branch svgs --output README.md

However, be careful with this command, since it will switch over to the svgs branch without any input from you.

Relative Paths

If you're on a private repository or you want to, for whatever reason, use relative paths to resolve your images, you can do so by using the combination

python -m readme2tex --branch master --nocdn --pngtrick ...

which will output pngs relative to your README.md.

Due to security considerations, Github will not resolve svgs relatively, which means that private repositories will be locked out of the usual svg workflow. Using the --branch master --nocdn --pngtrick combination will get around this restriction.

Troubleshooting

Tikz

If your Tikz drawings don't show up, there's a good chance that you either don't have Ghostscript installed or dvisvgm isn't picking it up for whatever reason. This is most likely to happen on some installations of TexLive on OSX.

Check to see if ps is included in the list when you run

# dvisvgm -l
bgcolor    background color special
color      complete support of color specials
dvisvgm    special set for embedding raw SVG snippets
em         line drawing statements of the emTeX special set
html       hyperref specials
pdf        pdfTeX font map specials
ps         dvips PostScript specials <<<
tpic       TPIC specials

If not, try installing it (either apt-get, yum, or brew). Furthermore, if you are on OSX, make sure to add the following to your ~/.bash_profile

export LIBGS=/usr/local/lib/libgs.dylib

where /usr/local/lib/libgs.dylib is the location where libgs.dylib is installed.

I'm seeing weird formatting from time to time.

Make sure that if you have a <p>...</p> tag somewhere, you leave at least one blank line after the closing tag.

I ran --add-git-hook, but the post-commit hook isn't running after committing.

chmod +x .git/hooks/post-commit

I raw readme2tex and got strange image srcs or got images that won't resolve

Try running readme2tex with

python -m readme2tex ... --username GITHUB_USERNAME  --project PROJECT_NAME

I ran readme2tex and got a traceback somewhere.

Unfortunately, this script still has a few kinks and bugs that I need to iron out. In the mean time, if the pypi releases aren't working for you, you should switch over to the development version to see if the bugs have been squashed:

git clone https://github.com/leegao/readme2tex
cd readme2tex
python setup.py develop

Technical Tricks

How can you tell where the baseline of an image is?

By prepending every inline formula with an anchor. During post-processing, we can isolate the anchor, which is fixed at the baseline, and crop it out. It's super clowny, but it does the job.

Caveats

Github does not allow you to pass in custom style attributes to your images. While this is useful for security purposes, it makes it incredibly difficult to ensure that images will align correctly to the text. readme2tex circumvents this using one of two tricks:

  1. In Chrome, the attribute valign=offset works for img tags as well. This allows us to shift the image directly. Unfortunately, this is not supported within any of the other major browsers, therefore this mode is not enabled by default.
  2. In every (reasonably modern) browser, the align=middle attribute will vertically center an image. However, the definition of the vertical "center" is different. In particular, for Chrome, Firefox, (and probably Safari), that center is the exact middle of the image. For IE and Edge however, the center is about 5 pixels (the height of a lower-case character) above the exact center. Since this looks great for non-IE browsers, and reasonably good on Edge, this is the default rendering method. The trick here is to pad either the top or the bottom of the image with extra spaces until the baseline of the formula is at the center. For most formulas, this works great. However, if you have a tall formula, like $\frac{~}{\sum\limits_{x^{x^{x^{x}}}}^{x^{x^{x^{x}}}} f(x)}$, you'll notice that there might be a lot of slack vertical spacing between these lines. If this is a deal-breaker for you, you can always try the --valign True mode. For most inline formulas, this is usually a non-issue.

How to compile this document

Make sure that you have the tikz and the xcolor packages installed locally.

python -m readme2tex --usepackage "tikz" --usepackage "xcolor" --output README.md --branch svgs

and of course

python -m readme2tex --usepackage "tikz" --usepackage "xcolor" --output README.md --branch svgs --add-git-hook

For the png relative mode, use

python -m readme2tex --usepackage "tikz" --usepackage "xcolor" --output README.md --branch master --nocdn --pngtrick

\begin{tikzpicture}[scale=0.25, line join=bevel]
% \a and \b are two macros defining characteristic
% dimensions of the Penrose triangle.		
\pgfmathsetmacro{\a}{2.5}
\pgfmathsetmacro{\b}{0.9}

\tikzset{%
  apply style/.code     = {\tikzset{#1}},
  triangle_edges/.style = {thick,draw=black}
}

\foreach \theta/\facestyle in {%
    0/{triangle_edges, fill = gray!50},
  120/{triangle_edges, fill = gray!25},
  240/{triangle_edges, fill = gray!90}%
}{
  \begin{scope}[rotate=\theta]
    \draw[apply style/.expand once=\facestyle]
      ({-sqrt(3)/2*\a},{-0.5*\a})                     --
      ++(-\b,0)                                       --
        ({0.5*\b},{\a+3*sqrt(3)/2*\b})                -- % higher point	
        ({sqrt(3)/2*\a+2.5*\b},{-.5*\a-sqrt(3)/2*\b}) -- % rightmost point
      ++({-.5*\b},-{sqrt(3)/2*\b})                    -- % lower point
        ({0.5*\b},{\a+sqrt(3)/2*\b})                  --
      cycle;
    \end{scope}
  }	
\end{tikzpicture}

readme2tex's People

Contributors

fulldecent avatar l-winston avatar leegao avatar maxwellgerber avatar philschatz avatar sergeio avatar tapplencourt 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

readme2tex's Issues

Error executing subprocess.CalledProcessError dvisvgm

I'm not sure what's wrong, tried with sudo in case my user didn't have permissions, same outcome.

$ python3 -m readme2tex --output README1.md README.md 
'$n * T_i | n\in \Bbb N + \{0\}$' has warnings during compilation. See /var/folders/3w/b2_16tq53jnfq2kn92fg4mdh0000gs/T/readme2tex-srbuc3i1/01c646718a35875ea8195cf0865d9375
ERROR: can't open file '/var/folders/3w/b2_16tq53jnfq2kn92fg4mdh0000gs/T/readme2tex-srbuc3i1/01c646718a35875ea8195cf0865d9375.dvi' for reading
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/site-packages/readme2tex/__main__.py", line 147, in <module>
    render(
  File "/usr/local/lib/python3.9/site-packages/readme2tex/render.py", line 167, in render
    svg, dvi, name = rendertex(engine, equation, packages, temp_dir, block)
  File "/usr/local/lib/python3.9/site-packages/readme2tex/render.py", line 43, in rendertex
    svg = check_output(
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['dvisvgm', '-v0', '-a', '-n', '-s', '/var/folders/3w/b2_16tq53jnfq2kn92fg4mdh0000gs/T/readme2tex-srbuc3i1/01c646718a35875ea8195cf0865d9375.dvi']' returned non-zero exit status 252.
$ cat /var/folders/3w/b2_16tq53jnfq2kn92fg4mdh0000gs/T/readme2tex-srbuc3i1/01c646718a35875ea8195cf0865d9375.tex 
% processed with readme2tex
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{geometry}
\pagestyle{empty}
\geometry{paperwidth=250mm, paperheight=16383pt, left=0pt, top=0pt, textwidth=426pt, marginparsep=20pt, marginparwidth=100pt, textheight=16263pt, footskip=40pt}
\begin{document}
a$n * T_i | n\in \Bbb N + \{0\}$
\end{document}

Possible to run without being in a git repo?

I'd just like to convert a markdown+tex file without being in git repo. Is this possible? Currently I get this error:

Not in a git repository, please enable --nocdn
fatal: not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.7/site-packages/readme2tex/render.py", line 290, in render
    giturl = check_output(['git', 'remote', '-v']).strip().decode('utf-8').splitlines()[0]
  File "/opt/anaconda3/lib/python3.7/subprocess.py", line 395, in check_output
    **kwargs).stdout
  File "/opt/anaconda3/lib/python3.7/subprocess.py", line 487, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['git', 'remote', '-v']' returned non-zero exit status 128.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/opt/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/opt/anaconda3/lib/python3.7/site-packages/readme2tex/__main__.py", line 160, in <module>
    args.bustcache)
  File "/opt/anaconda3/lib/python3.7/site-packages/readme2tex/render.py", line 296, in render
    raise Exception("Please specify your github --username and --project.")
Exception: Please specify your github --username and --project.

Using tikz libraries

Hi, I'd like to use tikz libraries, like \usetikzlibrary{positioning}. Is this possible? Thank you for your cool project!

gfill is NoneType

I got the error:

File "./readme2tex/render.py", line 180, in render
    gfill.set('fill-opacity', '0.9')
AttributeError: 'NoneType' object has no attribute 'set'

For whatever reason my environment's rendertex() was returning svgs with "http" instead of "https". A quick fix was to change the gfill and use variables in render.py to find the correct string.

gfill = xml.find('{http://www.w3.org/2000/svg}g')
gfill.set('fill-opacity', '0.9')
if not block:
    uses = gfill.findall('{http://www.w3.org/2000/svg}use')

If someone knows why my environment did that please let me know. It might also be nice to add some kind of check in the code to prevent the end user from having to alter this.

Using readme2tex in private repos

First of all, thanks for creating readme2tex -- very cool and useful idea!

I tried to use it in one of my private repos, and, unfortunately, it doesn't seem to work because rawgit doesn't allow to access files in private repos (see #92). At the same time, github doesn't allow accessing SVGs using relative paths for security reasons (see #316).

I am wondering if there is a known workaround for this issue? A straightforward one would be to enable rendering latex as PNGs (optionally) and use relative paths for them. Would it be possible to add support for this?

Remotes that are ssh instead of http

The path fails to correctly parse the username when the user is using a ssh as their first remote. This can be easily fixed by deleting a single '/' character from the parsing snippet in line 294 of render.py. As both http and ssh have a .com? right before the username, where ? is either "/" for http or "@" for ssh.

start = giturl.find('.com') + 5

Support for persistent newcommand definitions

The following works as expected:

# README 

$\newcommand{\f}{\mathbf{f}}
\|\f\|^2$

But if I put newcommand in a different line this will not work:

# README 

$\newcommand{\f}{\mathbf{f}}$

$\|\f\|^2$

Mathjax for example will keep commands persistent through the document. This is very useful if I want to define some macro at the top of the document and use it in a bunch of equations below.

I humbly request this feature.

Dark theme issues

I recognize this is a challenging problem to resolve but rendered formulas are invisible in dark mode:

image

broken/weird URL for images

Hi, I'm getting <img src="https://rawgit.com/in [email protected]:parrt/auto-diff-edu/master/images/6177db6fc70d94fdb9dbe1907695fce6.svg?invert_in_darkmode" align=middle width=15.947580000000002pt height=26.76201000000001pt/>. for an image url.

i'm using

python -m readme2tex --rerender --svgdir images --usepackage physics --output README.md README.tex.md 

cool package btw!

Support for unicode

The following works as expected:

# README

$\phi^2 \ge 0, \forall \in R$

Mathjax and other tex compilers will allow unicode input (probably by including \usepackage[utf8x]{inputenc}). If I use readme2tex directly this will not work

# README 

$φ² ≥  0, ∀ φ ∈ R$

and instead quietly outputs 0,R for the math part.

Is it possible to achieve this? If not, I'd like to request unicode support as a feature.

UnicodeDecodeError

When running python -m readme2tex --output foo.md Summary.md

I encounter this error message: UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 1: ordinal not in range(128)

I get that I must have an unusual char in my document, but how do I get around this?

Rawgit URL not work anymore

I don't know why but my math repo was working and I was making ready for my student and teachers in university but that day none of svgs worked

After that I found that rawgit is ended,
Can you see it, maybe I'm wrong ?!!

If it's true can you change the URL for rawgit
Thanks
I change the source code for myself and it's worked
How ever maybe I'm wrong about this.

Thanks for this handy tools
Hail Mathematics for ever

No such file or directory: 'dvisvgm'

Hello, I just installed this package and I tried to complie my README.md.
After I command python -m readme2tex --output result.md README.md, I got this error message but I don't know how to handle it

'$cost=\sum { { (y-\bar { y } ) }^{ 2 } } +\lambda \sum { { \left| W \right|  }^{ 2 } }$' has warnings during compilation. See /var/folders/zb/9sv0pm4x7v1c9ng44rpbqs7r0000gn/T/readme2tex-k3308sx3/6cfc9fee460f304e0df2af7fcf3336f8
Traceback (most recent call last):
  File "/Users/bmy4415/.pyenv/versions/3.5.4/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Users/bmy4415/.pyenv/versions/3.5.4/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/bmy4415/.pyenv/versions/3.5.4/lib/python3.5/site-packages/readme2tex/__main__.py", line 160, in <module>
    args.bustcache)
  File "/Users/bmy4415/.pyenv/versions/3.5.4/lib/python3.5/site-packages/readme2tex/render.py", line 167, in render
    svg, dvi, name = rendertex(engine, equation, packages, temp_dir, block)
  File "/Users/bmy4415/.pyenv/versions/3.5.4/lib/python3.5/site-packages/readme2tex/render.py", line 44, in rendertex
    ['dvisvgm', '-v0', '-a', '-n', '-s', dvi])
  File "/Users/bmy4415/.pyenv/versions/3.5.4/lib/python3.5/subprocess.py", line 316, in check_output
    **kwargs).stdout
  File "/Users/bmy4415/.pyenv/versions/3.5.4/lib/python3.5/subprocess.py", line 383, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/Users/bmy4415/.pyenv/versions/3.5.4/lib/python3.5/subprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "/Users/bmy4415/.pyenv/versions/3.5.4/lib/python3.5/subprocess.py", line 1289, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'dvisvgm'

I think there are some faults in my LATEX code but not sure.
Can anybody help me?

Inline equations will insert newlines

I'm not sure if I misconfigured something, but some short inline equations will insert a new line before and after the equation.

Example:
image
instead of
image

And
image
instead of
image

Have to remove ?invert_in_darkmode to render images

First, thanks for writing this!

Second, after I generate via

python -m readme2tex --output README.md --readme .README.md --branch master --svgdir 'docs/gfx' --nocdn --rerender --usepackage 'tikz' --usepackage 'algorithm' --usepackage 'algpseudocode' --usepackage 'fancybox'

I get a README.md with svg image links all ending in ?invert_in_darkmode. If I push these to github, the images are broken. However, if I remove ?invert_in_darkmode from the generated document everything works fine.

Another point that might be relevant, this is for a private repo.

Support different (pandoc) markdown syntaxes

When I convert a markdown file with pandoc to github flavor markdown with the -t gfm option, $$ ... $$ will get converted to \[ ...\] (not sure why). Any chance of supporting this syntax as well? Multimarkdown appears to have this/a non "$" based syntax for maths as well, for example.

403 Forbidden...?

Hi, I hope that I used everything correctly.
But after successfully running python -m readme2tex --output README.md INPUT.md I get my README.md file with

<p align="center"><img src="https://rawgit.com/patrick-rode/sudoku/None/svgs/32737e0a8d5a4cf32ba3ab1b74902ab7.svg?invert_in_darkmode" align=middle width=127.9847844pt height=39.452455349999994pt/></p>

in it. Looks good at first, but the URL does not work:

403 Forbidden
RawGit will soon shut down and is no longer serving new repos. Please visit https://rawgit.com/ for more details.

align=middle does not work on github.io

Seems like the img tags have align=middle instead of align="middle". Although this works on the github readme, it does not work on the corresponding github.io page. Manually changing them all to align="middle" seems to work.

New line in math block

I noticed a bug dealing with new lines in LaTeX blocks.

For example, if my markdown file looks like

$$ x = 1 \\ y = 1, $$

the output svg has all of this code in one line.

However, when I insert a new line inside of a matrix, this issue is not present. For example,

$$ y = \begin{bmatrix} y_1\\ y_2\\ ...\\ y_k \end{bmatrix} $$

works as it should.

'$' in code blocks

When I write '$' in code block, the script can not work as normal. For example,

$ git clone https://github.com/leegao/readme2tex.git
$ cd readme2tex/

and the script will detect the command as inline equation.

image1

image2

How can use readme2tex over multiple files?

Hi there,

I want to use readme2tex to compile latex equations for a wiki project where there are multiples Markdown files.
How can I use the git hook command to work over the multiple files?

Best regards

"pngtrick" unrecognized

Trying to generate PNGs with this tool, but it seems to not be recognizing the flag. I tried on bleeding edge as well:

python -m readme2tex --output ~/temp/README.md --branch master --nocdn --pngtrick --htmlize --username jjshammas --project test --usepackage tikz README.tex
usage: python -m readme2tex [-h] [--readme [README]] [--engine ENGINE]
                            [--output OUTPUT] [--usepackage USEPACKAGE]
                            [--svgdir SVGDIR] [--branch BRANCH]
                            [--username USERNAME] [--project PROJECT]
                            [--nocdn] [--htmlize] [--valign] [--rerender]
                            [--bustcache] [--add-git-hook]
                            [input]
python -m readme2tex: error: unrecognized arguments: --pngtrick

Difference rawgit.com or raw.githubusercontent.com

My raw files are stored on raw.githubusercontent.com instead of rawgit.com.

For example, some svg would be saved here:
https://raw.githubusercontent.com/RobRomijnders/ssl_graph/master/svgs/c9ea84eb1460d2895e0cf5125bd7f7b5.svg
But readme2tex would refer to the image as being here
https://rawgit.com/RobRomijnders/ssl_graph/master/svgs/c9ea84eb1460d2895e0cf5125bd7f7b5.svg

Might this be due to an update on github's side? If so, could be include it as a flag?

Failure while compiling

Hi,
I have just installed the package I have tried with the following command

python -m readme2tex --output README.md readme.md
and I have the following error message

Traceback (most recent call last):
  File "C:\Users\SESA476345\AppData\Local\Continuum\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\SESA476345\AppData\Local\Continuum\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\users\sesa476345\documents\to_install_latex\readme2tex\readme2tex\__main__.py", line 162, in <module>
    args.bustcache)
  File "c:\users\sesa476345\documents\to_install_latex\readme2tex\readme2tex\render.py", line 177, in render
    xml = (ET.fromstring(svg))
  File "C:\Users\SESA476345\AppData\Local\Continuum\anaconda3\lib\xml\etree\ElementTree.py", line 1315, in XML
    return parser.close()
xml.etree.ElementTree.ParseError: no element found: line 1, column 0

I am not sure to understand exactly where the problem comes from

Traceback when using --add-git-hook

The directory I was working in was a git repository:

code/coq-typeclass-hierarchy > python -m readme2tex --add-git-hook
Traceback (most recent call last):
  File "/nix/store/p4fqqhllhyj90njg2sksz8qrgzlzs193-python-2.7.13/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/nix/store/p4fqqhllhyj90njg2sksz8qrgzlzs193-python-2.7.13/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/nix/store/qgfi4pzf9awf5axakp2f0kj4xf7r7grn-readme2tex/lib/python2.7/site-packages/readme2tex/__main__.py", line 163, in <module>
    assert os.path.exists(".git")
AssertionError

[Possible bug report] - Proceeding tab

I found that the inline code and code block which are proceeded by tab wouldn't be translated by readme2tex.
For instances:

    $A^2 + B^2 = C^2$

    $$
    A^2 + B^2 = C^2
    $$

The output translated from the above LaTeX expressions is still the same.

  • Relative info:
    Package version: 0.0.1b2
    Python version: Python 2.7.17 / Python 3.6.9
    Platform: x86_64 GNU/Linux

Thanks for your consideration!

Parsing equations in a markdown list

I couldn't get readme2tex to generate any images from a markdown file containing a list, formatted like this:

1. First line of the list,
   manually broken and continued on this line
   along with an equation $Ax=b$

This (perhaps odd...) formatting is due to the text editor I use manually breaking lines rather than wrapping them.

In particular, extract_equations was returning an empty list when given my file's contents as input. This seemed like it was due to these three lines (lines 69-71) in render.py/extract_equations.

Indeed, I commented these lines out and everything worked great. What is the intended purpose of these lines? Am I breaking another functionality by commenting them out?

Exception for latex in code snippets

works great, but it also renders latex within code snippets that should ideally be left alone:

Here's an example

image

Any way to ignore text within ... regions?

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.