UnicAPL - Unicode APL code in GNU Emacs and LaTeX



GNU Emacs Lisp definitions: apl.el

XEmacs is currently not supported.

A screenshot: latex.png

A video demonstration: unicapl.mpg (0.3MB)


Getting started

Copy apl.el to your load-path and add to your .emacs:
	(require 'apl)
    
You can also specify a font for APL characters. For example, GNU Unifont (install it!) provides all relevant glyphs. Append:
      (apl-set-font "-gnu-unifont-*-r-*--*-*-*-*-*-*-ISO10646-1")
    
to your .emacs. With Emacs 22 and later, you can use the shorter form:
      (apl-set-font '("gnu-unifont" . "ISO10646-1"))
    

Emacs is getting increasingly better at handling Unicode, and more recent versions may choose the right glyphs for all characters automatically, sometimes drawing from various fonts. You therefore may not need "apl-set-font" at all. However, you may still find it useful to enforce a uniform font for all APL characters.


Unicode from ASCII transliterations

After restarting Emacs, you have a new input-method to enter Unicode APL characters with a standard US or European keyboard, using Jim Weigang's ASCII transliterations: Do M-x set-input-method (C-x C-m C-\, or C-u C-\) and specify apl-ascii (confirm with RET). Toggle it using M-x toggle-input-method (C-\). If it is activated, "apl" is displayed in the mode line. See modeline screenshot. You can do M-x describe-input-method (C-h I) and specify "apl-ascii" (or hit RET for the currently enabled method) to display the defined correspondence between key sequences and characters. Enter {rho}, {iota} etc. and see that Emacs performs the translation to Unicode characters dynamically. If such ASCII sequences already occur in the buffer, you can translate them to their Unicode APL codepoints with M-x apl-ascii-to-unicode.

A reference sheet showing available ASCII sequences (omitting surrounding curly braces) and their APL counterparts: asciiapl.pdf

Simulating a Union keyboard

On X Windows systems, you can use xmodmap to activate a keyboard layout close to the APL "Union keyboard", which lets you enter APL symbols faster. First, do
      xmodmap -pke > old_layout.txt
    
to save you current keyboard layout. Then, download usapl.txt and do
      xmodmap usapl.txt
    

The layout is taken from, and compatible with the A+ keyboard. If you already have a customized version of that layout, it will work too.

The layout is now set to yield rarely-used (in English texts) Latin-1 characters if you press AltGr + key. For example, AltGr + i yields capital E with acute accent (U+00C9), one example of a (Latin-1) character that A+ uses in its custom encoding of APL for something else, namely to denote iota. To translate these key strokes to the expected APL Unicode codepoints in Emacs, do M-x apl-toggle-aplus-layout. To disable the translation, execute the function again. The keyboard layout is reset every time you restart X. You can also switch to your previous layout via "xmodmap old_layout.txt". (For recent versions of X and xmodmap, it is also possible to set up a keyboard layout that generates the proper APL Unicode characters directly.)

Saving APL programs

Regardless of what method you choose for input, you end up with Unicode characters in your buffer. To save your files, you can use UTF-8 encoding. The coding system currently in use is also displayed in the mode line. On the previous modeline screenshot, you see "1" (standing for: Latin-1) to the right of "apl". Change coding systems using M-x set-buffer-file-coding-system (or C-x C-m f) , and specify utf-8. UTF-8 is indicated by "u" in the mode line.

Typesetting APL


To typeset APL programs, you can use LaTeX. You need To embed APL programs anywhere in the document, add the following before \begin{document} in the LaTeX-file:
      \usepackage[utf8]{inputenc}
      \input apl
    
Then, use verbatim-environments containing APL programs with Unicode characters. Save your file in UTF-8 encoding and place "apl.tex" and "cmapl10.mf" in the same directory as the document. Run latex or pdflatex to generate DVI or PDF documents. A screenshot of a rendered document: round.png.

The ASCII-APL reference sheet was typeset with this method. Its source is asciiapl.tex. It was largely generated by asciiapl.cpp.

The LaTeX definitions currently don't cover all APL symbols you can enter in Emacs (they cover all symbols on the reference sheet, though). For code exchange, you can transmit the UTF-8 encoded source directly if the receiver has a Unicode-capable editor. To make LaTeX aware of other symbols, append appropriate \DeclareUnicodeCharacter definitions to apl.tex and design the glyphs in METAFONT if they can't be constructed from available symbols.



Interoperability with A+

To convert the APL symbols in an A+ source file to their Unicode equivalents, mark the whole buffer (M-x mark-whole-buffer or C-x h) and do M-x apl-aplus-to-unicode. Conversely, do M-x apl-unicode-to-aplus on a region to convert it to A+ format.

You can thus easily generate PDF documents from A+'s plain text documentation by embedding the result of the conversion in a LaTeX verbatim environment. Some files of A+'s documentation in PDF format: The corresponding source files are: GettingStarted.tex, ScalarFunctions.tex, Syntax.tex, SimpleArrays.tex, Assignment.tex, NestedArrays.tex.

Closing remarks

View a page with a Unicode APL program: primes.

Send a nice Unicode APL program to me, either using M-x compose-mail (C-x m) in Emacs, by copying the characters to your mailer, or as an attachment!

To APL vendors: If you want to port your system to several platforms, consider using Emacs as a portable interface (which can also be used for sending mails with Unicode APL programs, for IRC chats involving Unicode etc.).

All code on this page is placed in the public domain. Use any portions you want for any purpose.


Main page