RF: extend the converter somewhat

Make the code replacement in the tex file a little less fragile with a
very crude parser.  Extend the things the converter can handle.