slightly better fixes to close #330
There is a line in which a reference is inside a maths environment
(enforced by `\ensuremath`).  As these are references, they are
actually text elements so should be in `\text` commands.
Merge pull request #332 from loopspace/upstream

Put references that are in maths mode in a `\text` command
Fix definition of pair^=