How to show math equations in general github's markdown(not github's blog)

后端 未结 10 1499
Happy的楠姐
Happy的楠姐 2020-11-29 14:36

After investigating, I\'ve found mathjax can do this. But when I write some example in my markdown file, it doesn\'t show the correct equations:

I have added this in

相关标签:
10条回答
  • 2020-11-29 15:09

    If just wanted to show math in the browser for yourself, you could try the Chrome extension GitHub with MathJax. It's quite convenient.

    0 讨论(0)
  • 2020-11-29 15:11

    But github show nothing for the math symbols! please help me, thanks!

    GitHub markdown parsing is performed by the SunDown (ex libUpSkirt) library.

    The motto of the library is "Standards compliant, fast, secure markdown processing library in C". The important word being "secure" there, considering your question :).

    Indeed, allowing javascript to be executed would be a bit off of the MarkDown standard text-to-HTML contract.

    Moreover, everything that looks like a HTML tag is either escaped or stripped out.

    Tell me how to show math symbols in general github markdown.

    Your best bet would be to find a website similar to yuml.me which can generate on-the-fly images from by parsing the provided URL querystring.

    Update

    I've found some sites providing users with such service: codedogs.com (no longer seems to support embedding) or iTex2Img. You may want to try them out. Of course, others may exist and some Google-fu will help you find them.

    given the following markdown syntax

    ![equation](http://www.sciweavers.org/tex2img.php?eq=1%2Bsin%28mc%5E2%29&bc=White&fc=Black&im=jpg&fs=12&ff=arev&edit=)
    

    it will display the following image

    equation http://www.sciweavers.org/tex2img.php?eq=1%2Bsin%28mc%5E2%29&bc=White&fc=Black&im=jpg&fs=12&ff=arev&edit=

    Note: In order for the image to be properly displayed, you'll have to ensure the querystring part of the url is percent encoded. You can easily find online tools to help you with that task, such as www.url-encode-decode.com

    0 讨论(0)
  • 2020-11-29 15:12

    Markdown supports inline HTML. Inline HTML can be used for both quick and simple inline equations and, with and external tool, more complex rendering.

    Quick and Simple Inline

    For quick and simple inline items use HTML ampersand entity codes. An example that combines this idea with subscript text in markdown is: hθ(x) = θo x + θ1x, the code for which follows.

        h<sub>&theta;</sub>(x) = &theta;<sub>o</sub> x + &theta;<sub>1</sub>x
    

    HTML ampersand entity codes for common math symbols can be found here. Codes for Greek letters here.

    While this approach has limitations it works in practically all markdown and does not require any external libraries.

    Complex Scalable Inline Rendering with LaTeX and Codecogs

    If your needs are greater use an external LaTeX renderer like CodeCogs. Create an equation with CodeCogs editor. Choose svg for rendering and HTML for the embed code. Svg renders well on resize. HTML allows LaTeX to be easily read when you are looking at the source. Copy the embed code from the bottom of the page and paste it into your markdown.

    <img src="https://latex.codecogs.com/svg.latex?\Large&space;x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}" title="\Large x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}" />
    

    Expressed in markdown becomes

    ![\Large x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}](https://latex.codecogs.com/svg.latex?\Large&space;x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}) 
    

    \Large x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}

    This combines this answer and this answer.

    GitHub support only somtimes worked using the above raw html syntax for readable LaTeX for me. If the above does not work for you another option is to instead choose URL Encoded rendering and use that output to manually create a link like:

    \Large x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}

    ![\Large x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}](https://latex.codecogs.com/svg.latex?x%3D%5Cfrac%7B-b%5Cpm%5Csqrt%7Bb%5E2-4ac%7D%7D%7B2a%7D)
    

    This manually incorporates LaTex in the alt image text and uses an encoded URL for rendering on GitHub.

    Multi-line Rendering

    If you need multi-line rendering check out this answer.

    0 讨论(0)
  • 2020-11-29 15:13

    Regarding tex→image conversion, the tool LaTeXiT produces much higher quality output. I believe it is standard in most TeX distributions but you can certainly find it online if you don't already have it. All you need to do is put it in the TeX, drag the image to your desktop, then drag from your desktop to an image hosting site (I use imgur).

    0 讨论(0)
  • 2020-11-29 15:14

    I used the following in the head of mark down file

    <script type="text/javascript" async
    src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js? 
    config=TeX-MML-AM_CHTML"
    </script>
    

    Then typed the following mathjax statement
    $$x_{1,2} = \frac{-b \pm \sqrt{b^2-4ac}}{2b}.$$
    It worked for me

    0 讨论(0)
  • 2020-11-29 15:20

    One other work-around is to use jupyter notebooks and use the markdown mode in cells to render equations.

    Basic stuff seems to work perfectly, like centered equations

    \begin{equation}
    ...
    \end{equation}
    

    or inline equations

    $ \sum_{\forall i}{x_i^{2}} $
    

    Although, one of the functions that I really wanted did not render at all in github was \mbox{}, which was a bummer. But, all in all this has been the most successful way of rendering equations on github.

    0 讨论(0)
提交回复
热议问题