<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>actionshrimp.com &#187; latexrender</title>
	<atom:link href="http://www.actionshrimp.com/tag/latexrender/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.actionshrimp.com</link>
	<description>fun and geekery</description>
	<lastBuildDate>Sun, 18 Apr 2010 12:42:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Integrating LatexRender into TiddlyWiki</title>
		<link>http://www.actionshrimp.com/2008/05/integrating-latexrender-into-tiddlywiki/</link>
		<comments>http://www.actionshrimp.com/2008/05/integrating-latexrender-into-tiddlywiki/#comments</comments>
		<pubDate>Tue, 13 May 2008 13:17:49 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[TiddlyWiki]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[latexrender]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.actionshrimp.com/?p=5</guid>
		<description><![CDATA[This post is adapted from my LatexRenderPluginDoc page on my wiki, so might contain a couple of errors on the copy over. If something doesn&#8217;t seem right, refer to that page, and please tell me in a comment below.
This uses LatexRender, my simple TiddlyWiki macro, LatexRenderPlugin, and a custom script I created for the purpose, [...]]]></description>
			<content:encoded><![CDATA[<p>This post is adapted from my <a title="LatexRenderPluginDoc" href="http://www.actionshrimp.com/physiwiki/index.html#LatexRenderPluginDoc" target="_blank">LatexRenderPluginDoc</a> page on my wiki, so might contain a couple of errors on the copy over. If something doesn&#8217;t seem right, refer to that page, and please tell me in a comment below.</p>
<p>This uses <a class="externalLink" title="External link to http://www.mayer.dial.pipex.com/tex.htm" href="http://www.mayer.dial.pipex.com/tex.htm" target="_blank">LatexRender</a>, my simple TiddlyWiki macro, <a href="http://www.actionshrimp.com/physiwiki#LatexRenderPlugin"><span class="tiddlyLink tiddlyLinkExisting">LatexRenderPlugin</span></a>, and a custom script I created for the purpose, render.php, which renders LaTeX fed to it as an argument. You&#8217;ll need imagemagick enabled on your server.</p>
<p><span id="more-5"></span></p>
<p>First you need access to a server with the ability to run LatexRender. Download the <a class="externalLink" title="External link to http://www.mayer.dial.pipex.com/latexrender.zip" href="http://www.mayer.dial.pipex.com/latexrender.zip" target="_blank">latexrender.zip</a>, and extract the &#8220;otherPHP&#8221; directory. Copy the class.latexrender.php, and latex.php files to a folder on your webserver. Set up the directories in each file accordingly. For example, I have my wiki set up like so:</p>
<blockquote><p>webroot/physiwiki/latexrender:<br />
<em>class.latexrender.php</em><br />
<em>latex.php</em></p></blockquote>
<p>and two subdirectories (which the webserver needs write access to, chmod 777):</p>
<blockquote><p>webroot/physiwiki/latexrender/pictures<br />
webroot/physiwiki/latexrender/tmp</p></blockquote>
<p>So in <em>class.latexrender.php</em>, I have:</p>
<pre>var $_picture_path = "/absolue/path/to/physiwiki/latexrender/pictures";
var $_picture_path_httpd = "/physiwiki/latexrender/pictures";
var $_tmp_dir = "/absolute/path/to/physiwiki/latexrender/tmp";</pre>
<p>Also, make sure the paths to <strong>latex</strong>, <strong>dvips</strong>, <strong>convert</strong>, <strong>identify</strong> are setup correctly on the lines below. You can also make changes to the other settings in this file if you want including image format. The default is <strong>gif</strong>, I changed it to <strong>png</strong>.</p>
<p>Now <em>latex.php</em> by default generates the html to show an image, like:</p>
<pre>&lt;img src="blah"&gt;</pre>
<p>We dont want this. So some changes to <em>latex.php</em> are required. First adjust the paths in <em>latex.php</em>:</p>
<pre>$latexrender_path = "/absolute/path/to/physiwiki/latexrender";
$latexrender_path_http = ".";</pre>
<p>The &#8216;.&#8217; is used as <em>latex.php</em> resides in the same directory as class.latexrender.php.<br />
Next, scroll right to the bottom of the file, and you can comment out/delete the last few lines, and change the return value to $url instead of $text as below:</p>
<pre>    $url = $latex-&gt;getFormulaURL($latex_formula);

    /*
    $alt_latex_formula = htmlentities($latex_formula, ENT_QUOTES);
    $alt_latex_formula = ...
    $alt_latex_formula = ..

        if ($url != false) {
            $text = substr_replace($text, "&lt;img src='".$url."' title='".$alt_latex_formula."' alt='".$alt_latex_formula."' align=absmiddle&gt;",$pos,strlen($tex_matches[0][$i]));
        } else {
            $text = substr_replace($text, "[Unparseable or potentially dangerous latex formula. Error $latex-&gt;_errorcode $latex-&gt;_errorextra]",$pos,strlen($tex_matches[0][$i]));
        }
    */
    }
    return $url;
}</pre>
<p>Right, that&#8217;s LatexRender all setup. Now we need to make the <em>render.php</em> file. Put the code in a file and save it in the same directory as <em>class.latexrender.php</em> and <em>latex.php</em>.<br />
<em>render.php</em>:</p>
<pre>&lt;?
header("Content-type: image/png");
include_once('latex.php');

if (isset($_GET['l'])){

        $text = $_GET['l'];
        $text = stripslashes($text);
        $text = "[tex]" . $text . "[/tex]";

        $latex_img_file = latex_content($text);
        $handle = fopen($latex_img_file, "r");
        $contents = fread($handle, filesize($latex_img_file));
        fclose($handle);

        echo $contents;
}
?&gt;</pre>
<p>Obviously change the header function to match the content type you specified in <em>class.render.php</em>. This file accepts LaTeX formula code as an argument render.php?l=&lt;formula&gt;, puts it between [tex] tags so it can be messed around by <em>latex.php</em> and then renders it as the image file.</p>
<p>Now all that is left is to incorporate this into TiddlyWiki, using a simple macro. (Just change the src= section to match the location of your script):</p>
<pre>config.macros.tex = {};
config.macros.tex.handler = function (place,macroName,params,wikifier,paramString,tiddler) {

     var code = encodeURIComponent(params[0]);
     wikify("&lt;html&gt;&lt;img class="teximg" title="" + params[0] + "" src="latexrender/render.php?l=" + code + ""&gt;&lt;/html&gt;", place);

}</pre>
<p>To use this plugin just call it like so:</p>
<pre>&lt;&lt;tex 'int_{-5}^{5} x^2 dx'&gt;&gt;</pre>
<p>For some rendered examples just browse my <a title="PhysiWiki" href="http://www.actionshrimp.com/physiwiki/" target="_blank">wiki</a>!<br />
The macro also gives all equations the &#8220;teximg&#8221; css class, so they can be adjusted to be inline &#8220;nicely&#8221;, using the following CSS in the <span class="tiddlyLink tiddlyLinkExisting">StyleSheet</span> tiddler:</p>
<pre>.viewer {line-height: 2.0 ;} .viewer img.teximg { vertical-align: middle;}</pre>
<p>Hopefully you&#8217;ll now have easy LaTeX macro&#8217;s working on your TiddlyWiki! Any problems just leave me a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.actionshrimp.com/2008/05/integrating-latexrender-into-tiddlywiki/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
