TeX - LaTeX Asked on November 9, 2021
How should I incorporate TeX in a website to render mathematical formulas? If there are multiple ways, what is the easiest way?
Since HTML does not support embedded LaTeX, converting the LaTeX to MathML for use with MathJax is an acceptable means, however the problem then becomes one of converting the LaTeX to MathML and seamlessly converting the MathML for use by the HTML browser.
The translation of LaTeX to MathML for use by MathJax can be done using the online WIRIS editor.
a. Just past the LaTeX in the LaTeX window and click apply.
b. Then copy the converted MathML from the MathML window into the HTML.
The MathML can then be seamlessly converted for use by the browser by use of the MathJax service with the adding of the following script to the HTML head.
<head>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG">
</script>
</head>
TL;DR
The WIRIS editor is also know as a formula editor or equation editor.
Note that the WIRIS editor can also do
Answered by Guy Coder on November 9, 2021
The free and open source Foswiki platform have a LatexModePlugin that allow insert easily chunks of LaTeX code within the wiki text, that are rendered as .png or .gif images. How it work is well explained in the above link.
There are also a MathModePlugin but as the name suggest only implement rendering images of mathematics formulas.
Answered by Fran on November 9, 2021
There is also the possibility to use LateXMathML, which converts LaTeX Math Mode to MathML with JavaScript only. No serverside installation needed.
Answered by moonglum on November 9, 2021
I'll add two math rendering alternatives only for reference purposes. Personally, I prefer to stick with either MathML or MathJaX.
Both MimeTeX and MathTeX are cgi
programs written in C.
MimeTeX, licensed under the gpl, lets you easily embed LaTeX math in your html pages. It parses a LaTeX math expression and immediately emits the corresponding
gif
image, rather than the usual TeXdvi
. And mimeTeX is an entirely separate little program that doesn't use TeX or its fonts in any way. It's just onecgi
that you put in your site'scgi-bin/
directory, with no other dependencies. So mimeTeX is very easy to install. And it's equally easy to use. Just place an html<img>
tag in your document wherever you want to see the corresponding LaTeX expression. For example,
<img src="../cgi-bin/mimetex.cgi?f(x)=int_{-infty}^xe^{-t^2}dt"
alt="" border=0 align=middle>
immediately generates the corresponding gif image on-the-fly, displaying wherever you put that
<img>
tag. MimeTeX doesn't need intermediatedvi-to-gif
conversion, and doesn't create separategif
files for each converted expression. (But you can cache images with mimeTeX's-DCACHEPATH="path/"
compile option.)
MathTeX, licensed under the gpl, is a
cgi
program that lets you easily embed LaTeX math in your own html pages, blogs, wikis, etc. It parses a LaTeX math expression and immediately emits the correspondinggif
(orpng
) image, rather than the usual TeXdvi
. So just place an html<img>
tag in your document wherever you want to see the corresponding LaTeX expression. For example,
<img src="/cgi-bin/mathtex.cgi?f(x)=int_{-infty}^xe^{-t^2}dt"
alt="" border=0 align="middle">
immediately generates the corresponding
gif
, displaying wherever you put that<img>
tag.
mathTeX dependencies
MathTeX's uses the
latex
anddvipng
programs, along with all necessary fonts, etc, from your TeX distribution. Occasionally, you may need to downloaddvipng
separately. If you can't, or don't want to, installdvipng
, then you may optionally specify the–DDVIPS
and–DCONVERT
switches when compiling mathTeX. Then mathTeX usesdvips
from your TeX distribution, and convert from the ImageMagick package, instead ofdvipng
.
[...]
These dependencies - always
latex
and eitherdvipng
ordvips/convert
- must all be installed on your server before you can run mathTeX. Ask your ISP or sysadmin if you have any questions or problems installing them. Or see mimeTeX if you can't install them.
Answered by Paulo Cereda on November 9, 2021
latex.exe
or pdflatex.exe
and other tools to get PDF output. This workflow is not for a newbie because you have to know a programming language for writing server script. If you are a C# user and know ASP.NET MVC, the following incomplete code snippet may help you to get the rough idea. But it has not been optimized and analyzed for any security vulnerability. [HttpPost]
[ValidateAntiForgeryToken]
[Authorize(Roles = "Administrators")]
public ActionResult Create(Problem problem )
{
ViewBag.Message = "LaTeX to PDF Converter";
string dir = Server.MapPath("~/Content/");
name = Path.GetRandomFileName() + MvcApplication.rnd.Next(int.MaxValue);
string inputpath = Path.Combine(dir, name + ".tex");
using (StreamWriter sw = new StreamWriter(inputpath))
{
sw.Write(problem.Description);
}
Process p = new Process();
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(p_Exited);
p.StartInfo.Arguments = "-interaction=nonstopmode " + inputpath;
p.StartInfo.WorkingDirectory = dir;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "pdflatex.exe";
p.Start();
p.WaitForExit();
if (p.ExitCode == 0)
{
TempData["outputpath"] = Url.Content("~/Content/" + name + ".pdf");
return RedirectToAction("Result");
}
else
{
ModelState.AddModelError("Description", "Syntax Error!");
return View(problem);
}
}
void p_Exited(object sender, EventArgs e)
{
Process p = sender as Process;
string dir = Server.MapPath("~/Content/");
using (StreamWriter sw = new StreamWriter(Path.Combine(dir, "log.txt"), true))
{
sw.WriteLine(DateTime.Now);
}
var filenames = Directory.GetFiles(dir, name + "*");
for (int x = 0; x < filenames.Length; x++)
{
if (Path.GetExtension(filenames[x]) != ".pdf" || p.ExitCode != 0)
System.IO.File.Delete(filenames[x]);
}
}
You need to create a separate process to invoke pdflatex
to compile the input file.
Answered by xport on November 9, 2021
here you find an example for MathJaX:
http://latex.userpage.fu-berlin.de/math.html
the source code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Mathedemo</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\(','\)']]}});
</script>
<script type="text/javascript"
src="http://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</head>
<body>
<h2>Math in TeX notation</h2>
When $a ne 0$, there are two solutions to (ax^2 + bx + c = 0) and they are
$$x = {-b pm sqrt{b^2-4ac} over 2a}.$$
$$ begin{array}{rcll}
y & = & x^{2}+bx+c\
& = & x^{2}+2timesdfrac{b}{2}x+c\
& = & underbrace{x^{2}+2timesdfrac{b}{2}x+left(frac{b}{2}right)^{2}}-
{left(dfrac{b}{2}right)^{2}+c}\
& & qquadleft(x+{dfrac{b}{2}}right)^{2}\
& = & left(x+dfrac{b}{2}right)^{2}-left(dfrac{b}{2}right)^{2}+c
& left|+left({dfrac{b}{2}}right)^{2}-cright.\
y+left(dfrac{b}{2}right)^{2}-c & = & left(x+
dfrac{b}{2}right)^{2} & left|strut(textrm{vertex form})right.\
y-y_{S} & = & (x-x_{S})^{2}\
S(x_{S};y_{S}) & ,textrm{or},
& Sleft(-dfrac{b}{2};,left(dfrac{b}{2}right)^{2}-cright)
end{array} $$
<h2>Math in MathML notation</h2>
When <math><mi>a</mi><mo>≠</mo><mn>0</mn></math>,
there are two solutions to <math>
<mi>a</mi><msup><mi>x</mi><mn>2</mn></msup>
<mo>+</mo> <mi>b</mi><mi>x</mi>
<mo>+</mo> <mi>c</mi> <mo>=</mo> <mn>0</mn>
</math> and they are
<math mode="display">
<mi>x</mi> <mo>=</mo>
<mrow>
<mfrac>
<mrow>
<mo>−</mo>
<mi>b</mi>
<mo>±</mo>
<msqrt>
<msup><mi>b</mi><mn>2</mn></msup>
<mo>−</mo>
<mn>4</mn><mi>a</mi><mi>c</mi>
</msqrt>
</mrow>
<mrow> <mn>2</mn><mi>a</mi> </mrow>
</mfrac>
</mrow>
<mtext>.</mtext>
</math>
</body>
</html>
Answered by user2478 on November 9, 2021
To display mathematics on the web, you have a number of options. There is the MathML standard which has the advantage of being endorsed by the same body that maintains the HTML and CSS standards. This isn't however, LaTeX based. There are tools to translate LaTeX code into MathML.
There is the "heavy duty" MathJax option. You can either install this on your server or use their CDN.
The simplest approach might be to use something like codecogs to produce images that you just include with html img
tags...
Answered by Seamus on November 9, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP