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!

Simple PHP Email Viewer
PortID PHP Function
XeTeX Hanging Punctuation
LaTeX Skeleton Argument Template

Simple PHP Email Viewer (for IMAP) v.1.01

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.

Please note that the user-name and password for the mailbox are hard-wired into the script. This means that anyone who can view the page can view your emails. This is deliberate: I did not want the hassle of loading a separate log-in page. The way to keep the page secure is to put the script in a secure part of your webserver, though it would be little trouble to add a login page if anyone would like it!

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.

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.

A copy of the file (portid.inc) is available for download.

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!

Examples of the output generated by the above code.

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.