Quoting from Joris’ answer
But, of course, you are free to develop a “smart-ref” package.
I have started writing such a package some time ago (https://github.com/pireddag/formatRef) and I think that although incomplete (it does not yet attempt at parsing multiple references) it can be used.
It follows the logic of LaTeX’s prettyref, where one defines prefixes for labels which determine the format;
Quoting again from Joris
or by looking directly at the environments around the corresponding label
that is the logic of LaTeX’s cleveref, and maybe that is better.
The formatRef program has a defect which I am not able—at the moment—to go around, that is the definitions of the format codes are run by TeXmacs over and over as it parses the text; but it is written in such a way (if I correctly recall, as it is more than one year that I do not go through the program) that redefinitions have no effect.
It is possible that I will go through the program again and add the critical points Joris mentioned—but I can’t do that immediately. I have seen that it needs to be thoroughly rewritten, and it would also benefit from a re-write of the instructions, both in a short pdf and in the readme—let me be optimistic and think that it is possible to use it even in the present state.
An example of use is
as a preamble command (or in a separate style file) for setting up a reference key,
(assume it is figure 1 in the document)
to define a label and
to typeset the reference as
Also, if I were to rewrite it, I think using association lists would yield a shorter and clearer program.
I have published it under the same license as TeXmacs so anyone is allowed to use/share/modify it.