# Ways to render latex-like formula like mathjax in Emacs

Assume one has a latex-like formula as the following which is usually rendered by mathjax in webpages supporting it (like wordpress):

For all positive integers {n} one has \displaystyle \frac{1}{n+1} \leq \frac{1}{n}


What are different ways to render these formulas like mathjax within Emacs?

To be precise the aim is that mathjax to render in the Emacs buffer (like latex preview via AUCTeX). Other solutions without using mathjax is also welcomed.

• Note, that the formulas should be identified by some delimiters, e.g., $$...$$ or $...$. Jan 10, 2018 at 0:00
• @Tobias Actually I had copied the formulas from a wordpress page. I changed the sentence. Hence the formulas didn't carry $$...$$ or $...$.
– Name
Jan 10, 2018 at 5:35

texfrag can be used for rendering TeX fragments in stackexchange pages (e.g., https://math.stackexchange.com) presented with sx. It uses the AucTeX preview package for the job. Therefore, you need a working AucTeX preview (inclusive a working LaTeX).

Several other major modes are supported, e.g., html-mode for MathJax fragments in html pages and prog-mode for formulas in doxygen comments.

In the comments you asked me to demonstrate texfrag-mode for the text

For all positive integers {n} one has \displaystyle \frac{1}{n+1} \leq \frac{1}{n}


in the scratch buffer.

The major mode of *scratch* is lisp-interaction-mode which is derived from prog-mode. Texfrag recognizes doxygen style formulas in comments in major modes derived from prog-mode by default. Therefore your line should be contained in a comment and the formulas in your line should be delimited by the doxygen equation delimiters \f$.  ;; For all positive integers \f$n\f$one has \f$\displaystyle \frac{1}{n+1} \leq \frac{1}{n}\f$ There is a recent bugfix of texfrag-mode that avoids an infinite iteration when the buffer ends in a comment. If you don't have that corrected version please make sure that the comment is not the last thing in the buffer. (Just add a newline.) Note, that you need some identification of TeX-formulas. For an instance MathJax formulas usually are identified by the boundaries  or $ \$.

texfrag-mode is quite flexible. You can add your own setup for a given major-mode to texfrag-setup-alist.

• Thanks, I installed texfrag from melpa. Any hint for using it? Assume that I have For all positive integers {n} one has \displaystyle \frac{1}{n+1} \leq \frac{1}{n} in scratch buffer. By calling M-x texfrag-mode nothing happens. Do I miss something?
– Name
Jan 9, 2018 at 19:55
• Texfrag doesn't use mathjax to render equations in-place, right? In the backstage it put the equations in .tex files, compile them into images, and then place the images in emacs buffer. I don't think this is what the op asked for.
– Alex
Jan 14, 2018 at 22:05
• @Alex You wrote: "Texfrag doesn't use mathjax to render equations in-place, right? In the backstage it put the equations in .tex files, compile them into images, and then place the images in emacs buffer." Yes that is right. 1st: How do you want to use MathJax to render the equations inplace? emacs is not an html engine and does not run Java. 2nd: Please reread the question. The OP demanded: "Other solutions without using mathjax are also welcomed. " Jan 14, 2018 at 22:43
• @Tobias Ok so we agree that texfrag doesn't use mathjax. I think you should explicitly say that in your answer.
– Alex
Jan 14, 2018 at 23:25
• @Alex I've added the requirements. Jan 15, 2018 at 8:38

As of now no package in emacs use mathjax rendering in-place. This is an open question, since mathjax is javascript.

On the other hand, there are several ways to display math in the buffer. The way these methods typically works is to take your equation, use latex engine to compile them into pictures, and then insert the pictures in your buffer. A common package to use is Preview TeX; org-mode ships with tex-rendering commands; there are more ways to it for example discussed here How to preview LaTeX in Emacs?

From my personal experience, these solutions all suffer from: 1. speed, it's really slow to compile all equations to separate image files on your hard drive. 2. extra files, this process usually leaves a lot of files on your disk. You can maybe do some auto cleaning but its still extra efforts.

As a digression, using mathjax to render equations in-place is possible in other text editors like atom. For example, I use atom + markdown preview plus package to take math notes. Not sure if this is what you look for though.