Giter Club home page Giter Club logo

vscode-math-to-image's Introduction

logo

Math » Image

📐 We can help you render LaTeX math equations in any Markdown file!

Azure DevOps builds (branch) Visual Studio Marketplace Visual Studio Marketplace Downloads Visual Studio Marketplace Rating (Stars)

This is a VS Code extension to help you convert a standard LaTeX math equation like $E=mc^2$ to an image like (remote) or a local SVG which can be embedded inside Markdown files or websites that doesn't support rendering LaTeX yet. (That's you GitHub!)

Read more about Math to Image here:

Table of Contents

Demo

Features

There are two modes in which we will render your math equations in Markdown:

  • Locally (with MathJax and sourcing relative SVG), and...
  • Remotely (with GitHub's LaTeX rendering server).

Rendering remotely

This is actually a hack. GitHub won't render LaTeX equations inside normal places like GitHub README, but it can render them in Jupyter notebooks, so we took advantage of this feature, utilizing GitHub's equation rendering server to embed SVG equations in GitHub. (See here for details: A hack for showing LaTeX formulas in GitHub markdown.)

Basically we can convert a standard LaTeX math equation like the Gaussian Normal Distribution...

$$
P(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{\frac{-(x-\mu)^2}{2\sigma^2}}
$$

... to a rendered image tag with the help of GitHub's math rendering server:

<div align="center"><img style="background: white;" src="https://render.githubusercontent.com/render/math?math=P(x)%20%3D%20%5Cfrac%7B1%7D%7B%5Csigma%5Csqrt%7B2%5Cpi%7D%7D%20e%5E%7B%5Cfrac%7B-(x-%5Cmu)%5E2%7D%7B2%5Csigma%5E2%7D%7D"></div>

In addition to GitHub's rendering server, we also newly added support for CodeCogs' rendering server:

<div align="center"><img style="background: white;" src="https://latex.codecogs.com/svg.latex?P(x)%20%3D%20%5Cfrac%7B1%7D%7B%5Csigma%5Csqrt%7B2%5Cpi%7D%7D%20e%5E%7B%5Cfrac%7B-(x-%5Cmu)%5E2%7D%7B2%5Csigma%5E2%7D%7D"></div>

Rendering locally

Not everywhere accept external SVGs. To circumvent this type of scenario, we can render math equations directly to local SVGs (with MathJax), and embed these local SVGs into our Markdown as a workaround.

We can convert the same LaTeX math equation:

$$
P(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{\frac{-(x-\mu)^2}{2\sigma^2}}
$$

To a local SVG like: svg/e40qQ5G9jw.svg, which will be saved to a dedicate folder called svg, and sourced inside the Markdown file that requires math-embedding.

🌸 NOTE: There used to be a demo SVG here, but Visual Studio Marketplace won't allow us to add local SVGs inside their README.

If you are reading this on GitHub, you can see that both of these methods work when we need to add math equations to READMEs or other Markdown files on GitHub.

See examples for more math equation rendering scenarios, i.e, inline math, aligned environments...

Extension Settings

You can specify the path to save the locally rendered SVG image. The settings are self-explanatory.

  • vscode-math-to-image.svgSavePath:
    • Current file directory: Generated SVG files will be put in a folder under current file's directory.
    • Current workspace directory: Generated SVG files will be put in a folder under current workspace directory.
  • vscode-math-to-image.remoteRenderEngine:
    • GitHub: Equations will be rendered with GitHub's rendering engine remotely.
    • CodeCogs: Equations will be rendered with CodeCogs' rendering engine remotely.
  • vscode-math-to-image.inlineSvgStyle: Optional style for rendered inline SVG equations. Defaults to transform: translateY(0.1em); background: white;. Note: Not supported with Markdown-insertionType.
  • vscode-math-to-image.displaySvgStyle: Optional style for rendered display SVG equations. Defaults to background: white;. Note: Not supported with Markdown-insertionType.
  • vscode-math-to-image.insertionType: Choose whether to insert the rendered equations as HTML (default) or Markdown. Note that Markdown doesn't support styling.

Change Log

For version updates and bug fixes, please see: CHANGELOG.


📐 Math » Image © TeamMeow. Released under the MIT License.

Authored and maintained by TeamMeow members.

🦁 We build things that go "meow" · @GitHub · @Members

vscode-math-to-image's People

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

vscode-math-to-image's Issues

Generate local svg with white background

Hi,

first, congrats for this amazing tool! :)

Since I work with dark themed VSC but the browser setting is user dependent, it would be nice to add the option to allow a white background in the locally saved SVG to always have contrast for light and dark setting of browser or VSC.

Best

Allow choice of SVG rendering engine

Great extension, just what I needed for Markdown. Would it possible to include other rendering engines? For example, SVG rendering from codecogs in addition to GitHub. Don't have a lot of time on my hands right now, but I could look into contributing this if it seems like a good addition. Changing the engine could be a dropdown in the extension settings.

Customize markdown image format instead of HTML

I would suggest to set the default inset code block using markdown or HTML format by customization,
because the the current HTML format may looks wired in other render engine, like Typora or Github web view.

For example, $n_i^t$: the number of.. will be to
<!-- $n_i^t$ --> <img src="https://render.githubusercontent.com/render/math?math=n_i%5Et">: the number of....
It looks good in vscode, but a new line will be introduced in Github web view, somewhat like
"$n_i^t$
: the number of...". The comment <!-- $n_i^t$ --> can not be hidden in Typora.

The markdown image format,
![$n_i^t$](https://render.githubusercontent.com/render/math?math=n_i%5Et): the number of...,
will not have this problem.

Render in dark mode

The svg saved doesn't work for dark mode in GitHub pages. Is there a workaround?

Screenshot 2021-08-31 at 8 48 46 AM

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.