# Scripts

Here you can find bits and pieces of scripts that I’ve knocked together over the years. Some more will be added when I have the time! These were all written for my own personal use, so I suggest you only use them if you are familiar with their workings and are confident that you can spot my mistakes!

## Plain-Text XSLT for XML Cellar Notes

Probably not much use at the moment, as it is designed for use with XML Cellar Notes Doctype (when finalised!).

port.xsl

The Gopher RSS Viewer allows you to view most RSS feeds in gopherspace. It uses an XSLT style-sheet to transform the XML of the RSS feed into plain-text, suitable for viewing with gopher.

Due to the nature of gopherspace, it requires a number of files. showfeed.txt should be edited to have change the directory requirements, made executable and then served with file-type 7. rss.txt should be dealt with, likewise, and placed in the same directory, along with the two XSLT files rss.xsl and atom2rss.xsl (the atom2rss file is courtesy of GreekHood). For an example of it in action, see gopher://sdf-eu.org/1/users/jacobh/rss.

## PHP Sitemap XML Generator

Various search engines are promoting the use of XML to create website sitemaps. The specification is outlined at http://www.sitemaps.org. Although the creation of such an XML DTD is generally to be welcomed, unfortunately, its implementation is very much geared towards search engine rather than webmaster use (e.g. titles or descriptions of the pages are not included). Nevertheless, it is always worth embracing technology that will assist the cataloguing of websites.

In order to implement the sitemap protocol on my website, I modified an existing XML sitemap generator to comply with the new specification. When included on each page of the website, it works by checking the sitemap XML each time a page is loaded and updating it, if necessary. It is therefore designed to be an “install and forget” way of complying with the new specifications.

To use this script, first create a file called sitemap.xml in the root directory of your website and make it writable by your webserver. Into this, write the following:
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> </urlset>

## Simple PHP Email Viewer (for IMAP) v.1.02

Although there are hundreds of webmail scripts in existence, few specialise in only viewing emails, rather than managing or sending them. I therefore wrote this script for viewing my emails in a very light weight and simple fashion. I find it particularly useful for use with mobile phones or dodgy internet connections where even my usual webmail client (Squirrelmail) struggles.

The original intention was to have the user-name and password hard-wired into the script. This meant that anyone who could view the page could view your emails. This was deliberate: I did not want the hassle of loading a separate log-in page and I kept the page secure with my webserver’s settings. Since version 1.02, you can leave the user-name and password blank to be prompted for them, although cookies will then need to be used to allow all functionality.

To use the script, download it; open it in your favourite text editor; change the user variables; save it with an extension of .php and upload it to a secure, password protected, area of you webspace.

### Changelog

1.02: allow script to prompt for user-name and password. Small formatting changes and internal navigation.

1.01: open the IMAP box in read-only state. Various bug corrections.

1: original release.

## PortID PHP Function

This script was written to help sort through some cellar notes. It aims to guess the name, producer and date of a bottle of Port from a string. It is fairly accurate: it includes details of over 125 Port shippers and can make allowances for the most common typos.

The PortID script creates a php function which, when called returns an array containing:
[0] Date (0 if undetermined/non-vintage)
[1] Port Shipper/Producer
[2] Style of port (vp/sqvp/lbv/tawny/colheita/ruby)
If more than one date, shipper or style is present in the string the function returns the first positive result.

Example Useage:
include('./portid.inc');
$port=(portid('My first quality Colhieta [sic] the 1900 Neipoort [sic]')); echo "Shipper:$port[1]. Style: $port[2]. Year:$port[3]";
This returns: “Shipper: Niepoort. Style: colheita. Year: 1900”

NB. This function uses a number of accents. For best results, use UTF-8!

## XeTeX Hanging Punctuation

Hanging punctuation is a typographical technique whereby punctuation marks at the start or end of a line of text are placed slightly outside the main text block and into the margin. The result of this is that the text block appears to have straighter edges, as each line ends with a visually solid letter. It is a technique that is most often associated with fine typography (it was famously used by Gutenberg in his 42-line Bible) so may not be to everyone’s taste!

Whilst pdftex has allowed hanging punctuation to be implemented by the manipulation of the Microtypography features of the PDF format, there is no such easy system for XeTeX. Knuth provides some macros in Section D of the Tex Book but these need to be manipulated to work with XeTeX’s Unicode support. I would suggest doing as follows:

\newdimen\commahang \setbox0=\hbox{,} \commahang=\wd0 \newdimen\periodhang \setbox0=\hbox{.} \periodhang=\wd0 \newdimen\colonhang \setbox0=\hbox{:} \colonhang=\wd0 \newdimen\scolonhang \setbox0=\hbox{;} \scolonhang=\wd0 \newdimen\exhang \setbox0=\hbox{!} \exhang=\wd0 \newdimen\queshang \setbox0=\hbox{?} \queshang=\wd0 \newdimen\rquotehang \setbox0=\hbox{’} \rquotehang=\wd0 \newdimen\rdquotehang \setbox0=\hbox{”} \rdquotehang=\wd0 \newdimen\quotehang \setbox0=\hbox{‘} \quotehang=\wd0 \newdimen\qquotehang \setbox0=\hbox{“} \qquotehang=\wd0 \newskip\zzz \def\allowhyphens{\nobreak\hskip\zzz} \def\comma{,\kern-\commahang\kern\commahang} \def\period{.\kern-\periodhang\kern\periodhang} \def\colon{:\kern-\colonhang\kern\colonhang} \def\scolon{;\kern-\scolonhang\kern\scolonhang} \def\exclaim{!\kern-\exhang\kern\exhang} \def\question{?\kern-\queshang\kern\queshang} \def\rquote{’\kern-\rquotehang\kern\rquotehang} \def\rdquote{”\kern-\rdquotehang\kern\rdquotehang} \def\lquote{\ifhmode\kern\quotehang\vadjust{}\else\leavevmode\fi \kern-\quotehang ‘\allowhyphens} \def\lquotes{\ifhmode\kern\qquotehang\vadjust{}\else\leavevmode\fi \kern-\qquotehang“\allowhyphens} \catcode,=\active \let,=\comma \catcode.=\active \let.=\period \catcode:=\active \let:=\colon \catcode;=\active \let;=\scolon \catcode!=\active \let!=\exclaim \catcode?=\active \let?=\question \catcode’=\active \let’=\rquote \catcode‘=\active \let‘=\lquote \catcode“=\active \let“=\lquotes \catcode”=\active \let”=\rdquote

NB, these macros should be inserted after a Unicode compliant font is loaded (e.g. after declaring \font\rm="My Font" at 10pt \rm). For the record, I also omitted to change Knuth’s American “period” to “full stop” for reasons of consistency!

To achieve hanging hyphens is more difficult as the insertion of hyphens is pretty much hard-wired into TeX. Knuth’s suggestion is to use a “zero-width hyphen”. Unfortunately, such a thing does not exist in either the Unicode standard or any fonts! The solution, therefore, is to make the zero-width hyphen oneself. Using a programme such as Font Forge open the font (after taking a backup!). Press the hyphen key on your keyboard to locate the hyphen and then press Ctrl+C to copy the glyph. Scroll down to slot U+E000 in the private use area of the encoding (this is a long way down). Click on it and then use Ctrl+V to paste the glyph. Now double-click on the glyph to open it. Drag the right-hand-most line across the glyph so that it is next to the left-hand-most line (this can be adjusted to taste, if necessary). This makes the width of the hyphen zero. Press Ctrl+Shift+G and save the font. Close Fontforge and reinstall the font file which you saved. Repeat this for your other fonts, taking backups as you go!

Now, in your tex file for each font you are using copy this line: \hyphenchar\rm= changing \rm to the name of the font. The final character in that line of code is U+E000 so it will appear as a question mark, empty square or similar on this webpage. According to the TeXBook \defaulthyphenchar= should also work for all fonts, but I have not had any success in doing so with XeTeX. Now, when you run TeX on your file, rather than using the standard hyphen, TeX will choose your new Zero-Width hyphen which will protrude into to margin and appear to hang.

The following image shows the default behaviour (without hanging punctuation); the behaviour with hanging punctuation and the behaviour with hanging punctuation and zero-width hyphens. Please note that it is somewhat contrived so that every line ends with a punctuation character!

## LaTeX Skeleton– Argument Template

For the College of Law’s G.D.L. competition, I designed a template for producing correctly–formatted skeleton arguments in LaTeX. If you would like a copy, you can download the stand–alone .tex file or see a preview of the resulting PDF. Although the template conforms to all the requirements of the mooting competition for which it was designed, it is advisable to consult the rules before using it elsewhere. At some stage it could be turned into a real package. At the moment it is presented as a self–contained file with so that it is easier to modify for those with less experience of LaTeX. I would suggest, if it is to be used in anger, to use a more modern version of LaTeX or TeX, such as XeTeX in combination with professional typefaces, rather than the Computer Modern LaTeX defaults.