Coder Social home page Coder Social logo

latexmathjax's Introduction

LaTeXMathJax

A simple LaTeX to HTML+CSS+MathJax translator.

To use this script client-side, simply download the files latexmathjax.js, latexmathjax.css and test.html to a folder that contains a LaTeX file. Then rename the test.html file so that it has the same name as your LaTeX file, but with the extension ".html".

Then open the HTML file from a browser. The result should be a reasonable approximation of the PDF file that pdflatex would have produced. If there are some issues (yes, this is quite possible since LaTeX is far too large to translate with a small script like this) then look at the latexmathjax.js file and the latexmathjax.css file to see if the issues can be fixed easily.

The test.html file (see below) just loads the script and CSS. The script then loads the LaTeX file and does simple regular expression replacements to translate it from LaTeX to HTML. The CSS file is used to style the elements and to number sections, subsections, lemmas, theorems, etc. Finally MathJax is invoked to display the math formulas.

Since each LaTeX construct is handled by a particular regular expression, the latexmathjax.js file is quite easy to modify and adapt to a larger subset of LaTeX or to translate some nonstandard features or packages.

The test.html file looks as follows:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="latexmathjax.js"></script>
    <link rel="stylesheet" type="text/css" href="latexmathjax.css" />
  </head>
  <body>
    <pre id="ltx" class="LaTeX"></pre>
  </body>
</html>

If you prefer, the LaTeX code can also be manually inserted into the <pre> tag, but then it cannot be processed with pdflatex and simultaneaously viewed in a browser.

Here are some sample pages:

test.html

A longer file

A chapter on functions

Note: LaTeXMathJax is designed to automatically load MathJax (from a cdn). Hence MathJax should not also be loaded at the top of the html file that loads LaTeXMathJax.js since this can cause conflicts preventing MathJax from loading properly.

latexmathjax's People

Contributors

jipsen avatar

Watchers

James Cloos avatar

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.