Can I Use MathJax In Gitbook.com - mathjax

I have one gitbook ebook in gitbook.com:here.But the mathjax plugin perform well in editor while the math expression can't seen in online version? is there any setting i need to set?

Math & TeX
GitBook supports math equations and TeX thanks to plugins. There are currently 2 official plugins to display math:
mathjax and katex.
Enable a math plugin:
To enable math support, you need to add one of these plugins to your
book.json:
{
"plugins": ["mathjax"]
}
Differences between MathJax and KaTeX
The mathjax and katex plugins are different implementations of TeX
equation rendering, backed by their respective Open Source libraries:
KaTeX and MathJax. MathJax supports the entire TeX syntax, but the
output is not perfect on ebooks (PDF, ePub and Mobi). KaTeX renders
perfectly on all formats (web and ebooks), but doesn't yet support all
the syntax.
Add math to your content:
Here is some inline math: $$a \ne 0$$
A block of math should begin with a new line:
Here is a block of math:
$$
a \ne 0
$$
From: http://help.gitbook.com/format/math.html

Related

Mathjax strangely render back-tick in code blocks

I have a TCL code gist embedded in my own website. This page uses MathJax 2.7.5 configed with "TeX-MML-AM_CHTML". However, Mathjax strangely rendered the code between back-ticks in the comments of the code. For example, one line in the source code is (can be found here in gist):
# `testPrintFlag` : integer
The letters "int" were rendered by MathJax to a integration symbol (see here).
The gist code block appears like this., but the correct one should be like this. I'm wondering how I can fix this.
Thanks!
The configuration file TeX-MML-AM_CHTML includes the AsciiMath input processor, and AsciiMath uses back-ticks as its math delimiters. So all your back-tacks will cause AsciiMath to process their contents as math. If you aren't using AsciiMath input, you probably want to use a different configuration format, like just TeX-AMS_CHTML which only does TeX input (not MathML and AsciiMath, as in your original). That will be faster as well as it is a smaller file.
If you are using AsciiMath input, then you could configure it to use a different delimiter. See the documentation for details.
You could also configure MathJax to skip containers with certain class names (e.g., class="gist"). See the ignoreClass option for the asciimath2jax preprocessor at the link above. There is a similar one for the tex2jax preprocessor.

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 do I change LaTeX to MathML using MathJax in 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.

Mathjax: how to deal with this strange behavior?

I am using the markdown editor and I have loaded Mathjax in all pages of my website.
I have realized that this line of latex works well:
$(u_1)$
However, this one does not work (basically latex does not work):
$(u_1,u_2)$
In order to make this work, I have to write something like this:
$(u\_1,u\_2)$
I have a similar problem here. This does not work:
$$M=\left(\begin{array}{cc}
a & b \\
c & d \\
\end{array}\right)$$
But this works:
$$M=\left(\begin{array}{cc}
a & b \\\\
c & d \\\\
\end{array}\right)$$
This is a common issue of mixing LaTeX-input with Markdown. From the MathJax documentation:
There cannot be HTML tags within the math delimiters (other than <br>) as TeX-formatted math does not include HTML tags.
And later:
Another source of difficulty is when MathJax is used in content management systems that have their own document processing commands that are interpreted before the HTML page is created. For example, many blogs and wikis use formats like Markdown to allow you to create the content of you pages. In Markdown, the underscore is used to indicate italics, and this usage will conflict with MathJax’s use of the underscore to indicate a subscript. Since Markdown is applied to the page first, it will convert your subscripts markers into italics (inserting tags into your mathematics, which will cause MathJax to ignore the math).
As other answers on SO (see the link at the top) point out, some markdown parsers are more aware of TeX-like syntax than others.

Getting R plots into LaTeX?

I'm a newbie to both R and LaTeX and have just recently found how to plot a standard time series graph using R and save it as a png image. What I'm worried about is that saving it as an image and then embedding it into LaTeX is going to scale it and make it look ugly.
Is there a way to make R's plot() function output a vector graphic and embed that into LaTeX? I'm a total beginner in both so please be gentle :) Code snippets are highly appreciated!
I would recommend the tikzDevice package for producing output for inclusion in LaTeX documents:
http://cran.r-project.org/web/packages/tikzDevice/index.html
The tikzDevice converts graphics produced in R to code that can be interpreted by the LaTeX package tikz. TikZ provides a very nice vector drawing system for LaTeX. Some good examples of TikZ output are located at:
http://www.texample.net/
The tikzDevice may be used like any other R graphics device:
require( tikzDevice )
tikz( 'myPlot.tex' )
plot( 1, 1, main = '\\LaTex\\ is $\\int e^{xy}$' )
dev.off()
Note that the backslashes in LaTeX macros must be doubled as R interprets a single backslash as an escape character. To use the plot in a LaTeX document, simply include it:
\include{path/to/myPlot.tex}
The pgfSweave package contains Sweave functionality that can handle the above step for you. Make sure that your document contains \usepackage{tikz} somewhere in the LaTeX preamble.
http://cran.r-project.org/
The advantages of tikz() function as compared to pdf() are:
The font of labels and captions in your figures always matches the font used in your LaTeX document. This provides a unified look to your document.
You have all the power of the LaTeX typesetter available for creating mathematical annotation and can use arbitrary LaTeX code in your figure text.
Disadvantages of the tikz() function are:
It does not scale well to handle plots with lots of components. These are things such as persp() plots of large matricies. The shear number of graphic elements can cause LaTeX to slow to a crawl or run out of memory.
The package is currently flagged as beta. This means that the interface or functionality of the package is subject to change if the authors find a compelling reason to do so.
I should end this post by disclaiming that I am an author of both the tikzDevice and pgfSweave packages so my opinion may be biased. However, I have used both packages to produce several academic reports in the last year and have been very satisfied with the results.
Shane is spot-on, you do want Sweave. Eventually.
As a newbie, you may better off separating task though. For that, do this:
open a device: pdf("figures/myfile.pdf", height=6, width=6).
plot your R object: plot(1:10, type='l', main='boring') -- and remember that lattice and ggplot need an explicit print around plot.
important: close your device: dev.off() to finalize the file.
optional: inspect the pdf file.
in LaTeX, use usepackage{graphicx} in the document header, use
\includegraphics[width=0.98\textwidth]{figures/myfile} to include the figure created earlier and note that file extension is optional.
run this through pdflatex and enjoy.
You might want to consider using Sweave. There is a lot of great documentation available for this on the Sweave website (and elsewhere). It has very simple syntax: just put your R code between <<>>= and #.
Here's a simple example that ends up looking like this:
\documentclass[a4paper]{article}
\title{Sweave Example 1}
\author{Friedrich Leisch}
\begin{document}
\maketitle
In this example we embed parts of the examples from the
\texttt{kruskal.test} help page into a \LaTeX{} document:
<<>>=
data(airquality)
library(ctest)
kruskal.test(Ozone ~ Month, data = airquality)
#
which shows that the location parameter of the Ozone
distribution varies significantly from month to month. Finally we
include a boxplot of the data:
\begin{center}
<<fig=TRUE,echo=FALSE>>=
boxplot(Ozone ~ Month, data = airquality)
#
\end{center}
\end{document}
To build the document, you can just call R CMD Sweave file.Rnw or run Sweave(file) from within R.
This is a dupe of a question on SO that I can't find.
But:
http://r-forge.r-project.org/projects/tikzdevice/ -- tikz output from r
and
http://www.rforge.net/pgfSweave/ tikz code via sweave.
Using tikz will give you a look consistent with the rest of your document, plus it will use latex to typeset all the text in your graphs.
EDIT
Getting LaTeX into R Plots

Resources