<?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; integration</title>
	<atom:link href="http://www.actionshrimp.com/tag/integration/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.actionshrimp.com</link>
	<description>fun and geekery</description>
	<lastBuildDate>Thu, 12 May 2011 20:12:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>jsvi and TiddlyWiki</title>
		<link>http://www.actionshrimp.com/2008/05/jsvi-and-tiddlywiki/</link>
		<comments>http://www.actionshrimp.com/2008/05/jsvi-and-tiddlywiki/#comments</comments>
		<pubDate>Tue, 13 May 2008 15:26:28 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[TiddlyWiki]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[jsvi]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.actionshrimp.com/?p=6</guid>
		<description><![CDATA[Note: This is a bit out of date now, but Chris Peplin has built a proper plugin for tiddlywiki which does this for the latest versions of everything. So check it out! If you&#8217;re still interested in the old way then read on&#8230; When adding posts to my TiddlyWiki, I oft found myself craving vi, [...]]]></description>
			<content:encoded><![CDATA[<p><i>Note: This is a bit out of date now, but Chris Peplin has built <a href="http://github.com/peplin/jsvim-tiddly">a proper plugin</a> for tiddlywiki which does this for the latest versions of everything. So check it out! If you&#8217;re still interested in the old way then read on&#8230;</i></p>
<p style="text-align: left;">When adding posts to my TiddlyWiki, I oft found myself craving <a title="vi" href="http://en.wikipedia.org/wiki/Vi" target="_blank">vi</a>, rather than a simple textarea. There were a few options that involved using a plugin for Firefox such as mozEx, and using an external program to edit textareas. However, I found a nice &#8216;integrated&#8217; option instead.</p>
<p style="text-align: left;"><span id="more-6"></span></p>
<p style="text-align: left;"><a title="jsvi" href="http://gpl.internetconnection.net/vi/" target="_blank">jsvi</a> is an excellent javascript implementation of vi. I decided to try and integrate it into my TiddlyWiki, and the steps I took are shown below. To try out the final result, use the edit mode on my <a title="PhysiWiki" href="http://www.actionshrimp.com/physiwiki/" target="_blank">wiki</a>.</p>
<p style="text-align: center;"><a href="http://www.actionshrimp.com/wordpress/wp-content/uploads/2008/05/jsvi.png"><img class="size-medium wp-image-7" title="jsvi" src="http://www.actionshrimp.com/wordpress/wp-content/uploads/2008/05/jsvi-300x225.png" alt="jsvi in action on my wiki" width="300" height="225" /></a></p>
<p style="text-align: left;"><em><strong>Be warned:</strong></em> <em>this is a bit of a dirty hack, and requires a few files external to the TiddlyWiki file, which makes TiddlyWiki a bit less portable. At some point it&#8217;d be nice if this was build as a TiddlyWiki plugin instead, but at the minute I&#8217;m not experienced enough with writing plugins for TW. There is also a slight bug which means you can&#8217;t scroll up while editing. </em></p>
<p style="text-align: left;">First of all, I installed the <a title="iFrameEditorPlugin" href="http://visualtw.ouvaton.org/old/VisualTW.old.html#iFrameEditorPlugin" target="_blank">iFrameEditorPlugin</a> from an old version of the <a title="VisualTW" href="http://visualtw.ouvaton.org/VisualTW.html" target="_blank">VisualTW</a> site. I don&#8217;t think VisualTW uses the plugin anymore, and has instead changed it&#8217;s wysiwig editors to using plugins rather than iFrames &#8211; a far superior solution, but one I didn&#8217;t have the time or ability for. The plugin alone is not quite enough though, and a few changes to it are required.</p>
<p style="text-align: left;">iFrameEditorPlugin loads an iFrame containing your editor, passes the editor the text from the body of the tiddler, you edit it, and then when you save the page, the plugin gets your changes and saves them to the tiddler. However, it expects you to use a custom field rather than the default text field, which is a slight problem in our case. The function getContent() is what actually performs this:</p>
<pre style="text-align: left;">getContent=function(tiddler, field) {
    var t,f;
    t=store.getTiddler(tiddler);
    f = t ? t.fields[field] : "";
    f = f ? f : "";
    return f;
}</pre>
<p style="text-align: left;">As you can see, it reads the field of the tiddler with t.fields[field]. To read the default text field instead, I added a new function to the plugin:</p>
<pre style="text-align: left;">getContentText=function(tiddler) {
 var t,f;
 t=store.getTiddler(tiddler);
 f = t ? t.text : "";
 f = f ? f : "";
 return f;
}</pre>
<p style="text-align: left;">Great. So that&#8217;s set up. There&#8217;s also another problem with the plugin &#8211; it was originally intended for use with wysiwig html style editors, but I enjoy editing my wiki content raw. Also, the content has to be passed in a URL to the editor, so strange characters in the URL will mess it up, so there were problem with escaping html entities and things like that. To get around this, I found a handy javascript function that converted html entities back to their original form, and added this to the top of the plugin (thanks to The JavaScript Source):</p>
<pre style="text-align: left;">/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Ultimater | http://webdeveloper.com/forum/member.php?u=30185 */
function html_entity_decode(str) {
  var ta=document.createElement("textarea");
  ta.innerHTML=str.replace(/&lt;/g,"&lt;").replace(/&gt;/g,"&gt;");
  return ta.value;
}</pre>
<p style="text-align: left;">Ok, now we actually have to use this function, so we edit the plugin a bit more. Look for the line that reads the data back from the iFrame:</p>
<pre style="text-align: left;">if(f) fields[f] = e.contentWindow.getContent();</pre>
<p style="text-align: left;">and change it to:</p>
<pre style="text-align: left;">if(f) fields[f] = html_entity_decode(e.contentWindow.getContent());</pre>
<p style="text-align: left;">The plugin is all ready to go now, so we have to make the actual external editor that&#8217;s gonna go in the iFrame, using jsvi. Download these three files, and put them in the same folder as your TiddlyWiki html file.</p>
<blockquote style="text-align: left;"><p><a href="http://gpl.internetconnection.net/vi/vi.js" target="_blank">vi.js</a><br />
<a title="jsvi css file" href="http://gpl.internetconnection.net/vi/vi.css" target="_blank">vi.css</a><br />
<a title="editor" href="http://www.actionshrimp.com/physiwiki/editor.html" target="_blank">editor.html</a></p></blockquote>
<p style="text-align: left;">The first two are the actual jsvi javascript file and it&#8217;s style sheet, the second is my own editor iFrame. Let&#8217;s have a look at the important lines of the <em>editor.html</em> file:</p>
<pre style="text-align: left;">&lt;script type="text/javascript" src="vi.js"&gt;&lt;/script&gt;</pre>
<p style="text-align: left;">This includes the jsvi javascript file.</p>
<pre style="text-align: left;">&lt;textarea style="width: 99%" name="theEditor" onfocus="editor(this);"&gt;
&lt;/textarea&gt;</pre>
<p style="text-align: left;">This builds the actual textarea that&#8217;s gonna be edited by jsvi. Ok, now the javascript &#8220;meat&#8221; of the page:</p>
<pre style="text-align: left;">var oEditor = document.getElementsByName('theEditor')[0];
function getContent() {return oEditor.value;}
tiddlers=/[\?&amp;]tiddler=([^&amp;#]*)/.exec(unescape(window.location.href));
fields=/[\?&amp;]field=([^&amp;#]*)/.exec(unescape(window.location.href));
if (tiddlers&amp;&amp;fields) oEditor.value = parent.getContentText(tiddlers[1]);
oEditor.focus();</pre>
<p style="text-align: left;">All that happens here is we write the getContent() function that the iFrameEditorPlugin calls to read your changes. The tiddlers line reads the URL to get which tiddler you&#8217;re editing, and the fields line does the same for the field (actually this isn&#8217;t even necessary with our getContentText() function). The last two lines read the tiddler&#8217;s content, so we can edit it, and set the focus to the textarea to launch jsvi automatically when the iFrame loads.</p>
<p style="text-align: left;">That&#8217;s everything setup now, so all we need to do is tell Tiddlywiki when we want to make our edits with the iFrameEditor instead of with it&#8217;s default text field. I made a plugin (based on code from VisualTW&#8217;s EasyEditPlugin &#8211; thanks a lot!). <a title="jsviPlugin" href="http://www.actionshrimp.com/physiwiki/#jsviPlugin">You can view the plugin here</a>. Hopefully it should add a &#8216;vi&#8217; button next to the edit button on each tiddler. If no button appears, add &#8216;jsvi&#8217; to the first line of the ViewTemplate tiddler to look like this:</p>
<pre>&lt;div class='toolbar' macro='toolbar closeTiddler closeOthers +editTiddler jsvi &gt; fields syncing ....</pre>
<p style="text-align: left;">To make jsvi the default, remove the + from in front of editTiddler and put it in front of jsvi.</p>
<p style="text-align: left;">Now when you press the vi button, you should be presented with a rather gorgeous vi interface! <em><strong>One note, when you&#8217;re done editing a tiddler with jsvi, you must save it using the usual vi write command, :w, or press the &#8220;Save and Close&#8221; button. Otherwise the textarea does not get updated, and the iFrameEditorPlugin cannot read your changes. Also beware editing config shadow tiddlers with jsvi, as the line &#8220;macro=stuff&#8221; in some of the tooldbars etc. is interpreted by jsvi as it&#8217;s own command and it can end up destroying certain things.<br />
</strong></em></p>
<p style="text-align: left;">Update: I found a small problem with focusing using this in Firefox (didn&#8217;t test in other platforms) &#8211; after editing a post I was unable to select other fields and items in the window. This was fixed by changing one line in the vi.js file, line <strong>3588</strong>, which needs to be uncommented (the comment line before even refers to a bug in Firefox, possibly in an older version?) to look like this:</p>
<pre>document.body.removeChild(backing);</pre>
<p style="text-align: left;">Now it should work perfectly, apart from a few kinks: being able to edit the tiddler title the first time jsvi launches. Save and close vi, and it&#8217;s editable again, and still editable when you relaunch jsvi by clicking on the text area. If you cant get focus back on jsvi, right click it.</p>
<p style="text-align: left;">Hope you enjoy this as much as I do, and hopefully at some point soon when I have a bit more free time, I&#8217;ll have it in plugin format so it&#8217;s all incorporated into TW. Any problems, leave a comment and I&#8217;ll try and get back to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.actionshrimp.com/2008/05/jsvi-and-tiddlywiki/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<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 [...]]]></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>

