<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Random Determinism</title>
	<atom:link href="http://randomdeterminism.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://randomdeterminism.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sun, 08 Jan 2012 22:15:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='randomdeterminism.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Random Determinism</title>
		<link>http://randomdeterminism.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://randomdeterminism.wordpress.com/osd.xml" title="Random Determinism" />
	<atom:link rel='hub' href='http://randomdeterminism.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Update for the filter module: faster caching</title>
		<link>http://randomdeterminism.wordpress.com/2012/01/08/faster-caching-for-filter-module/</link>
		<comments>http://randomdeterminism.wordpress.com/2012/01/08/faster-caching-for-filter-module/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 22:13:17 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[ConTeXt]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[luaTeX]]></category>
		<category><![CDATA[pandoc]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=773</guid>
		<description><![CDATA[Over the last year, the code base of the filter module has matured considerably. Now, the module has all the &#8230;<p><a href="http://randomdeterminism.wordpress.com/2012/01/08/faster-caching-for-filter-module/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=773&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Over the last year, the code base of the <a href="http://modules.contextgarden.net/filter">filter</a> module has matured considerably. Now, the module has all the features that I wanted when I started with it about a year and a half back. The last remaining limitation (in my eyes, at least) was that caching of results required a call to external programs (<code>mtxrun</code>) to calculate md5 hashes; as such, caching was slow. That is no longer the case. Now (since early December), md5 sums are calculated at the lua end, so there is no time penalty for caching. As a result, in MkIV, recompiling is much faster for documents having lots of external filter environments with caching enabled(i.e., environments defined with <code>continue=yes</code> option).</p>
<p><span id="more-773"></span></p>
<p>Since, the <a href="http://modules.contextgarden.net/vim">vim</a> module uses the filter module in the background, recompiling MkIV documents using the vim module will also be much faster. In this blog post, I explain both the old and new implementation of caching.</p>
<p>The filter module works as follows. Suppose, you want to use write an</p>
<pre><code>\startmarkdown
....
\stopmarkdown
</code></pre>
<p>to write content in Markdown and use a markdown-to-context tool like <code>pandoc</code> to process the content to ConTeXt. Using the filter module, such an environment can be defined as</p>
<pre><code>\defineexternalfilter
    [markdown]
    [filter={pandoc -t context}]
</code></pre>
<p>This defines a <code>markdown</code> start-stop environment. The contents of the environment are written to <code>\jobname-temp-markdown.tmp</code> file, which is processed using <code>pandoc -t context</code>, the result is written to <code>\jobname-temp-markdown.tex</code> file, which is finally read back to ConTeXt.</p>
<p>When a second <code>markdown</code> start-stop environment is encountered, the <code>\jobname-temp-markdown.tmp</code> file is overwritten, and the above process is repeated.</p>
<p>The above process works fine for fast programs like <code>pandoc</code> but for slow external programs, re-running the external program for each compilation slows down processing time. The filter module allows you to cache results by passing <code>continue=yes</code> option:</p>
<pre><code>\defineexternalfilter
    [markdown]
    [
      filter={pandoc -t context},
      continue=yes,
    ]
</code></pre>
<p>Now, the contents of the <code>markdown</code> start-stop environment are written to <code>\jobname-temp-markdown-&lt;n&gt;.tmp</code> file, where <code>&lt;n&gt;</code> is a count for the number of <code>markdown</code> environments so far. These files are processed using <code>pandoc -t context</code>, and the results are written to <code>\jobname-temp-markdown-&lt;n&gt;.tex</code> file, which is finally read back to ConTeXt.</p>
<p>Now, to cache the results, all we need to do is check if the <code>\jobname-temp-markdown-&lt;n&gt;.tmp</code> file has changed from the previous compilation. If so, re-process the file using <code>pandoc -t context</code>; otherwise simply reuse the result of previous compilation.</p>
<p>One low-cost method to check if the contents of a file have changed is to store a md5 sum of the contents and check if the md5 sum of the new file has changed or now. The ConTeXt wrapper script <code>mtxrun</code> provides this feature. If you call</p>
<pre><code>mtxrun --ifchanged=&lt;filename&gt; --direct &lt;program&gt;
</code></pre>
<p>then <code>mtxrun</code> calculates the md5 sum of <code>&lt;filename&gt;</code>, stores it in <code>&lt;filename&gt;.md5</code>, and runs <code>&lt;program&gt;</code> only if the md5 sum has changed.</p>
<p>I used <code>mtxrun</code> with appropriate options to cache the results in the older implementation of the filter module. (This implementation is still in use in MkII). However, this method requires a call to an external program, <code>mtxrun</code>, for each filter environment. These external calls to calculate md5 sum might be faster than the call the actual external program (like <code>pandoc</code>), but it does take a non-significant amount of time. I had some documents with around 70-80 code snippets that use the vim module, which in turn uses the filter module; and these 70-80 calls to <code>mtxrun</code> took considerable amount of time.</p>
<p>In the new implementation, the md5 sum is computed in Lua and stored in <code>.tuc</code> file. No calls to external programs is required; thus, the processing overhead is minimal. In fact, ConTeXt provides a Lua function <code>job.files.run</code> that takes care of computing the md5 sum and storing it to the <code>tuc</code> file. So, all that I have to do is that instead of calling <code>mtxrun</code>, use:</p>
<pre><code>\ctxlua{job.files.run(&quot;&lt;filename&gt;&quot;, &quot;&lt;program&gt;&quot;)}
</code></pre>
<p>The <code>job.files.run</code> function stores the md5 sum in the tuc file, and runs <code>&lt;program&gt;</code> only if the md5 sum has changed. With this implementation, there is very little overhead for multiple md5 sum calculations.</p>
<p>With this change, I think that the filter module is feature complete. From now on, I&#8217;ll only be making bugfixes for the filter module and concentrate adding features to my other modules: vim (which is more or less stable now), mathsets (which needs to be re-written for MkIV), and simpleslides (which needs cleanup to keep up with MkIV).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/773/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=773&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2012/01/08/faster-caching-for-filter-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>
	</item>
		<item>
		<title>Some thoughts on lowering the learning curve for using TeX (part I)</title>
		<link>http://randomdeterminism.wordpress.com/2011/09/04/some-thoughts-on-lowering-the-learning-curve-for-using-tex-part-i/</link>
		<comments>http://randomdeterminism.wordpress.com/2011/09/04/some-thoughts-on-lowering-the-learning-curve-for-using-tex-part-i/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 22:43:32 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[ConTeXt]]></category>
		<category><![CDATA[luaTeX]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[asciimode]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=767</guid>
		<description><![CDATA[TeX has a steep learning curve. Often times, steeper than it needs to be. Take, for example, the special characters &#8230;<p><a href="http://randomdeterminism.wordpress.com/2011/09/04/some-thoughts-on-lowering-the-learning-curve-for-using-tex-part-i/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=767&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>TeX has a steep learning curve. Often times, steeper than it needs to be. Take, for example, the <em>special characters</em> in TeX. Almost every introduction to plain TeX, eplain, LaTeX, or ConTeXt has a section on these <em>special characters</em></p>
<pre><code>\ { } $ &amp; # ^ _ &amp; ~
</code></pre>
<p>A good introduction then goes on to explain why these special characters are important; sometimes dropping a hint about category codes. I feel that these details are useless and, <strong>at the user level</strong>, we should get rid of them.</p>
<p><span id="more-767"></span></p>
<p>If you are skeptical, I don&#8217;t blame you. After all, category codes are the very soul of TeX. However, I strongly believe that they are useless at the user level. Lets go over each of these special characters one-by-one and see if we really need them.</p>
<h2> Minimum category codes: <code>\ { }</code> </h2>
<p>The only category codes that we need at the user level are <code> \ { }</code>. The character <code>\</code> marks the start of a control sequence, and <code>{</code> and <code>}</code> group the arguments. The rest, can simply be replaced by control sequences.</p>
<h2> Math mode category codes: <code>$ _ ^</code> </h2>
<p>In TeX, <code>$</code> is used to delimit math mode&mdash;Knuth used dollars as the math shift character because typesetting math was expensive, so goes an old joke. But do we really need to stick to <code>$</code>? After all, at the user level, both LaTeX and ConTeXt do not use <code>$$</code> to move to display math mode. Both macro packages provide environments for display math. Can&#8217;t we do the same for in-line math? In fact, both LaTeX and ConTeXt also provide macros for in-line math: LaTeX uses <code>\(...\)</code> and ConTeXt uses <code>\m{...}</code> and <code>\math{...}</code>. The only trouble is that these macros are not widely used (and that the LaTeX macros are not robust, but that is easily correctable). The only real argument in favor of <code>$...$</code> is that it shorted to type, but compared to <code>\(...\)</code> or <code>\m{...}</code>, not by much. </p>
<p>The same is true for <code>_</code> and <code>^</code>. Both LaTeX and ConTeXt (in fact, so does plain TeX!) provide macros for both of them: <code>\sp</code> for <code>^</code> and <code>\sb</code> for <code>_</code>. But don&#8217;t panic! I am not asking everyone to start using <code>\sp</code> and <code>\sb</code>. What I am asking is that <code>_</code> and <code>^</code> have normal meaning in text mode. That is, if I type <code>_</code>, I should get <code>_</code>, not a funky error message. In fact, this is not too difficult to achieve. In LaTeX, use the <code>underscore</code> package (it is easy to extend that to take care of <code>^</code> as well), and in ConTeXt use <code>\nonknuthmode</code> somewhere in your preamble. </p>
<p>Of course, the next logical step is to make <code>$</code> a normal letter: that is, if you type <code>$</code> you get <code>$</code>. This is not possible in pdftex, because there is no other means of entering into math mode (other than making some other character the math shift character, but that has the same drawback as making <code>$</code> the math shift character.) However, luatex provides primitive control sequences for entering and exiting in-line and display math. So, it is possible to make <code>$</code> a normal letter. </p>
<h2> Align character <code>&amp; </code> </h2>
<p>Horizontal alignment is one of the strengths of TeX. Most table and multi-line display math environments use horizontal alignment and <code>&amp;</code> specifies the alignment point for horizontal alignment. Surely, getting rid of <code>&amp;</code> will not work.</p>
<p>Unfortunately, that is true in LaTeX. The <code>&amp;</code> character is so critical for horizontal alignment at the user-level that eliminating it will mean a lot of change. Perhaps, <code>&amp;</code> can be handled in the same manner as <code>_</code> and <code>^</code>: it can be a regular letter in text mode and have special meaning inside horizontal alignment. But, it is not always clear to the users which macros use horizontal alignment internally. As such, changing the meaning of <code>&amp;</code> inside some environments will bring more trouble than benefits.</p>
<p>However, the situation in ConTeXt is completely different. At the user-level, <code>&amp;</code> is never used to indicate the alignment point. Both tables and multi-line math display use <code>\NC ... \NC ... \NC \NR</code> type of syntax to indicate new columns. In such a situation it is all the more awkward to explain to a user why <code>&amp;</code> is a special character. It should just be made a normal letter. LuaTeX provides a <code>\aligntab</code> primitive which can be used instead in alignment macros.</p>
<h2> Parameter indicator <code>#</code> </h2>
<p>Macros is what makes TeX different from all other text markup languages. Automatic numbering, cross-references, headers and footers, and all possible due to macros. And <code>#1</code> is used to indicate the first parameter for the macro, <code>#2</code> the second, and so on. But, why do we need this special meaning at the user-level? Only the macro writer needs to care about it.</p>
<p>Most LaTeX macros are written in <code>.sty</code> files, that are loaded under a different catcode regime anyways. Most ConTeXt macros are written inside <code>\unprotect ... \protect</code>. So, it is easy to set the traditional catcode regime in both cases. If a user really needs to define macros in the middle of the document, there can be a &#8220;programming&#8221; environment. For example, ConTeXt provides <code>\starttexcode...\stoptexcode</code>, which sets the same catcodes as <code>\unprotect...\protect</code>. Implementing the same environment in LaTeX is trivial (think <code>\makeatletter...\makeatother</code> on steroids).</p>
<h2> Unbreakable space <code>~</code> </h2>
<p>Knuth used <code>~</code> to indicate an unbreakable space, and that tradition has continued ever since. In this age of Unicode text, do we still need such crutches. It is easy enough to type Unicode <code>0x00AA</code> (non-breakable space) in most editors. For example, in vim I just need to type <code>CTRL+K+&lt;space&gt;+&lt;space&gt;</code>. A smart syntax highlighting scheme will make the non-breakable space visible. So, there is no real reason to keep on using <code>~</code> as a non-breakable space. The same argument holds for the TeX macros for accents, typing in Unicode is easy to input and easy to read (but that will be the subject of another rant). </p>
<h2>So, what&#8217;s the point of all this?</h2>
<p>Now image that all these features have been implemented. Then, we may split the introduction to a TeX macro package into two parts: using the macro package and programming the macro package. Split the first part into two further parts: text mode and math mode. For the text mode, the only special characters are <code>\ { } %</code>. All other characters are normal, that means if you type them, you see them in the output (provided the font has the glyph; lets ignore complex languages like Arabic, CJK, and Indic scripts and setting appropriate font features for them at the moment). <code>\</code> starts a control sequence, <code>{...}</code> groups an argument, and <code>%</code> is a line comment. For the math mode, explain how to enter math mode (<code>\(...\)</code> or <code>\m{...}</code> or the display-math environments) and explain that <code>_</code> and <code>^</code> are used to indicate sub- and super-scripts. Postpone explaining the programming mode for later. I think that such a scheme will lower the cognitive load on the new user. </p>
<p>Will such a system work? Yes, it will. In fact, it already does. For about an year now, ConTeXt has a <code>\asciimode</code> macro that implements all these features, with a slight twist. <code>%</code> is also a normal letter and you need to type <code>%%</code> to get a line comment (and <code>%{}%</code> if you really need the output <code>%%</code>). This macro is not enabled by default. I think that making it default will simplify understanding TeX for the first time. As an added advantage, it will also make the job of sanitizing the input simpler for converters (such as <a href="http://johnmacfarlane.net/pandoc/">pandoc</a>) that convert some other markup language to TeX.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/767/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/767/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/767/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/767/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/767/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/767/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/767/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/767/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/767/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/767/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/767/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/767/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/767/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/767/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=767&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2011/09/04/some-thoughts-on-lowering-the-learning-curve-for-using-tex-part-i/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>
	</item>
		<item>
		<title>Typewriter scroll mode in vim</title>
		<link>http://randomdeterminism.wordpress.com/2011/08/15/typewriter-scroll-mode-in-vim/</link>
		<comments>http://randomdeterminism.wordpress.com/2011/08/15/typewriter-scroll-mode-in-vim/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 15:21:37 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[vim]]></category>
		<category><![CDATA[typewriter scroll mode]]></category>
		<category><![CDATA[writeroom]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=760</guid>
		<description><![CDATA[I came across a Mac specific application Writeroom for distraction free writing and couldn&#8217;t help wonder that good &#8216;ol vim &#8230;<p><a href="http://randomdeterminism.wordpress.com/2011/08/15/typewriter-scroll-mode-in-vim/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=760&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I came across a Mac specific application <a href="http://www.hogbaysoftware.com/products/writeroom">Writeroom</a> for <em>distraction free writing</em> and couldn&#8217;t help wonder that good &#8216;ol <a href="http://www.vim.org/">vim</a> provides the same features.</p>
<p>One interesting feature was &quot;typewriter scroll mode&quot;, in which, the line that you are writing is always in the middle of the screen. At times, while editing long files, I find myself too often at the bottom of the screen at find myself typing <code>zz</code>  to redraw the buffer so that the current line is at the middle of the screen. It would be nice to have that as default. A quick search of  the vim help revealed:</p>
<pre><code>
'scrolloff' 'so'    number  (default 0)
            global
            {not in Vi}
    Minimal number of screen lines to keep above and below the cursor.
    This will make some context visible around where you are working.  If
    you set it to a very large value (999) the cursor line will always be
    in the middle of the window (except at the start or end of the file or
    when long lines wrap).
    For scrolling horizontally see 'sidescrolloff'.
    NOTE: This option is set to 0 when 'compatible' is set.
</code></pre>
<p>So, the solution is:</p>
<p><pre class="brush: plain;">
set scrolloff=99
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/760/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=760&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2011/08/15/typewriter-scroll-mode-in-vim/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>
	</item>
		<item>
		<title>visual counter for Maya numbers</title>
		<link>http://randomdeterminism.wordpress.com/2011/07/02/visual-counter-for-maya-numbers/</link>
		<comments>http://randomdeterminism.wordpress.com/2011/07/02/visual-counter-for-maya-numbers/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 04:37:44 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[ConTeXt]]></category>
		<category><![CDATA[Metapost]]></category>
		<category><![CDATA[Maya]]></category>
		<category><![CDATA[visualcounter]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=754</guid>
		<description><![CDATA[The other day I saw the documentary breaking the Maya code. At one stage they showed how the Maya number &#8230;<p><a href="http://randomdeterminism.wordpress.com/2011/07/02/visual-counter-for-maya-numbers/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=754&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The other day I saw the documentary <a href="http://www.imdb.com/title/tt0496253/">breaking the Maya code</a>. At one stage they showed how the Maya number system worked. If you haven&#8217;t seen the documentary, see the wikipedia page on <a href="http://en.wikipedia.org/wiki/Maya_script#Numerical_system">Maya number system</a>. I thought that this would be a nice way to visually represent page numbers in presentations. So, I added a new style to the <a href="http://randomdeterminism.wordpress.com/2010/11/14/visualcounter-module/">visual counter</a>, unimaginatively called <em>mayanumbers</em>. A <a href="https://github.com/adityam/visualcounter/blob/master/tests/page.tex">test</a> file comparing this affect with other visual counters from the module is in the <a href="https://github.com/adityam/visualcounter">github</a> directory of the module. </p>
<p>Have a look at the output <a href='http://randomdeterminism.files.wordpress.com/2011/07/page.pdf'>pdf</a>. It uses four counters; cycically from the top-left corner they are: <em>countdown</em>, <em>pulseline</em>, <em>scratchcounter</em>, and finally, <em>mayanumbers</em>. !&#8217;ll definitely experiment with <em>mayanumbers</em> in my next presentation.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/754/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/754/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/754/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/754/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/754/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/754/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/754/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/754/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/754/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/754/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/754/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/754/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/754/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/754/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=754&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2011/07/02/visual-counter-for-maya-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>
	</item>
		<item>
		<title>Syntax highlighting engines: clean tex output</title>
		<link>http://randomdeterminism.wordpress.com/2011/06/06/clean-tex-output/</link>
		<comments>http://randomdeterminism.wordpress.com/2011/06/06/clean-tex-output/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 20:02:30 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[ConTeXt]]></category>
		<category><![CDATA[TeX]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=750</guid>
		<description><![CDATA[The vim module uses the vim editor to syntax highlight code snippets in ConTeXt. I thought that it should be &#8230;<p><a href="http://randomdeterminism.wordpress.com/2011/06/06/clean-tex-output/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=750&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The vim module uses the vim editor to syntax highlight code snippets in ConTeXt. I thought that it should be straight forward to support other syntax highlighting engines: source-highlight, pygments, HsColor, etc. Unfortunately, that is not the case. None of these syntax highlighting engines were written with reuse in mind. </p>
<p><!-- more Continue reading --></p>
<p>For example, consider a simple tex file:</p>
<p><pre class="brush: plain;">
\definestartstop[important]
                [color=red,
                 style=\italic]
\starttext
This is an \important{important} text
\stoptext
</pre></p>
<p>Lets compare the tex file generated by various syntax highlighters:</p>
<p><code>source-highlight -f latex</code> gives<br />
<pre class="brush: plain;">
% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
\noindent
\mbox{}\textbf{\textcolor{Blue}{\textbackslash{}definestartstop}}\textcolor{Purple}{[important]} \\

\mbox{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [color=red, \\

\mbox{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ style=\textbf{\textcolor{Blue}{\textbackslash{}italic}}] \\

\mbox{}\textbf{\textcolor{Blue}{\textbackslash{}starttext}} \\

\mbox{}This\ is\ an\ \textbf{\textcolor{Blue}{\textbackslash{}important}}\textcolor{ForestGreen}{\{important\}}\ text \\

\mbox{}\textbf{\textcolor{Blue}{\textbackslash{}stoptext}} \\

\mbox{}
</pre></p>
<p><code>pygmentize -f latex</code> gives<br />
<pre class="brush: plain;">
\begin{Verbatim}[commandchars=\\
\{\}]
\PY{k}{\PYZbs{}definestartstop}\PY{n+na}{[important]}
                [color=red,
                 style=\PY{k}{\PYZbs{}italic}]
\PY{k}{\PYZbs{}starttext}
This is an \PY{k}{\PYZbs{}important}\PY{n+nb}{\PYZob{}}important\PY{n+nb}{\PYZcb{}} text
\PY{k}{\PYZbs{}stoptext}
\end{Verbatim}
</pre></p>
<p><code>HsColor-latex -partial</code> gives<br />
<pre class="brush: plain;">
\textcolor{red}{$\backslash$}{\rm{}definestartstop}\textcolor{red}{[}{\rm{}important}\textcolor{red}{]}\\
\hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \textcolor{red}{[}{\rm{}color}\textcolor{red}{=}{\rm{}red}\textcolor{cyan}{,}\\
\hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace \hsspace {\rm{}style}\textcolor{cyan}{=$\backslash$}{\rm{}italic}\textcolor{red}{]}\\
\textcolor{red}{$\backslash$}{\rm{}starttext}\\
{\rm{}This}\hsspace {\rm{}is}\hsspace {\rm{}an}\hsspace \textcolor{red}{$\backslash$}{\rm{}important}\textcolor{cyan}{\{}{\rm{}important}\textcolor{cyan}{\}}\hsspace {\rm{}text}\\
\textcolor{red}{$\backslash$}{\rm{}stoptext}\\
</pre></p>
<p>HsColor and source-highlight use explicit LaTeX commands for spacing and formatting. Ouch! Pygments uses logical markup, but with cryptic command names. But, from the point of view of using pygments output in ConTeXt, the <code>\begin{Verbatim}</code> and <code>\end{Verbatim}</code> are show stopper. (OK, not really. It can be bypassed with some effort).</p>
<p>Based on my experience, I decided to clean up the output generated by <code>2context.vim</code>:<br />
<pre class="brush: plain;">
\SYN[Identifier]{\\definestartstop}[important]
                [color=red,
                 style=\SYN[Identifier]{\\italic}]
\SYN[Statement]{\\starttext}
This is an \SYN[Identifier]{\\important}\{important\} text
\SYN[Statement]{\\stoptext}
</pre><br />
I assume only four TeX commands to be defined: <code>\\</code>, <code>\{</code>, and <code>\}</code> for backslash, open brace, and close brace; and <code>\SYN[...]{...}</code> for syntax highlighting. Thus, if anyone wants to reuse <code>2context</code> in plain TeX or LaTeX, or a yet to be written future macro package, they would not need to modify the output at all. I wish the other syntax highlighting programs did the same.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/750/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/750/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/750/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/750/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/750/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/750/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/750/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/750/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/750/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/750/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/750/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/750/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/750/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/750/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=750&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2011/06/06/clean-tex-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>
	</item>
		<item>
		<title>HTML export</title>
		<link>http://randomdeterminism.wordpress.com/2011/05/29/html-export/</link>
		<comments>http://randomdeterminism.wordpress.com/2011/05/29/html-export/#comments</comments>
		<pubDate>Mon, 30 May 2011 03:48:20 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[ConTeXt]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[luaTeX]]></category>
		<category><![CDATA[xhtml]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=742</guid>
		<description><![CDATA[The question of translating TeX to (X)HTML arises frequently. Almost everyone wants it. After all, on the web, (X)HTML is the de-facto standard markup; PDF, with all its hyper link abilities, is clumsier to use. On the other hand, for print, PDF, especially, TeX generated PDF is the de-facto standard (at least for math heavy fields); (X)HTML, with all its print css abilities, is clumsier to use. Often, you want <b>both</b> an (X)HTML version and a PDF version of a document. With the popularity of eink devices, epub (which is essentially a zipped (X)HTML file) is also becoming popular. Generating these multiple <em>output</em> formats from the same source is tricky.<p><a href="http://randomdeterminism.wordpress.com/2011/05/29/html-export/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=742&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The question of translating TeX to (X)HTML arises frequently. Almost everyone wants it. After all, on the web, (X)HTML is the de-facto standard markup; PDF, with all its hyper link abilities, is clumsier to use. On the other hand, for print, PDF, especially, TeX generated PDF is the de-facto standard (at least for math heavy fields); (X)HTML, with all its print css abilities, is clumsier to use. Often, you want <b>both</b> an (X)HTML version and a PDF version of a document. With the popularity of eink devices, epub (which is essentially a zipped (X)HTML file) is also becoming popular. Generating these multiple <em>output</em> formats from the same source is tricky.</p>
<p><span id="more-742"></span><br />
The easiest solution, of course, is to use an ascii markup language like markdown, restructured text, asciidoc, etc. that generate (X)HTML and tex output from the same source. For simple tasks these are great: the synatx is fairly intuitive and there are various tools that translation tools are fairly robust. But, these simple markups lack an important ability of TeX: <b>programmable macros</b>. To give an example, suppose I need to write n tuples <code>$(a_1, \dots, a_n)$</code> fairly often in a document. When using TeX, I am in the habit of defining a macro</p>
<p><pre class="brush: plain;">
\def\TUPLE#1{(#_1,\dots,#_n)}
</pre></p>
<p>and then use <code>$\TUPLE a$</code>. This saves typing and prevents typos. Ascii markup languages lack this ability. </p>
<p>A more robust solution is to use XML as the input language and then use XML-tookchain to translate the input to both HTML and TeX (There are various TeX based solution for parsing XML directly, both in LaTeX and ConTeXt). However, typing XML is a pain, epsecially, when it comes to typing MathML. </p>
<p>A solution which meets the needs midway is inputing text in (X)HTML and math in TeX format. Then use <a href="http://www.mathjax.org">mathjax</a> to render HTML and one of the TeX XML processing packages to convert to PDF. I think that until browsers become mature in displaying MathML, mathjax is an excellent ad-hoc solution. In addition, it does parse simplist TeX macros. However, you do loose the ability to write complicated TeX macros.</p>
<p>Of course, if you want to parse TeX macros, the only real solution is to use TeX to parse to parse TeX. Why? Because TeX has the <em>amazing</em> ability to change its grammer on the fly.</p>
<p><pre class="brush: plain;">
\newcatcodetable \weirdcatcodes
\startcatcodetable \weirdcatcodes
    \catcode`\@ = 0
    \catcode`\( = 1
    \catcode`\) = 2
\stopcatcodetable
\setcatcodetable \weirdcatcodes
</pre></p>
<p>After this, <code>@</code> takes the usual meaning of <code>\</code>, <code>(</code> of <code>{</code>, and <code>)</code> of <code>}</code>. So, to start a section, you have to use</p>
<p><pre class="brush: plain;">
@section (A section)
</pre></p>
<p>This ability of changing catcodes is best illustrated by David Carlisle&#8217;s <code>xii.tex</code></p>
<p><pre class="brush: plain;">
\let~\catcode~`76~`A13~`F1~`j00~`P2jdefA71F~`7113jdefPALLF
PA''FwPA;;FPAZZFLaLPA//71F71iPAHHFLPAzzFenPASSFthP;A$$FevP
A@@FfPARR717273F737271P;ADDFRgniPAWW71FPATTFvePA**FstRsamP
AGGFRruoPAqq71.72.F717271PAYY7172F727171PA??Fi*LmPA&amp;&amp;71jfi
Fjfi71PAVVFjbigskipRPWGAUU71727374 75,76Fjpar71727375Djifx
:76jelse&amp;U76jfiPLAKK7172F71l7271PAXX71FVLnOSeL71SLRyadR@oL
RrhC?yLRurtKFeLPFovPgaTLtReRomL;PABB71 72,73:Fjif.73.jelse
B73:jfiXF71PU71 72,73:PWs;AMM71F71diPAJJFRdriPAQQFRsreLPAI
I71Fo71dPA!!FRgiePBt'el@ lTLqdrYmu.Q.,Ke;vz vzLqpip.Q.,tz;
;Lql.IrsZ.eap,qn.i. i.eLlMaesLdRcna,;!;h htLqm.MRasZ.ilk,%
s$;z zLqs'.ansZ.Ymi,/sx ;LYegseZRyal,@i;@ TLRlogdLrDsW,@;G
LcYlaDLbJsW,SWXJW ree @rzchLhzsW,;WERcesInW qt.'oL.Rtrul;e
doTsW,Wk;Rri@stW aHAHHFndZPpqar.tridgeLinZpe.LtYer.W,:jbye
</pre></p>
<p><b>To parse such TeX, you need TeX. </b></p>
<p>Now, from TeX&#8217;s point of view, (X)HTML is not different from any other <em>backend</em> like DVI and PDF. It just needs to write the output in a specific format to a file. LuaTeX makes this easy and ConTeXt MkIV now supports a XHTML backend. Simply add</p>
<p><pre class="brush: plain;">
\setupbackend[export=yes, xhtml=yes]
</pre></p>
<p>in your preamble. This creates a <code>\joname.xhtml</code> file (and a <code>\jobname.export</code> XML file) For example</p>
<p><pre class="brush: plain;">
\setupbackend[export=yes, xhtml=yes]

\starttext
\input ward
\stoptext
</pre></p>
<p>gives</p>
<p><pre class="brush: xml;">
&lt;?xml version='1.0' encoding='UTF-8' standalone='yes' ?&gt;

&lt;!-- input filename   : xhtml             --&gt;
&lt;!-- processing date  : Sun May 29 22:02:02 2011 --&gt;
&lt;!-- context version  : 2011.05.18 22:26  --&gt;
&lt;!-- exporter version : 0.20              --&gt;

&lt;document xmlns:m=&quot;http://www.w3.org/1998/Math/MathML&quot; version=&quot;0.20&quot; language=&quot;en&quot; date=&quot;Sun May 29 22:02:02 2011&quot; file=&quot;xhtml&quot; context=&quot;2011.05.18 22:26&quot; xmlns:xhtml=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
The Earth, as a habitat for animal life, is in old age and has a fatal illness. Several, in fact. It would be happening whether humans had ever evolved or not. But our presence is like the effect of an old-age patient who smokes many packs of cigarettes per day --- and we humans are the cigarettes. 
&lt;/document&gt;
</pre></p>
<p>This is not really an XHTML file. It is just an XML file. With a proper stylesheet, most browsers will be able to display this file. Creating such a stylesheet is easy. A simple example of such a stylesheet is <a href="https://gist.github.com/998408">here</a>. To use this stylesheet, save it as, say <tt>mkiv-export.css</tt>, then add</p>
<p><pre class="brush: plain;">
\setupbackend[export=yes, xhtml=yes, css=mkiv-export.css]
</pre></p>
<p>This adds the following line to the generated XHTML output</p>
<p><pre class="brush: xml;">
&lt;?xml-stylesheet type=&quot;text/css&quot; href=&quot;mkiv-export.css&quot;?&gt;
</pre></p>
<p>The XHTML file exports the <b>structure</b> of the document, not the style. Consider the following, more complicated example:</p>
<p><pre class="brush: plain;">
\setupbackend[export=yes, xhtml=yes, css=mkiv-export.css]

\definestartstop[important][style=italic]

\starttext
\section {The first attempt}

The XHTML export with \important{structured text}, but not manual {\em style}
\italic{commands}. But the good thing is that it works with math!

Consider a quadratic equation $ax^2 + bx + c = 0$. The roots of this equation are
\startformula
  x = (-b ± \sqrt{b^2 - 4ac})/2a
\stopformula
\stoptext
</pre></p>
<p>This gives </p>
<p><pre class="brush: xml;">
&lt;?xml version='1.0' encoding='UTF-8' standalone='yes' ?&gt;

&lt;!-- input filename   : xhtml             --&gt;
&lt;!-- processing date  : Sun May 29 22:08:38 2011 --&gt;
&lt;!-- context version  : 2011.05.18 22:26  --&gt;
&lt;!-- exporter version : 0.20              --&gt;

&lt;?xml-stylesheet type=&quot;text/css&quot; href=&quot;mkiv-export.css&quot;?&gt;

&lt;document xmlns:m=&quot;http://www.w3.org/1998/Math/MathML&quot; version=&quot;0.20&quot; language=&quot;en&quot; date=&quot;Sun May 29 22:08:38 2011&quot; file=&quot;xhtml&quot; context=&quot;2011.05.18 22:26&quot; xmlns:xhtml=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;xhtml:a name=&quot;aut_1&quot;&gt;&lt;section location=&quot;aut:1&quot; detail=&quot;section&quot;&gt;
    &lt;sectionnumber&gt;1&lt;/sectionnumber&gt;  
    &lt;sectiontitle&gt;The first attempt&lt;/sectiontitle&gt;  
    &lt;sectioncontent&gt;
The XHTML export with &lt;construct detail=&quot;important&quot;&gt;structured text&lt;/construct&gt;, but not manual style commands. But the good thing is that it works with math!

      &lt;break/&gt;
 Consider a quadratic equation 
      &lt;m:math&gt;
        &lt;m:mrow&gt;
          &lt;m:mi&gt;𝑎&lt;/m:mi&gt;
          &lt;m:msup&gt;
            &lt;m:mi&gt;𝑥&lt;/m:mi&gt;
            &lt;m:mn&gt;2&lt;/m:mn&gt;
          &lt;/m:msup&gt;
          &lt;m:mo&gt;+&lt;/m:mo&gt;
          &lt;m:mi&gt;𝑏&lt;/m:mi&gt;
          &lt;m:mi&gt;𝑥&lt;/m:mi&gt;
          &lt;m:mo&gt;+&lt;/m:mo&gt;
          &lt;m:mi&gt;𝑐&lt;/m:mi&gt;
          &lt;m:mo&gt;=&lt;/m:mo&gt;
          &lt;m:mn&gt;0&lt;/m:mn&gt;
        &lt;/m:mrow&gt;
      &lt;/m:math&gt;
. The roots of this equation are

      &lt;formula&gt;
 
        &lt;formulacontent&gt;
          &lt;m:math&gt;
            &lt;m:mrow&gt;
              &lt;m:mi&gt;𝑥&lt;/m:mi&gt;
              &lt;m:mo&gt;=&lt;/m:mo&gt;
              &lt;m:mo&gt;(&lt;/m:mo&gt;
              &lt;m:mo&gt;−&lt;/m:mo&gt;
              &lt;m:mi&gt;𝑏&lt;/m:mi&gt;
              &lt;m:mo&gt;±&lt;/m:mo&gt;
              &lt;m:mo&gt;󿁰 &lt;/m:mo&gt;
              &lt;m:mroot&gt;
                &lt;m:mrow&gt;
                  &lt;m:msup&gt;
                    &lt;m:mi&gt;𝑏&lt;/m:mi&gt;
                    &lt;m:mn&gt;2&lt;/m:mn&gt;
                  &lt;/m:msup&gt;
                  &lt;m:mo&gt;−&lt;/m:mo&gt;
                  &lt;m:mn&gt;4&lt;/m:mn&gt;
                  &lt;m:mi&gt;𝑎&lt;/m:mi&gt;
                  &lt;m:mi&gt;𝑐&lt;/m:mi&gt;
                &lt;/m:mrow&gt;
              &lt;/m:mroot&gt;
              &lt;m:mo&gt;)&lt;/m:mo&gt;
              &lt;m:mi&gt;/&lt;/m:mi&gt;
              &lt;m:mn&gt;2&lt;/m:mn&gt;
              &lt;m:mi&gt;𝑎&lt;/m:mi&gt;
            &lt;/m:mrow&gt;
          &lt;/m:math&gt;
        &lt;/formulacontent&gt;
      &lt;/formula&gt;
    &lt;/sectioncontent&gt;
  &lt;/section&gt;&lt;/xhtml:a&gt;
&lt;/document&gt;
</pre></p>
<p>Notice some features of the output: the section number is exported with the section title (if you change the conversion of the section number, the output will honor that); the structure command <code>\important</code> is exported, the style commands <code>\em</code> and <code>\italic</code> are not; math is exported as MathML with Unicode symbols!. There are some interesting features that we are experimenting with. I&#8217;ll post more about the MathML export in the future.</p>
<p>So, if you are interested in XHTML output for TeX sources, play around with the new export feature. It is not perfect &#8230; yet. But with MathML and SVG (remeber, Metapost has a SVG backend), it is possible to get a fully working XHTML output for the TeX input <em>generated by TeX</em> rather than a pre- or post-processor. After all, <b>only TeX can parse TeX</b> </p>
<p><pre class="brush: plain;">
\setupbackend[export=yes, xhtml=yes, css=mkiv-export.css]

\starttext
\let\bye=\donothing %xii.tex ends with \bye
\input xii
\stoptext
</pre></p>
<p>(The output is <a href="https://gist.github.com/998417">here</a>)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/742/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/742/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/742/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/742/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/742/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/742/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/742/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/742/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/742/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/742/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/742/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/742/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/742/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/742/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=742&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2011/05/29/html-export/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>
	</item>
		<item>
		<title>Images for documentation examples</title>
		<link>http://randomdeterminism.wordpress.com/2011/05/07/images-for-documentation-examples/</link>
		<comments>http://randomdeterminism.wordpress.com/2011/05/07/images-for-documentation-examples/#comments</comments>
		<pubDate>Sat, 07 May 2011 23:31:05 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[ConTeXt]]></category>
		<category><![CDATA[luaTeX]]></category>
		<category><![CDATA[externalfigure]]></category>
		<category><![CDATA[placekitten]]></category>
		<category><![CDATA[tex.se]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=731</guid>
		<description><![CDATA[ConTeXt users tend to use the famous Dutch cow as a place holder image for documentation examples. At times, it &#8230;<p><a href="http://randomdeterminism.wordpress.com/2011/05/07/images-for-documentation-examples/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=731&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ConTeXt users tend to use the <em>famous</em> Dutch cow as a place holder image for documentation examples. At times, it gets <a href="http://randomdeterminism.wordpress.com/2011/03/28/would-a-table-by-any-other-name-be-as-useful/">annoying</a>. One alternative is to use random figures:</p>
<p><pre class="brush: plain;">
\useMPlibrary[dum]

\starttext
  \placefigure[left,none]{}
    {\externalfigure[whatever][width=0.5\textwidth, height=0.3\textheight]}
  \input knuth
\stoptext
</pre></p>
<p>which gives an image as shown below:</p>
<p><a href="http://randomdeterminism.files.wordpress.com/2011/05/dummy.png"><img src="http://randomdeterminism.files.wordpress.com/2011/05/dummy.png?w=529" alt="" title="dummy"   class="aligncenter size-full wp-image-732" /></a></p>
<p><span id="more-731"></span><br />
The image is draws random circles with random colors using metapost.</p>
<p>In a recent <a href="http://meta.tex.stackexchange.com/questions/1306/list-of-commonly-available-example-images/1312#1312">discussion</a> on <a href="http://tex.stachexchange.com">tex.se</a>, Sharpie mentioned a website: <a href="http://placekitten.com">http://placekitten.com</a>, that provides pictures of kittens as placeholders for images. Those kittens are definitely cuter than the Dutch cow. Using these kittens as placeholder images is easy: if you want a 300pt x 400pt images, just type:</p>
<p><pre class="brush: plain;">
\externalfigure[http://placekitten.com/g/300/400][method=jpg]
</pre></p>
<p>ConTeXt takes care of downloading and caching the image. However, to use this approach, you need to know the required image dimensions in postscript points. Many a times, the image dimensions are known in relative terms like the above example where we asked for an image that is <code>0.5\textwidth</code> wide and <code>0.3\textheight</code> high. To convert a arbitrary TeX dimention to points, we can use <code>\dimexpr</code> which reports its result in points. So, to know how much is <code>0.5\textwidth</code> we can use</p>
<p><pre class="brush: plain;">
\the\dimexpr0.5\textwidth
</pre></p>
<p>For the default setup, this reports <code>213.3937pt</code>. To use this dimension with place kitten website, we need to get rid of the <code>pt</code> suffix&mdash;a freqeuntly needed feature for which ConTeXt, like almost all other macro packages, provides a built-in macro: <code>\withoutpt</code>. Thus, we can use</p>
<p><pre class="brush: plain;">
\withoutpt{\the\dimexpr0.5\textwidth}
</pre></p>
<p>to get the value of <code>0.5\textwidth</code> without the <code>pt</code> suffix. However, this is not enough: the place kitten website does not provide images with fractional sizes. So, we need to round (or truncate) the value to a whole number. I don&#8217;t know if ConTeXt has a built-in macro for that; neither do I care enough to write such a macro in TeX. Truncating a float to an integer is easy in Lua, and that is what I will use. Combining all this, here is a macro that places an image of a kitten that is of a particular size:</p>
<p><pre class="brush: plain;">
\def\externalkitten[#1]%
    {\getparameters[kitten][width=10pt, height=10pt, #1]
     \externalfigure
        [\ctxlua{context(&quot;http://placekitten.com/g/\%0.0f/\%0.0f&quot;,
                  \withoutpt{\the\dimexpr\kittenwidth},
                  \withoutpt{\the\dimexpr\kittenheight})}]
        [#1, method=jpg]}
</pre></p>
<p>This can be used as:</p>
<p><pre class="brush: plain;">
\starttext
  \placefigure[left,none]{}
    {\externalkitten[width=0.5\textwidth, height=0.3\textheight]}
  \input knuth
\stoptext
</pre></p>
<p>which gives the following result:<br />
<a href="http://randomdeterminism.files.wordpress.com/2011/05/kitten.png"><img src="http://randomdeterminism.files.wordpress.com/2011/05/kitten.png?w=529" alt="" title="kitten"   class="aligncenter size-full wp-image-734" /></a></p>
<p>I think that this looks much nicer than the random image above. Below is an example that uses the place kitten images to show how the <code>location</code> key works.</p>
<p><pre class="brush: plain;">
\startcombination[3*3]
  {\externalkitten[width=0.2\textwidth, height=0.15\textheight, location=top]}{}
  {\externalkitten[width=0.2\textwidth, height=0.20\textheight, location=top]}{}
  {\externalkitten[width=0.2\textwidth, height=0.25\textheight, location=top]}{}
  {\externalkitten[width=0.2\textwidth, height=0.15\textheight, location=middle]}{}
  {\externalkitten[width=0.2\textwidth, height=0.20\textheight, location=middle]}{}
  {\externalkitten[width=0.2\textwidth, height=0.25\textheight, location=middle]}{}
  {\externalkitten[width=0.2\textwidth, height=0.15\textheight, location=bottom]}{}
  {\externalkitten[width=0.2\textwidth, height=0.20\textheight, location=bottom]}{}
  {\externalkitten[width=0.2\textwidth, height=0.25\textheight, location=bottom]}{}
\stopcombination
</pre></p>
<p><a href="http://randomdeterminism.files.wordpress.com/2011/05/combination.png"><img src="http://randomdeterminism.files.wordpress.com/2011/05/combination.png?w=529" alt="" title="combination"   class="aligncenter size-full wp-image-735" /></a></p>
<p>Note that all three images are of different sizes. The first row is top aligned, the second row is middle aligned, and the third row is bottom aligned. Now imagine how this would have looked if all three images were scaled cows!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/731/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=731&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2011/05/07/images-for-documentation-examples/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>

		<media:content url="http://randomdeterminism.files.wordpress.com/2011/05/dummy.png" medium="image">
			<media:title type="html">dummy</media:title>
		</media:content>

		<media:content url="http://randomdeterminism.files.wordpress.com/2011/05/kitten.png" medium="image">
			<media:title type="html">kitten</media:title>
		</media:content>

		<media:content url="http://randomdeterminism.files.wordpress.com/2011/05/combination.png" medium="image">
			<media:title type="html">combination</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding color to tables</title>
		<link>http://randomdeterminism.wordpress.com/2011/05/01/adding-color-to-tables/</link>
		<comments>http://randomdeterminism.wordpress.com/2011/05/01/adding-color-to-tables/#comments</comments>
		<pubDate>Sun, 01 May 2011 16:29:25 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[ConTeXt]]></category>
		<category><![CDATA[colors]]></category>
		<category><![CDATA[natural tables]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=713</guid>
		<description><![CDATA[Texblog had an interesting post on creating tables with alternating colors. See the pdf for the final output. I thought &#8230;<p><a href="http://randomdeterminism.wordpress.com/2011/05/01/adding-color-to-tables/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=713&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://texblog.wordpress.com/2011/04/19/highlight-table-rowscolumns-with-color/">Texblog</a> had an interesting post on creating tables with alternating colors. See the <a href="http://texblog.files.wordpress.com/2011/04/color-table.pdf">pdf</a> for the final output. I thought that it will be interesting to see how to reproduce the same effect in ConTeXt. <span id="more-713"></span>This is the table that I am going to use for my tests:</p>
<p><pre class="brush: plain;">
\startbuffer[contents]
\NC       \NC Col 1 \NC Col 2 \NC Col 3 \NC Col 4 \NC Col 5 \NC \NR
\NC Row 1 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 2 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 3 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 4 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 5 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 6 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\stopbuffer
</pre></p>
<p>First lets get the frames right. The example typesets each table with a rules around the first row, a vertical rule after the first column, and a rule after the last column. To get that, use</p>
<p><pre class="brush: plain;">
\startsetups table:frame
\setupTABLE[each][each][frame=off, align=middle, background=color, rulethickness=1bp]
\setupTABLE[row][first][bottomframe=on,topframe=on]
\setupTABLE[row][last] [bottomframe=on]
\setupTABLE[column][first][rightframe=on]
\stopsetups
</pre></p>
<p>That is pretty self explanatory. By default, all cells in a table have a frame, so I switch that off with <code>frame=off</code>; each cell should be middle aligned, so I use <code>align=middle</code>; <code>background=color</code> is for later when I will set the color for the table; <code>rulethickness</code> sets the thickness of the line. This setup gives the following result:</p>
<p><pre class="brush: plain;">
\startTABLE[setups=table:frame]
  \getbuffer[contents]
\stopTABLE
</pre></p>
<p style="text-align:center;"><a href="http://randomdeterminism.files.wordpress.com/2011/05/table-1.png"><img class="size-medium wp-image-717 aligncenter" title="Basic table" src="http://randomdeterminism.files.wordpress.com/2011/05/table-1.png?w=300&#038;h=191" alt="" width="300" height="191" /></a></p>
<p>Now, lets try the different color setups.</p>
<h2>Rows with alternative colors</h2>
<p>This one is simple. Set</p>
<p><pre class="brush: plain;">
\startsetups table:rows
\setupTABLE[row][odd] [backgroundcolor=yellow:1]
\setupTABLE[row][even][backgroundcolor=blue:1]
\stopsetups
</pre></p>
<p>The colors <code>yellow:1</code> and <code>blue:1</code> mean 10% yellow and blue. Then add this setup to the table to get the following result:</p>
<p><pre class="brush: plain;">
\startTABLE[setups={table:frame,table:rows}]
  \getbuffer[contents]
\stopTABLE
</pre></p>
<p><a href="http://randomdeterminism.files.wordpress.com/2011/05/table-2.png"><img src="http://randomdeterminism.files.wordpress.com/2011/05/table-2.png?w=300&#038;h=191" alt="" title="Alternate rows" width="300" height="191" class="aligncenter size-medium wp-image-721" /></a></p>
<h2>Columns with alternative colors</h2>
<p>This is almost identical to the row setup.</p>
<p><pre class="brush: plain;">
\startsetups table:columns
\setupTABLE[column][odd] [backgroundcolor=yellow:1]
\setupTABLE[column][even][backgroundcolor=blue:1]
\stopsetups

\startTABLE[setups={table:frame,table:columns}]
  \getbuffer[contents]
\stopTABLE
</pre></p>
<p><a href="http://randomdeterminism.files.wordpress.com/2011/05/table-3.png"><img src="http://randomdeterminism.files.wordpress.com/2011/05/table-3.png?w=300&#038;h=191" alt="" title="Alternate columns" width="300" height="191" class="aligncenter size-medium wp-image-722" /></a></p>
<h2>Chessboard coloring</h2>
<p>And now for the most interesting setup: coloring the table cells like a chessboard.</p>
<p><pre class="brush: plain;">
\startsetups table:chessboard
\setupTABLE[each][each][backgroundcolor=yellow:1]
\setupTABLE[odd][odd]  [backgroundcolor=blue:1]
\setupTABLE[even][even][backgroundcolor=blue:1]
\stopsetups

\startTABLE[setups={table:frame,table:chessboard}]
  \getbuffer[contents]
\stopTABLE
</pre></p>
<p><a href="http://randomdeterminism.files.wordpress.com/2011/05/table-4.png"><img src="http://randomdeterminism.files.wordpress.com/2011/05/table-4.png?w=300&#038;h=191" alt="" title="Chessboard" width="300" height="191" class="aligncenter size-medium wp-image-723" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/713/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/713/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/713/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=713&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2011/05/01/adding-color-to-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>

		<media:content url="http://randomdeterminism.files.wordpress.com/2011/05/table-1.png?w=300" medium="image">
			<media:title type="html">Basic table</media:title>
		</media:content>

		<media:content url="http://randomdeterminism.files.wordpress.com/2011/05/table-2.png?w=300" medium="image">
			<media:title type="html">Alternate rows</media:title>
		</media:content>

		<media:content url="http://randomdeterminism.files.wordpress.com/2011/05/table-3.png?w=300" medium="image">
			<media:title type="html">Alternate columns</media:title>
		</media:content>

		<media:content url="http://randomdeterminism.files.wordpress.com/2011/05/table-4.png?w=300" medium="image">
			<media:title type="html">Chessboard</media:title>
		</media:content>
	</item>
		<item>
		<title>Fill in the blanks in ConTeXt</title>
		<link>http://randomdeterminism.wordpress.com/2011/04/30/fill-in-the-blanks-in-context/</link>
		<comments>http://randomdeterminism.wordpress.com/2011/04/30/fill-in-the-blanks-in-context/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 05:04:34 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[ConTeXt]]></category>
		<category><![CDATA[typesetting exams]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=698</guid>
		<description><![CDATA[While preparing an exam, I needed to create empty lines for students to write their answers. How to typeset that &#8230;<p><a href="http://randomdeterminism.wordpress.com/2011/04/30/fill-in-the-blanks-in-context/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=698&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While preparing an exam, I needed to create empty lines for students to write their answers.</p>
<p><a href="http://randomdeterminism.files.wordpress.com/2011/04/blanks.png"><img class="aligncenter size-full wp-image-699" title="blanks" src="http://randomdeterminism.files.wordpress.com/2011/04/blanks.png?w=529" alt=""   /></a></p>
<p>How to typeset that using ConTeXt? I could think of a plain TeX solution: create an appropriate <code>\leaders</code> to create a ruled line; insert appropriate <code>\vskip</code> between the lines. Before trying to code it, I decoded to quickly grep ConTeXt base for <code>\leaders</code> to see if a similar macro was already implemented. Sure enough, ConTeXt had a macro for that: <a href="http://wiki.contextgarden.net/Reference/en/thinrules"><code>\thinrules</code></a> (and <a href="http://wiki.contextgarden.net/Reference/en/setupthinrules"><code>\setupthinrules</code></a> to change space between the lines, color and thickness of the rule, etc.) Thus, to get the result shown above, I needed:</p>
<pre><code>Fill in the blanks \thinrules[n=2] </code></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/698/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/698/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/698/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/698/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/698/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/698/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/698/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/698/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/698/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/698/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/698/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/698/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/698/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/698/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=698&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2011/04/30/fill-in-the-blanks-in-context/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>

		<media:content url="http://randomdeterminism.files.wordpress.com/2011/04/blanks.png" medium="image">
			<media:title type="html">blanks</media:title>
		</media:content>
	</item>
		<item>
		<title>Would a table by any other name be as useful</title>
		<link>http://randomdeterminism.wordpress.com/2011/03/28/would-a-table-by-any-other-name-be-as-useful/</link>
		<comments>http://randomdeterminism.wordpress.com/2011/03/28/would-a-table-by-any-other-name-be-as-useful/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 03:48:16 +0000</pubDate>
		<dc:creator>randomdeterminism</dc:creator>
				<category><![CDATA[ConTeXt]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[natural tables]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://randomdeterminism.wordpress.com/?p=690</guid>
		<description><![CDATA[Karl Berry recently blogged about creating the following in TeX: A 6&#215;6 grid of pictures, with a big picture of &#8230;<p><a href="http://randomdeterminism.wordpress.com/2011/03/28/would-a-table-by-any-other-name-be-as-useful/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=690&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Karl Berry recently <a href="http://www.advogato.org/person/karlberry/diary/199.html">blogged</a> about creating the following in TeX:<br />
<a href="http://randomdeterminism.files.wordpress.com/2011/03/photo.png"><img class="alignright size-full wp-image-691" title="photo" src="http://randomdeterminism.files.wordpress.com/2011/03/photo.png?w=529" alt="photo table"   /></a></p>
<blockquote><p>A 6&#215;6 grid of pictures, with a big picture of size 2&#215;2 in the middle. All pictures should be surrounded by a border.</p></blockquote>
<p>Karl said that he tried <code>pdfpages</code> package but, in the end, used low-level <code>\halign</code>. Ouch! Use <code>\halign</code>. I don&#8217;t know how many people who start with LaTeX or ConTeXt actually know the syntax of <code>\halign</code>. But what I find shocking is that Karl&#8217;s next best choice was <code>pdfpages</code>, a package to combine pdf pages. <em>Is the state of affairs with LaTeX tables so bad?</em></p>
<p>I tried to achieve that same layout in ConTeXt, and it was really simple.</p>
<pre><code>    % Placeholders for figures
    \useexternalfigure[photo] [cow]   [width=2cm, height=1.5cm]
    \useexternalfigure[center][cow]   [width=4cm, height=3cm]

    \setupTABLE[each][each][framecolor=lightred, rulethickness=3bp, frame=on, strut=off]

    \starttext

    \startTEXpage
    \bTABLE
      \bTR
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
      \eTR
      \bTR
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
      \eTR
      \bTR
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD[nr=2,nc=2] \externalfigure[center]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
      \eTR
      \bTR
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
      \eTR
      \bTR
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
      \eTR
      \bTR
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
        \bTD \externalfigure[photo]\eTD
      \eTR
    \eTABLE
    \stopTEXpage

    \stoptext
</code></pre>
<p>Notice the <code>[nr=2,nr=2]</code> for the middle cell. This tells ConTeXt that the middle cell spans 2 rows and 2 columns. And thats it!</p>
<p>For another, more extreme, example see Willi Egger&#8217;s <a href="http://dl.contextgarden.net/myway/NaturalTables.pdf">My Way</a> on drawing <em>type cases</em> (wooden cases with boxes for storing letter types) used in hand typesetting.</p>
<p><strong>Edit:</strong> In a <a href="http://latex-alive.tumblr.com/post/4181257183/non-textual-tabular-requirements-i-once-wrote-a">follow-up post</a>, Will Robertson said that he does not like the verbose syntax of ConTeXt tables. Neither do I. As a matter of fact, ConTeXt has multiple <a href="http://wiki.contextgarden.net/Tables_Overview">table implementations</a>. The oldest table macros, <code>\starttable ... \stoptable</code> were just a wrapper around the <a href="http://www.pctex.com/addons.html">TaBlE macros </a> by Michael Wichura. The syntax of this macro is:</p>
<pre><code>\starttable
     \NC .... \NC .... \NC .... \NC \NR
     \NC .... \NC .... \NC .... \NC \NR
     \NC .... \NC .... \NC .... \NC \NR
\stoptable
</code></pre>
<p>But this mechanism is not as powerful as natural tables (that is what the mechanism that I posted is called). There is, however, a wrapper around natural tables that uses the syntax of the old table macros but provides most of the functionality of natural tables: </p>
<pre><code>\startTABLE
     \NC .... \NC .... \NC .... \NC \NR
     \NC .... \NC .... \NC .... \NC \NR
     \NC .... \NC .... \NC .... \NC \NR
\stopTABLE
</code></pre>
<p>This is meant for simple tables. Therefore, the <code>\NC</code> macro does not accept optional arguments. As a result, we cannot use this simpler interface to get the above result. Unless, of course, we cheat. Note the definition of <code>\TC</code> (tablular cell) below and the deliberate use of <code>\1</code> and <code>\9</code> to make the code appear less verbose <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre><code>\setupTABLE[each][each][frame=on, rulethickness=3bp, rulecolor=lightred]
\def\TC{\eTD \dobTD}

\def\1{\externalfigure[cow][width=2cm, height=1.5cm]}
\def\9{\externalfigure[cow][width=4cm, height=3cm]}

\starttext

\startTABLE
  \NC \1 \NC \1 \NC \1 \NC \1     \NC \1 \NC \1 \NC \NR
  \NC \1 \NC \1 \NC \1 \NC \1     \NC \1 \NC \1 \NC \NR
  \NC \1 \NC \1 \TC[nc=2,nr=2] \9 \NC \1 \NC \1 \NC \NR
  \NC \1 \NC \1                   \NC \1 \NC \1 \NC \NR
  \NC \1 \NC \1 \NC \1 \NC \1     \NC \1 \NC \1 \NC \NR
  \NC \1 \NC \1 \NC \1 \NC \1     \NC \1 \NC \1 \NC \NR
\stopTABLE

\stoptext
</code></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdeterminism.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdeterminism.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdeterminism.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdeterminism.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdeterminism.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdeterminism.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdeterminism.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdeterminism.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdeterminism.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdeterminism.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdeterminism.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdeterminism.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdeterminism.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdeterminism.wordpress.com/690/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdeterminism.wordpress.com&amp;blog=6015750&amp;post=690&amp;subd=randomdeterminism&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdeterminism.wordpress.com/2011/03/28/would-a-table-by-any-other-name-be-as-useful/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8d2ae37ec7f8038091cdfde1734774da?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdeterminism</media:title>
		</media:content>

		<media:content url="http://randomdeterminism.files.wordpress.com/2011/03/photo.png" medium="image">
			<media:title type="html">photo</media:title>
		</media:content>
	</item>
	</channel>
</rss>
