<?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>Mark's Blog &#187; Software</title>
	<atom:link href="http://longair.net/blog/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://longair.net/blog</link>
	<description>(occasional miscellanea)</description>
	<lastBuildDate>Tue, 03 Aug 2010 09:59:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Hashing Flickr Photos</title>
		<link>http://longair.net/blog/2009/12/19/hashing-flickr-photos/</link>
		<comments>http://longair.net/blog/2009/12/19/hashing-flickr-photos/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:30:27 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[flickr scripting]]></category>

		<guid isPermaLink="false">http://longair.net/blog/?p=405</guid>
		<description><![CDATA[<p>I used to host my photos with a simple set of CGI scripts that basically worked well enough for my simple requirements.  Such web applications are easy and fun to write, but in the end I decided that it wasn&#8217;t worth it because:</p> Hosting large amounts of data on a generic shell account is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/mhl20/4197661773/"><img class="alignright" src="http://farm3.static.flickr.com/2756/4197661773_d671c5feea_m.jpg" alt="" width="240" height="124" /></a>I used to host my photos with a simple set of CGI scripts that basically worked well enough for my simple requirements.  Such web applications are easy and fun to write, but in the end I decided that it wasn&#8217;t worth it because:</p>
<ul>
<li>Hosting large amounts of data on a generic shell account is typically quite expensive.  <a href="http://www.flickr.com">Flickr</a>&#8216;s <a href="http://www.flickr.com/upgrade/">&#8220;pro&#8221; account subscription</a> is a very good deal in comparison: as long as each photo is beneath 20 megabytes in size, you can upload as many as you like for $24.95 a year.</li>
<li>The community aspect of sites like Flickr is very encouraging &#8211; it&#8217;s lovely to have random people say nice things about your photographs, and occasionally have people use them in articles, etc.</li>
</ul>
<p>(Some people are put off from using Flickr by the appearance of the site, but its API means that there are plenty of alternative front-ends for viewing or presenting your photos, such as <a href="http://www.flickriver.com/photos/mhl20/">flickriver</a>.)</p>
<p>The slight problem with switching to hosting on Flickr was that previously I&#8217;d indexed all my photos by the MD5sum of the original image, so several of my pages had links or inline images that pointed to an MD5sum-based URL on the old site.  It occurred to me that it might be useful in general to have <a href="http://www.flickr.com/groups/api/discuss/72157594497877875/">&#8220;machine tags&#8221;</a> on each photo with a hash or checksum of the image, so that, for example:</p>
<ul>
<li>You can simply check which photos have already been uploaded.</li>
<li>You can find URLs for all the different image sizes, etc. based on the content of the file.</li>
</ul>
<p>Unfortunately, I hadn&#8217;t done this when uploading the files in the first place, so had to write a script (<a href="http://github.com/mhl/flickr-checksums/blob/master/flickr-checksum-tags.py">flickr-checksum-tags.py</a>) which takes the slightly extraordinary step of downloading the original version of every photo that doesn&#8217;t have the checksum tags to a temporary file, hashing each file, adding the tags and deleting the temporary file.  This add tags for the MD5sum and the SHA1sum, using a namespace and keys <a href="http://www.flickr.com/groups/api/discuss/72157594497877875/#comment72157594506503786">suggested in this discussion</a>, where someone suggests taking the same approach. These tags are of the form:</p>
<pre>
  checksum:md5=c629c63f8508cfd1a5e6ba6b4b3253a8
  checksum:sha1=df44fc771660fbe7a2d6b2e284ae61e9ed3e377c
</pre>
<p>The same script can return URLs for a given checksum:</p>
<pre>
  # ./flickr-checksum-tags.py -m c629c63f8508cfd1a5e6ba6b4b3253a8 --short
  > http://flic.kr/p/7oQxqK
  # ./flickr-checksum-tags.py -m c629c63f8508cfd1a5e6ba6b4b3253a8 -p
  > [... the Flickr photo page URL, which WordPress insists on turning into an image ...]
  # ./flickr-checksum-tags.py -m c629c63f8508cfd1a5e6ba6b4b3253a8 --size=b
  > http://farm3.static.flickr.com/2552/4196574615_491c6387f8_b.jpg
</pre>
<p>The <a href="http://github.com/mhl/flickr-checksums">repository</a> also has a <a href="http://github.com/mhl/flickr-checksums/blob/master/find-not-uploaded.py">script to pick out files that haven&#8217;t been uploaded</a>, and a <a href="http://github.com/mhl/flickr-checksums/blob/master/flickr-upload.py">simple uploader script</a> which will upload an image and add the checksum tags.  The scripts are based on the very useful Python <a href="http://stuvel.eu/projects/flickrapi">flickrapi module</a> and you&#8217;ll need to put your Flickr API key and secret in <tt>~/.flickr-api</tt></p>
<p>Anyway, these have been useful for me so maybe of some interest to someone out there&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://longair.net/blog/2009/12/19/hashing-flickr-photos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LyX Tips for Thesis Writing</title>
		<link>http://longair.net/blog/2009/11/11/lyx-tips-for-thesis-writing/</link>
		<comments>http://longair.net/blog/2009/11/11/lyx-tips-for-thesis-writing/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 15:22:42 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[PhD Work]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://longair.net/blog/?p=304</guid>
		<description><![CDATA[<p>LyX is a lovely bit of software for preparing beautiful documents &#8211; you get the high quality output of LaTeX and the advantages of logical document description in a usable interface and without having to remember TeX syntax.  There are a few aspects of using LyX that puzzled me while writing a certain large [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lyx.org">LyX</a> is a lovely bit of software for preparing beautiful documents &#8211; you get the high quality output of LaTeX and the advantages of logical document description in a usable interface and without having to remember TeX syntax.  There are a few aspects of using LyX that puzzled me while writing <a href="http://longair.net/blog/2009/10/21/thesis-visualization/">a certain large document</a>, however &#8211; many of these are dealt with in the <a href="http://wiki.lyx.org/FAQ/">LyX FAQ</a>, but I thought it would be worth collecting those that were most useful to me here.</p>
<h3>Use pdflatex for Output</h3>
<p>There are various different options for generating output PDF output in LyX, but it will save you trouble if you do everything using <strong>pdflatex</strong> in the first place. (I think this is the upshot of the <a href="http://wiki.lyx.org/FAQ/PDF#toc14">slightly unclear advice in the FAQ</a> on the subject.) This turned out to be particularly important because when your document is 50000 words long and has over 100 figures, the other methods take over 10 minutes to generate a PDF; pdflatex would finish in a couple of seconds. If you take this advice then you have to change the <em>Document -&gt; Settings -&gt; Document Class</em> option to pdfTeX, or you get some surprising errors. Also, I would strongly recommend that you only use PNG files for bitmap images and PDF for vector graphics. (PNG is obviously sensible, but in the case of vector graphics I found PS and EPS files unexpectedly awkward in terms of getting the orientation and clipping right.)</p>
<h3>Incorrect Colours in Bitmap Graphics</h3>
<p>I came across a bizarre problem where the colours would be slightly wrong for certain PNG files that I include in the document. (I suppose I should say &#8220;colors&#8221; too, just for the sake of searchers using American English.) This turned out to be a problem with full-colour PNG images with transparency (i.e. RGBA images), which my notes say is discussed further <a href="http://forums.adobe.com/thread/395348">in</a> <a href="http://forum.planetpdf.com/wb/default.asp?action=9&amp;fid=106&amp;read=62468">these</a> <a href="http://sarovar.org/tracker/?func=detail&amp;atid=493&amp;aid=896&amp;group_id=106">posts</a>. Setting the PDF version as suggested in the first of those posts didn&#8217;t help me at all, so I had to convert all my RGBA PNG files to RGB. If you want to check for these files you can use file(1), something like:</p>
<pre>find . -type f -iname '*.png' -print0 | xargs -n 1 -0 file | egrep RGBA</pre>
<p>&#8230; and I fixed them by feeding the filenames (one per line) to a script like:</p>
<pre>#!/bin/sh

set -e

while [ $# -ne 0 ]
do
 t=`mktemp`
 convert "$1" png24:"$t" &amp;&amp; mv "$t" "$1"
 shift
done</pre>
<p>Obviously you need imagemagick installed for the &#8220;convert&#8221; command.</p>
<h3>Footnotes</h3>
<p>By default there is no extra vertical space to separate footnotes, but I much prefer there to be a small gap. To do that, add to the following line to the document preamble:</p>
<pre>\setlength{\footnotesep}{12pt}</pre>
<h3>Captions</h3>
<p>By default, the formatting of caption text in floated figures looks very similar to the main body text. Somewhere on the web I found the recommendation to use the &#8220;caption&#8221; package to change this, e.g. by adding the following to the preamble:</p>
<pre>\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=endash]{caption}</pre>
<h3>Fitting Tables Onto Pages</h3>
<p>Making tables fit on the page is annoying &#8211; just changing the text size often doesn&#8217;t reduce the overall size or causes a horrible font to be used. Resizing the whole table is the best way I found. Before the table (either in a float or in the normal flow of the document) I added the following in ERT:</p>
<pre> \resizebox{\textwidth}{!}{%</pre>
<p>and then immediately after the table added, again in ERT:</p>
<pre> }</pre>
<p>This scales the table such that the width of the table fits the page width.</p>
<h3>Suppressing Pages Numbers For Full Page Figures</h3>
<p>If you want to use a whole page for a floated figure, the page number can overlap with the figure or just look odd.  However, second tip here: <a title="http://wiki.lyx.org/FAQ/UnfloatingFigureOnEmptyPage" rel="nofollow" href="http://wiki.lyx.org/FAQ/UnfloatingFigureOnEmptyPage">http://wiki.lyx.org/FAQ/UnfloatingFigureOnEmptyPage</a> works well to remove page numbers from all-page figures. To summarize, add the following to the preamble:</p>
<pre>\usepackage{floatpag}
\floatpagestyle{plain} % Default page style for pages with only floats</pre>
<p>Then, in ERT before the figure (but still in the float) add:</p>
<pre>\thisfloatpagestyle{empty}
\vspace{-\headsep}</pre>
<p>&#8230; and similarly, after the figure but above the caption add:</p>
<pre>\vspace{0.3cm}</pre>
<p>&#8230; or you may find the caption too close to the graphics.</p>
<h3>Better On-Screen Fonts in PDFs</h3>
<p>As explained in the second question in this <a href="http://www.mail-archive.com/lyx-docs@lists.lyx.org/msg00209.html">mini-FAQ on generating PDFs from LyX</a> you should use the outline font version of Computer Modern instead of the bitmapped versions. For me, this boiled down to going to Document -&gt; Settings -&gt; Fonts and setting the Roman font option to &#8220;AE (Almost European)&#8221;.</p>
<p>You can further improve the rendering of text in your output by using <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/microtype/">microtype</a>. Just add</p>
<pre>\usepackage{microtype}</pre>
<p>&#8230; to the preamble. (These suggestions only apply if you&#8217;re using the pdflatex workflow as suggested above.)</p>
<h3>Adding Footnotes in Tables</h3>
<p>You might notice that adding footnotes in table cells doesn&#8217;t work. One <a href="http://wiki.lyx.org/LyX/Tables#toc12">answer to this</a> is manually add them in ERT with <tt>\footnotemark</tt> and <tt>\footnotetext</tt>, possibly adjusting the counter as described in that FAQ entry.</p>
]]></content:encoded>
			<wfw:commentRss>http://longair.net/blog/2009/11/11/lyx-tips-for-thesis-writing/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
