Modify Reference Macro

Hey there

I would like to modify the reference macro in my text so that instead of displaying just the number of the item it is referencing, that it displays the item-type (Theorem, Lemma, Example, …) and the number.

I.e. something like: … see Theorem 1.19. …

I found this entry, but as I am quite new to texmacs I would be glad if somebody can translate this into hardcode, so I can copy.

Any help is welcome, thank you very much in advance.

What you want are “smart references”, but these are somewhat tricky to use.
For instance, how to do “by Theorems 3 and 4”, “by Propositions 2, 3, and 5”, etc.?
Moreover, think about translating this correctly to all languages.
I introduced macros like that in LaTeX when writing my PhD,
but later found this to be more of a nuisance than a help.

But, of course, you are free to develop a “smart-ref” package.
In that case, you would indeed introduce a macro ‘smart-ref’ that
does what you want (preferrably with a variable number of arguments).
You may then retrieve typing info from the name of the macro,
or by looking directly at the environments around the corresponding label.
I would write the macro in Scheme, so as to deal with all aforementioned subtleties.

1 Like

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
<addToFormatRef|fig:|figure (#)>
as a preamble command (or in a separate style file) for setting up a reference key,
<label|fig:testFigure>
(assume it is figure 1 in the document)
to define a label and
<formatRef|fig:testFigure>
to typeset the reference as
figure (1)

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.

2 Likes

For information: I have edited the example file (which now is called formatRef_examples), I hope it is helpful.