Change named/anchored text ($(LNAME2 ...)) into subtle links to themselves

Resumption of #497.

Difference from the original PR:

 * `GNAME` was changed to use the `id` attribute instead of the `name` attribute, as the latter is deprecated.
 * This PR now also changes `LEGACY_LNAME2` to use the `span` tag instead of the `a` tag for the legacy name, as it is illegal to nest `a` tags.