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

后端 未结 10 1520
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: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θ(x) = θo x + θ1x
    

    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.

    
    

    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.

提交回复
热议问题