How do I change LaTeX to MathML using MathJax in Node.js? - node.js

I'm trying to render math equations from user input server side using MathJax in Node.js. I'm using a separate library (mathjs) to turn the input into LaTeX, but after spending an hour looking at the MathJax docs I'm no closer to turning the LaTeX into MathML.
I'm assuming I'd be using the mathjax package on NPM, and then use the MathJax.InputJax and MathJax.OutputJax classes to do the processing, but I've got no idea how to put everything together.
(In case anyone is wondering, I'm using a CSS file to polyfill MathML, rather than load MathJax in the browser and cause a delay while the processing happens.)

You want to use MathJax-node for this. It is set up to run MathJax server-side. There are a number of example command-line tools in the bin directory. You could also hook up a web service to handle the conversion. Tim Arnold made one available as mathjax-server on npmjs.com.

Related

How To Handle File Input

I am working on a tutorial website using MERN, whereon I will be displaying tutorials on pretty much anything I know well, and new things that I learn. The backend and frontend work fine. I just don't know what to do with regards to the tutorial's body in the submission form. The kind of tutorials that I want to add will have a combination of images, specially highlighted text(i.e. code examples), and text. So, I was thinking maybe I can upload all that as a word document and have it be parsed before it is saved in the database. Is this the way to go? Are there useful libraries that can make this easier to handle?
I suspect you'll like markdown.
Markdown is a simple markup language where you enter plain old text but can render the text with styles. There are many libraries (especially for react and node) that will convert your markdown to html, and it can be easily extended to style code snippets, images, and even react components.

Render small LaTeX-Snippets on GTK GUI using Rust

Problem
I am developing a Rust program which has a GTK3 GUI using the given rust-gtk-binding.
The program should be cross-platform (at least Linux and Windows).
The GUI should be able to show custom plaintexts and small LaTeX-snippets to allow the use math environments (small means sizes of one formula as an element to display).
Therefore, I need a way to convert LaTeX-code into something which can be displayed by the GUI.
Ideas and their problems
I can see two approaches displaying LaTeX:
Compile the LaTeX-source into pdf and then into some image type. It should be possible to use Ghostscript to get the image. But I do not know how to generate the pdf in a way which is lightweight (does not include rather large packages like miktex) and cross-platform. This option could also be overkill as there is no need to dynamically download special packages, a good math support would be sufficient. The positive side is that rendering an image in GTK should be easy.
Use KaTeX which should be sufficient for math environments. I was able to install matching crates and generate HTML source from some formulas. But here it becomes difficult to render the result as GTK has no native way for displaying HTML. As it would be difficult to integrate a HTML-engine into the GUI it would be optimal to find a tool which is able to render HTML to an image type which then can be displayed.
Now I have two ways both using an intermediate step where for common LaTeX the first step is difficult and for KaTeX the second step displays a problem. For both approaches' difficult steps I could not find any feasible solution.
Are there any libraries or similar I could not find or are there any different approaches?
It would be perfectly sufficient to be able to render a single formula, I just want to avoid such massive and difficult overkills like using a complete LaTeX compiler or half a browser to render HTML.
After searching and evaluating many more approaches I got a solution which is kind of good while also having some major drawbacks:
First of all, I use TinyTex as LaTeX environment. I did not restrict the use of LaTeX to e.g. math environments. TinyTex offers support for major platforms while being lightweight and portable. Additional LaTeX packages have to be installed manually which allows me to decide which ones are being shipped with my application.
The negative side is that while TinyTex is lightweight for a LaTeX environment it still is rather big for its purpose here (about 250MB).
I installed the required packages to use \documentclass[preview]{standalone} to get an already cropped pdf.
Afterwards I use Ghostscript to get a png-image for the generated pdf. I did not use language bindings and instead just went std::process::Command.
The following lines should be sufficient to convert test.tex into test.png with the portable TinyTex installation and Ghostscripts gswin64c.exe present in subfolders of the project's directory under Windows: (As TinyTex and Ghostscript also exist for other OS the given example can easily be changed to work on other systems)
use std::process::Command;
fn main() {
let output = Command::new("TinyTex\\bin\\win32\\pdflatex.exe")
.args(&["test.tex"])
.output()
.expect("Some error message 1");
println!("{}", String::from_utf8(output.stdout).unwrap());
let output = Command::new("gs\\gswin64c.exe")
.args(&[
"-dNOPAUSE",
"-dBATCH",
"-sDEVICE=png16m",
"-r1000",
"-sOutputFile=test.png",
"test.pdf",
])
.output()
.expect("Some error message 2");
println!("{}", String::from_utf8(output.stdout).unwrap());
}
Of course this is no particulary good and useful code at this stage but it shows how to proceed with the given problem and I wanted to leave it here in case anyone with a similar problems finds this post.

How to config MathJax for reveal.js when running offline?

In the reveal.js documentation, the MathJax section says that normally, MathJax is loaded from a remote server, and if you want to use MathJax offline you'll need to download a copy of the library and adjust the mathjax configuration value.
The configuration I'm trying is
math: {
mathjax: 'MathJax/MathJax.js',
config: 'TeX-AMS_HTML-full'
}
where MathJax/MathJax.js is the relative address of the MathJax.js file in a clone of the MathJax repository I have locally on my computer.
When I first load a page in the presentation with equations on it (or reload it by pressing F5 in the browser), I first see the LaTeX code for the equations for a short while, before seeing a rendering that looks very basic and not very nice but still okay, but then finally I see what looks like a nice rendering of the equations, but with thick frames around every character in the equations which completely mess up everything.
How should MathJax be configured properly, so that it looks identical to when MathJax is loaded from a remote server?

Generate HTML from MathJax code in a batch script

I know how to use MathJax to convert TeX commands in a web page to mathematical formulae. The MathJax scripts would search the page for TeX commands and convert them inline to HTML statements.
Is there a way to do this as a form of pre-processing? In other words, I have some text or HTML files on my harddisk that contain raw TeX commands. I'd like to use MathJax to convert them to HTML, so that they can be viewed without having the MathJax scripts.
The reason I need this is that these pages are very long and contain many, many TeX statements. MathJax is fast, but it's not fast enough for such huge pages, so I need to preprocess them.
Thanks for any hints.
MathJax-node provides APIs for using MathJax in nodejs, thus enabling this kind of preprocess. There are examples in the repository for handling HTML fragments.
The SVG output can be used this way but the HTML-CSS output cannot because it is very client dependent.
However, the new CommomHTML output -- which has been completed in MathJax v2.6, currently in beta -- will be usable this way. It will be integrated into mathjax-node once v2.6 is out of beta.

How can I minify html, css, js/jquery and ruby code inside Sublime Text 3?

Running Windows 7. What is the best Sublime Text 3 plugin to do this, and maybe beautify the code as well.
May be useful, this shortcut will erase all line breaks of the selected text
Ctrl + J
Notice this is not really minify, since it doesn't consider the code language.
You may have already found something you like by now, but I just ran across this same need and have tried out two plugins: Minifier and Clientside. Clientside has more features like linting and beautifying but is only compatible up to ST2 (according to its Package Control page), whereas Minifier should be compatible with ST3.
Updated 8. 4. 2015 as many things have changed
I've been looking for such ST3 plugin as well. I've tried Sublime HTML5 Minifier by geekpradd and Minify by Zoltan, both seem as great options. See their pros and cons.
HTML5 Minifier
Only minifies, cannot beautify (so far)
Doesn't restructure your CSS or JavaScript files, only removes white space and comments
Not as effective as Minify, but keeps the code readable after beautification
Works for HTML, CSS and JS without trouble
Can minify the code in the current view without creating new files or saving anything
Easy installation, doesn't require Node.js or anything else
Has a typo in console - HTML Minfier instead of HTML Minifier. But maybe it's on purpose :)
Minify
Minifies and beautifies
Restructure your CSS and JavaScript files, renames JS variables, function names etc.
Super effective, smallest file sizes possible, but the code is changed by the minification process
Works for HTML, CSS and JS without trouble, also should support SVG (haven't tested)
Can't minify the code in the current view without creating new files or saving anything, minification always creates a new .min. or .beatified. file in the same directory
A bit more complicated installation, requires Node.js and some other Node.js CLI apps
Which plugin is better?
There is no straightforward answer for that. Minify is more effective, so as long as all you care about is the smallest file size possible, Minify is your choice. I personally use both of these as in some cases, HTML5 Minifier may be a better choice in some cases.
I'm just hoping that Zoltan, the Minify developer, will add the crucial functionality to minify the current buffer without creating or saving any file just like geekpradd did.
I know it is an old question, but here is my answer anyway:
I recommend you to visit the excellent Package Control website and perform a search for the keyword "minify"
You will get a list of various packages for the Sublime Text editor which provide the requested functionality (minifying / beautifying).
Disclosure: I am the author of one of the packages listed on the Package Control website: Minify.
I am not saying that my package is best for everyone, but Minify is the package I use, obviously.
Note: I'm also on Windows 7. My Minify package works in both Sublime Text 2 and Sublime Text 3. Once installed, it works offline, so you can even minify your files while you are not connected to the Internet.

Resources