Page 1 of 1

TeX in General & Problem forums

Posted: Mon Dec 15, 2008 5:23 pm
by axelbrz
Hi!

It would be so great if we can write in TeX in both general and problems forums..

It's so easy to add, just create another label of this form (tex)EXPRESSION(/tex), and replace it on the internal parser by (img)http://www.codecogs.com/eq.latex?EXPRESSION(/img) (() are []) where users just have to write the expression of the first form.

Some examples:

[tex]{3}^{2} \equiv 1 (4)[/tex]:
Image

[tex](x \equiv 0 (4)) \lor (x \equiv 2 (4)) \Leftrightarrow x \equiv 0 (2)[/tex]:
Image

But I cannot add it easily, I had to replace the {, }, ^ and \ by the characters %7B, %7D, %5E and %5C respectively because it doesn't look like it accepts those characters on img labels, so I replaced they by their url encoded character, maybe you have to do the same on the parser to make it easier to write TeX for users.

I hope you like it and of course I hope you to add it :)

Whatever you need just tell me!

Excellent site!

Axel.

Re: TeX in General & Problem forums

Posted: Wed Dec 24, 2008 4:47 am
by axelbrz
so.. what do you think??

did you read this post??

thanks!

Re: TeX in General & Problem forums

Posted: Wed Dec 24, 2008 1:21 pm
by daniel.is.fischer
I would like it, but it may be too much work to incorporate the parsing and rendering into the existing machinery. euler?

Re: TeX in General & Problem forums

Posted: Wed Dec 24, 2008 2:02 pm
by hk
That would make rendering dependant on an external source.
I doubt that that would be wise.

Re: TeX in General & Problem forums

Posted: Wed Dec 24, 2008 2:33 pm
by daniel.is.fischer
It wouldn't. I thought about something like [tex]LaTeX stuff[/tex] → include in template → latex2html → include generated html when rendering the page, all done locally. But that would probably be too resource hungry :(

Re: TeX in General & Problem forums

Posted: Wed Dec 24, 2008 9:37 pm
by jaap
daniel.is.fischer wrote:It wouldn't. I thought about something like [tex]LaTeX stuff[/tex] → include in template → latex2html → include generated html when rendering the page, all done locally. But that would probably be too resource hungry :(
You could look into using jsMath. It is javascript, so all the work is done client-side. The only extra load is the serving of the js file, which gets cached in most cases anyway.

Re: TeX in General & Problem forums

Posted: Wed Dec 24, 2008 10:57 pm
by axelbrz
Mmm.. yes, it would be to use something external..

But I recently found this page that use a real time latex parser:
http://hausheer.osola.com/latex2png

And it's source (link from that page):
http://hausheer.osola.com/software/latex2png.phps

This is that PHP code:

Code: Select all

<?php

/*
 * PHP script to turn a LaTeX string into PNG, GIF, EPS, or JPEG
 *
 * Copyright (c) 2005 - 2008 David Hausheer
 * 
 * This script is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This script is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this script; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 * 
 */

$LATEX    = "openin_any=p /usr/bin/latex";
$DVIPNG   = "/usr/bin/dvipng";
$DVIPS    = "/usr/bin/dvips";
$EPSTOOL  = "/usr/bin/epstool";
$CONVERT  = "/usr/bin/convert"; // ImageMagick
$TEMPDIR  = "/tmp";
$TEMPNAM  = "eqn";
$IMGTYPES = array("png" => "image/png", 
                  "gif" => "image/gif", 
                  "eps" => "application/postscript",
                  "jpg" => "image/jpeg");

$source      = $_POST['source'];
$type        = $_POST['type'];
$density     = $_POST['density'];
$preview     = $_POST['preview'];
$transparent = $_POST['transparent'];
$inline      = $_POST['inline'];

if($source && get_magic_quotes_gpc()) $source = stripslashes($source);

if($source) $dynurl = $_SERVER['SCRIPT_URI']."/".str_replace("=","-",base64_encode($source))."/$density/".(($transparent && ($type=="png" || $type=="gif") || $preview && $type=="eps") ? 1 : 0)."/result.$type";

if($source && ($type=="eps" || $inline=="")) { header("Location: $dynurl"); exit(); }

list($encsource,$encdens,$enctrans,$enctype) = explode('/', substr($_SERVER['PATH_INFO'],1));
if ($encsource) $source = base64_decode(str_replace("=","-",$encsource));
if ($encdens) $density = $encdens;
if ($enctrans==1) { $transparent = "yes"; $preview = "yes"; }
if ($enctype) $type = substr($enctype, 7);

if($enctype) {

$tmpname = tempnam($TEMPDIR, $TEMPNAM);
$density = $density + 0;
$density = (1200 < $density) ? 1200 : (($density < 75) ? 75 : $density);

$source = strtr($source,"\n\r\t\0","    ");
$tex = "\documentclass[fleqn]{article} \usepackage{amssymb,amsmath,bm,color} \usepackage[latin1]{inputenc} \begin{document} \\"."thispagestyle{empty} \mathindent0cm \parindent0cm $source \end{document}";

$handle = fopen($tmpname.".tex", "w");
fputs($handle, $tex);
fclose($handle);

exec("cd $TEMPDIR; $LATEX -interaction=nonstopmode ".substr($tmpname,5));

if (isset($IMGTYPES[$type])) {

header('Content-Type: '.$IMGTYPES[$type]);
header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
header("Expires: ".gmdate("D, d M Y H:i:s",time() + 3600)." GMT"); 
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 

if ($transparent && ($type=="png" || $type=="gif")) $bg = "Transparent"; else $bg = "White";

if ($type=="gif" || $type=="jpg") passthru("$DVIPNG -q -T tight -bg $bg -D $density -o /dev/stdout $tmpname.dvi | $CONVERT png:- $type:-");

else if ($type=="png") passthru("$DVIPNG -q -T tight -bg $bg -D $density -o /dev/stdout $tmpname.dvi");

else if ($type="eps") { exec("$DVIPS -q -E $tmpname.dvi -o $tmpname.eps");
if ($preview) exec("$EPSTOOL --dpi $density -t6p $tmpname.eps $tmpname.eps");
readfile($tmpname.".eps");
}

}

exec("rm $tmpname*");

} else {

echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>Latex2png, latex2gif, latex2eps, latex2jpg</title>
</head>
<body>

<h1>Latex2png, latex2gif, latex2eps, latex2jpg</h1>
<hr/>

<p>Latex2png is a webtool to convert LaTeX code into different graphic formats (PNG, GIF, EPS, or JPEG).</p>
<p>This is convenient if you, e.g., want to insert a LaTeX formula as PNG into MS PowerPoint, or as EPS into Adobe FrameMaker.</p>
<p><b>Usage:</b> Enter your LaTeX code (e.g. a math formula), choose the desired output type and press "submit":</p>

<div style="position:relative">

<script type="text/javascript" src="/latexeditor/functions.js"></script>
<script type="text/javascript" src="/latexeditor/menu_items.js"></script>
<script type="text/javascript">
<!--//
new menu (MENU_ITEMS);
//-->
</script>

<?php

$displaycode = "\begin{displaymath}\n\oint_{\partial A}\vec H\;\cdot\mathrm{d}\vec s=\iint_A\vec J\;\cdot\mathrm{d}\vec A+\frac{\mathrm{d}}{\mathrm{d} t}\iint_A\vec D\;\cdot\mathrm{d}\vec A\n\end{displaymath}";

echo "<form id=\"latex2png\" method=\"post\" action=\"".$_SERVER['SCRIPT_NAME']."\">\n";

echo "<p><textarea name=\"source\" rows=\"10\" cols=\"60\">".($source ? $source : $displaycode)."</textarea></p>";

echo "<p><b>Type:</b> ";

foreach ($IMGTYPES as $key => $value) {
echo " <input type=\"radio\" name=\"type\" value=\"$key\" ".($type=="$key" || ($type=="" && $key=="png") ? "checked=\"checked\"" : "")."/> ".strtoupper($key);
}

echo "</p>";

echo "<p><b>Options:</b> ";

echo "<input type=\"text\" name=\"density\" value=\"".($density ? $density : 300)."\" size=\"3\"/> dpi (75-1200) ";

echo "<input type=\"checkbox\" name=\"preview\" value=\"yes\"/> with TIFF preview (EPS only) ";

echo "<input type=\"checkbox\" name=\"transparent\" value=\"yes\" ".($transparent=="yes" ? "checked=\"checked\"" : "")."/> transparent (PNG/GIF only) ";

echo "<input type=\"checkbox\" name=\"inline\" value=\"yes\" ".($inline=="yes" ? "checked=\"checked\"" : "")."/> show inline (PNG/GIF/JPG only)";

echo "</p>";
echo "<p><input type=\"submit\" value=\"submit\"/> <input type=\"reset\" value=\"reset\"/></p>";
echo "</form>\n";

echo "</div>\n";

if ($dynurl) {
echo "<p>To save the image, click the right mouse button over it and select \"Save Image As...\".</p>";
echo "<img style=\"padding:2px".($transparent ? "; background-color:#cccccc" : "")."\" src=\"$dynurl\"/>\n";
}

?>

</body></html>

<?php

}

?>
There is the link of the Latexeditor too if you need it (I really don't know how to mix all them to make a functional module, but I'm sure it would not be hard).

So, maybe you can check it, and make an extra module page called for example latex2img.php to use it as image for the replacement when some label [tex]..[/tex] appears :), and I'm sure it will be fast.

What do you say? I don't pretend you to add TeX for sure, because maybe you can't add this functionality because the resources, although I think it doesn't require much of them.. but if you can, It would be soo great to have TeX in Project Euler!! =)

Re: TeX in General & Problem forums

Posted: Sat Jan 03, 2009 1:28 pm
by hk
Currently we are not able to handle any functional requests that imply changing the functioning of the website or this forum.
Sorry.