I understand that it's possible to have \autoref generate references like Theorem 12, or Thm. 12, etc. where the label is always the same. Is there any way to have a short and long version of autoref? Sometimes I'll be referencing a theorem in equations, and I don't want Proposition 12 or something, but an abbreviation. In the main text, I will always want the long form. Is there a pain-free way of doing this?
[Tex/LaTex] autoref: Short and long label
cross-referencinghyperref
Related Solutions
Let our LyX document be called
mypaper.lyx
. Under “Document > Settings...” we add two branches: “fulltext” and “shorttext” both with filename suffix set to “Yes”. (As mentioned, “branches” are used in LyX to manage several different variants of one document.)When only the branch “fulltext” is activated we call this the full version of the document; when only the branch “shorttext” is activated we call this the short version of the document.
The branch “fulltext” shall contain all the details, e.g., a float table (with the label “tab:1”). Such details are placed inside a “branch box”, which is created by “Insert > Branch > 1. fulltext”. Furthermore, the branch “shorttext” will only contain a cross-reference “Table [Ref: tab:1]” to that table in the long version.
So far we got the following LyX document with two branches:
How to generate the short version mypaper-shorttext.pdf
and the full version mypaper-fulltext.pdf
?
First, we activate the “fulltext” branch only and compile the full version (as PDF), to which we want to refer in the short version. The file name of the output will be
mypaper-fulltext.pdf
as you may see in the PDF viewer.Then, we add two lines to the LaTeX Preamble of
mypaper.lyx
.\usepackage{xr} \externaldocument{mypaper-fulltext}
where
mypaper-fulltext
is the filename without extension of the just created output.Finally, we activate the “shorttext” branch only and compile the short version.
The outputs are:
Warnings
- Before compiling the short version we have to make sure that the full version is updated (that is, the full version was compiled) otherwise the references may not work correctly!
- After every new start of LyX one has to compile the full version again. Only after that the short version can be created.
- Changing only a label in an activated branch does not trigger LyX such that one can recompile the document. A little change of text is necessary for triggering.
Background – how does this work in LyX?
For compiling a document, LyX exports a document to a LaTeX file in a temporary directory and runs the program “pdflatex” (or similar) to create the output. Luckily LyX uses the same temporary directory when compiling the short version and the full version. Hence, the files mypaper-shorttext.tex
, mypaper-shorttext.aux
, mypaper-fulltext.tex
, mypaper-fulltext.aux
are in the same directory. By using \externaldocument{mypaper-fulltext}
LaTeX will find the necessary files like mypaper-fulltext.aux
. After a new start of LyX, the temporary directory is empty again. Hence, the full version needs to be compile first to create the files mypaper-fulltext.tex
, mypaper-fulltext.aux
.
Extensibility: If the “shorttext” branch contains labels that are referred by the long version then we need to add \externaldocument{mypaper-shorttext}
to the LaTeX Preamble, too, and keep the short version compiled (updated), too. More complex scenarios with several branches are possible.
Best Answer
Instead of using
\autoref
, I suggest you also load thecleveref
package and then assign the abbreviated labels to\cref
(via a\crefname
directive) and the non-abbreviated labels to\Cref
(via a\Crefname
directive).