# Code

Software I develop and maintain:

# LaTeX: Cleveref package

LaTeX: Cleveref package 27 March 2018 The Cleveref package (also available from CTAN) does clever things with cross-references:

• automatic formatting of cross-references based on the type of object referred to (chapter, section, equation, theorem, etc.);
• full control and customisation of the reference format;
• cross-references and page references to multiple items;
• automatic (optional) sorting and compression of multiple cross-references or page references;
• optional output of a sed script that can strip out Cleveref commands and replace them with standard LaTeX, allowing Cleveref to be used e.g. in articles sent to journals or collaborators that don't (yet!) support Cleveref.

A number of other LaTeX packages provide similar features. Some are venerable enough to be documented in The LaTeX Companion, or even included in the standard LaTeX distribution itself. But all those that I've come across provide only a subset of the Cleveref features. (See the Introduction to the package documentation for some comparisons.)

## Documentation

Full documentation is available in a variety of formats, for download and viewing online. (Since the package is in DocTeX format, the source for the documentation is the same as the package itself.)

• PDF file
• Postscript file (gzipped)

The latest release of the Cleveref package is version 0.21.4 (released March 2018).

Note that this is a pre-release version, which is a not currently available on CTAN, and should not (yet) be considered fully stable. Please report any issues or bugs that you encounter, and check back here periodically for updates. Note that the version number is only finally fixed once the version is uploaded to CTAN. Pre-release versions may be updated without any change to the version number. Compare package dates to see if you hav

# Emacs: Data structure packages

Emacs: Data structure packages 16 August 2017 These packages provide basic (and not so basic) data structures. They are all relatively stable, though bug-fixes and new features are added occasionally. (Latest update: August 2017).

In recent versions of Emacs (>=24.1), you can install all the non-obsolete packages from within Emacs itself, via GNU ELPA. Use M-x list-packages and take it from there. This is the preferred installation method. (Occasionally, the ELPA version might lag slightly behind the latest version available here.)

• Git repository: http://www.dr-qubit.org/git/predictive.git
• heap.el (version 0.5)
• queue.el (version 0.2)
• avl-tree.el (already included in Emacs >=24.1)
• tNFA.el (version 0.1.1; requires queue.el)
• tstree.el (obsolete! Use trie.el instead)
• trie.el (version 0.4; requires everything except dict-tree.el)
• dict-tree.el (version 0.14; requires everything else)

## Documentation

The functions these packages provide are well documented using Emacs' built-in documentation features. Brief descriptions of the data structures follow:

### Heaps

A heap is a form of efficient self-sorting tree. In particular, the root node is guaranteed to be the highest-ranked entry in the tree. (The comparison function used for ranking the data can, of course, be freely defined). They are often used as priority queues, for scheduling tasks in order of importance, and for implementing efficient sorting algorithms (such as heap-sort).

• heap.el (version 0.5)

### Queues

A queue can be used both as a first-in last-out and as a first-in first-out stack, i.e. elements can be added to and removed from the front or back of the queue. (This library is an updated re-implementation of the old Elib queue library.)

• queue.el (version 0.2)

### Tagged Non-deterministic Finite state Automata

Features of modern regexp implementations, including Emacs', mean

# Emacs: Miscelaneous packages

Emacs: Miscelaneous packages 12 June 2015 These packages provide miscelaneous features I needed at some point. So I coded them. Currently, they're all to do with displaying useful information in the mode line.

show-point-mode displays the current value of the point in the mode line. I primarily find it useful when debugging Elisp code that uses overlays and markers.

wc-mode displays output similar to the Unix wc command in the mode line, i.e. the character count, word count and line count for the current buffer. (I primarily find this Useful when writing grant applications with character or word limits. Though I'm sure it's useful for other more productive activities, too…)

• show-point-mode.el (version 0.3)
• wc-mode.el (version 0.3)

# Matlab code

Matlab code 28 December 2013 I've collected here various functions, routines, and other bits of Matlab, Octave and Mathematica code organized by topic, that might save someone, somewhere, from re-inventing the wheel. Some of them are so simple it would probably be quicker to re-code them than find this page, but since you're here anyway…

Comments within the code should be enough to figure out what they do and how to use them (try help <function> from within Matlab or Octave). No guarantee they work as advertised, but I use them myself so I do correct bugs when I come across them. The Matlab code should run under both Octave and Matlab.

If you make use of this code in your research, consider including a citation to this web page in any resulting publication. Not only is it fair to give credit when you've made use of other people's work, it is important for scientific reproducability to document any code you used to help produce your results. Also, if you found this code useful, then others probably will too! Citing this page helps others find it.

I leave it to your judgement whether you feel your results made sufficient use of this code to warrant a citation; I do not insist on it. But consider whether using this code has been as helpful to your research as the least useful paper you are citing. (Typically, this sets the bar very low!). If so, you should probably include a citation to this web page.

## Quantum Information Package

For convenience, all the Matlab/Octave functions related to quantum mechanics and quantum information theory are also available in a single bundle, as well as individually (below).

• Quantinf package (version 0.5.1)

## Linear algebra

Partial trace:$$TrX(\rho \text{ or } \psi, sys, dim)$$
Par

# Emacs: Undo Tree package

Emacs: Undo Tree package 8 August 2013 Emacs has a powerful undo system. Unlike the standard undo/redo system in most software, it allows you to recover any past state of a buffer (whereas the standard undo/redo system can lose past states as soon as you redo). However, this power comes at a price: many people find Emacs' undo system confusing and difficult to use, spawning a number of packages that replace it with the less powerful but more intuitive undo/redo system. (See the Emacs Wiki.)

Both the loss of data with standard undo/redo, and the confusion of Emacs' undo, stem from trying to treat undo history as a linear sequence of changes. It's not. The undo-tree-mode provided by this package replaces Emacs' undo system with a system that treats undo history as what it is: a branching tree of changes. This simple idea allows the more intuitive behaviour of the standard undo/redo system to be combined with the power of never losing any history. An added side bonus is that undo history can in some cases be stored more efficiently, allowing more changes to accumulate before Emacs starts discarding history.

It gets better. You don't have to imagine the undo tree, because undo-tree-mode includes an undo-tree visualizer which draws it for you, and lets you browse around the undo history.

The only downside to this more advanced yet simpler undo system is that it was inspired by Vim. But, after all, most successful religions steal the best ideas from their competitors!

## Documentation

Details of the undo-tree-mode commands and key bindings can be found in the Commentary section at the top of the undo-tree.el file itself, along with an extended explanation (with diagrams!) of the differences between the undo-tree-mode, standard Emacs' undo, and undo/redo systems.

The commands themselves are all documented using the standard, built-in Emacs documentation features. Customization options can be found under the undo-tree customization group.

In recent v

# Emacs: Auto-Overlays package

Emacs: Auto-Overlays package 22 February 2013 The Auto-Overlays package allows you to define overlays that are created (and updated and destroyed) automatically when text in a buffer matches a regular expression.

Various classes of automatic overlay are provided, to make it easy to define matches for different text regions: words, lines, regions enclosed by start and end tags, or regions enclosed by delimiters. You can also define your own custom classes.

The overlays are updated just before any buffer modification. The built in overlay classes only update as much as is necessary to ensure that overlays covering the point are consistent. Therefore the overlays at the point are guaranteed to be correct before any buffer modification takes place there, but updating the overlays is fast and usually causes no noticeable delay.

In recent versions of Emacs (>=24.1), you can install the Auto-Overlays package from within Emacs itself, via GNU ELPA. Use M-x list-packages and take it from there. This is the preferred installation method. (Occasionally, the ELPA version might lag slightly behind the latest version available here.)

The current release of the Auto-Overlays package is version 0.10.8 (released February 2013). It's relatively stable, though bug fixes and new features are added occasionally.

If you want to live on the bleeding edge, the latest "development" version of the Auto-Overlays package is hosted in the same git repository as the Predictive Completion package.

• Git repository: http://www.dr-qubit.org/git/predictive.git
• Current version (0.10.8)

Note that the git repository URL is a git repository, not a web-site. You cannot view it in a web browser. To grab the latest development version, clone the repository using something like: #+BEGINEXAMPLE git clone http://www.d

# Emacs: Completion User Interface package

Emacs: Completion User Interface package 22 February 2013 The Completion User Interface package is a library that implements user-interfaces for in-buffer completion.

Typically, in packages providing some kind of text completion, a large amount of code deals with providing the user interface rather than finding good completions. The goal of Completion-UI is to be the swiss-army knife of in-buffer completion user-interfaces; a library which any completion package can use to provide an in-buffer completion user-interface, thereby freeing completion package writers to concentrate on the task of finding the completions in the first place.

In fact, Completion-UI is even better than a swiss-army knife, because it's also extensible: it's easyto add new completion user-interfaces and hook them into Completion-UI. The new interface will then be available to any completion package that uses the Completion-UI library, without needing to make any changes to that package.

Various standard completion user-interfaces and commands are provided "out of the box". These can be separately enabled, disabled and tweaked by the Emacs user via the usual bewildering array of customization variables. The UIs provided with the package are:

Dynamic completion
Provisionally inserts the best completion candidate in the buffer, highlighting the completed portion.
Completion hotkeys
Single-key selection of a completion.
Cycling
Cycle through completion candidates.
Tab-completion
"Traditional" expansion to longest common substring.
Echo area
Display a list of completion candidates in the echo-area.
Tooltip
Display a list of completion candidates in a tool-tip located below the point.
Pop-up tip
Display a list of completion candidates in a pseudo tool-tip located below the point, using the <code>popup.el</code> library.Displays faster and looks better than real tooltips.
Pop-up frame
Allow completion candidates to be selected from a pop-up frame displayed below the point.
Allow completion candidates to be selected from a drop-down menu located below the point.

# Emacs: Predictive Completion package

Emacs: Predictive Completion package 22 February 2013 The Emacs Predictive Completion package adds a new minor-mode to the GNU Emacs editor. When enabled, predictive mode exploits the redundancy inherent in languages in order to complete words you are typing before you've finished typing them (somewhat like the IntelliSense feature in some IDEs). It is highly customisable, and works happily alongside other Emacs major modes. See the documentation for more details.

Predictive mode only works under GNU Emacs, not under XEmacs. It may be possible to get it to work under XEmacs with a modicum of work. (At the very least, the overlay compatibility package would be required.) If you're interested in attempting this, then I'm happy to answer questions, but I have no plans to do it myself.

The current release of the Predictive Completion package is version 0.24 (released February 2013). It's still under active development, so don't forget to check back here for updates every so often. If you want to live on the bleeding edge, the latest "development" version of the Predictive package is hosted in a git repository.

• Git repository: http://www.dr-qubit.org/git/predictive.git
• Current version (0.24)

Note that the git repository URL is a git repository, not a web-site. You cannot view it in a web browser. To grab the latest development version, clone the repository using something like:

git clone http://www.dr-qubit.org/git/predictive.git


Whether you downloaded the package or cloned the git repository, you need to perform some further steps in order to install the Predictive Completion package on your system. See the Obtaining and Installing section of the manual and the INSTALL file included in the package for installation instructions.

## Documentation

Full documentation is available in a variety of formats,

# LaTeX: Quantum package

LaTeX: Quantum package 2 October 2012 The Quantum package defines a number of commands and short-hands useful when writing about quantum mechanics, and quantum information theory in particular.

There is no separate documentation; read the package source to find out what commands it provides.

• Quantum package

# LaTeX: Authord package

LaTeX: Authord package 27 July 2012 Gives a complete solution to the problem of precedence in scientific pubication, in a way that Don Knuth would surely approve of.

• Authord package
• Authord documentation