# How to find out the counter of theorems etc. in LyX

I have a document that has a lot of theorems - all introduced in LyX via the "Theorems"-Module (for those who don't know LyX, that means, that I didn't define my own theorem environment via \newtheorem..., LyX did!).

Now I want do to reference to some of my theorems.

As far as I know, this is done by giving the theorem I want to reference a label and then using \hyperref[LABEL]{TEXT}, where "TEXT" is then the colored link to the theorem (somehow \ref isn't working in LyX, if anyone is wondering why hyperref).

And now my question comes in: I need a command that somehow returns the number of the theorem (all my theorem are numbered continuously with one number through the whole text) that has the label "LABEL" - like \findnumber{LABEL} - so that I can use \hyperref[LABEL]{\findnumber{LABEL}}.

Thus, if I add another theorem the number that is the link to that theorem also changes. I don't know if this solution is the "correct" one. If it isn't, please let me know.

-
So the normal cross referencing system doesn't work? (Insert --> label/Insert --> cross reference) I did a quick test, and it worked fine here. –  Torbjørn T. Mar 28 '12 at 14:02
Also, what happens when you try \ref? as that does exactly what you're asking for in \findnumber. –  Torbjørn T. Mar 28 '12 at 18:34

## 1 Answer

To add cross references to a theorem, first add a label right after the theorem "title" (e.g. Theorem 1) with Insert --> Label or the button on the toolbar. This places, well, a label at that point which you can refer to at other places in the document. The label refers to the last "active" counter, so when you place it right at the beginning of the theorem, you know you get the right one.

A cross reference is added via Insert --> Cross reference or the button on the toolbar (right next to the insert label-button). You will get a list of all the labels in the document, and a choice of what kind of reference you would like. For example, <reference> prints just the number.

To change the type of reference just right click the reference and choose from the menu that pops up.

## \hyperref

One use of this command is to have a clickable link that consists of more that just the number. hyperref provides a starred \ref command that prints the relevant number without turning it into a clickable link. For example:

\hyperref[thm:ATheorem]{Theorem \ref*{thm:ATheorem}}


## Summary of sorts

In the screenshot below I've tried to "sum up" some of this (click it to see larger). To point out the obvious, LyX on the left, PDF output on the right.

-
If this completely missed the target and didn't help you, just let me know and I'll delete it. –  Torbjørn T. Mar 28 '12 at 19:25
It got the point straight! Although one thing I couldn't do, namely I couldn't figure out how to use the hyperref command from within LyX. If I do a right-click all that would get near that are the options "formatted reference" and "textual reference" that either display (in the first case) the entire name of the thing I labeled, like "theorem 1.2" or (in the last) nothing at all. How can I, if that is possible, pass arguments to textual referencing –  user10324 Mar 29 '12 at 17:09
You mean like the last line in my screenshot? That is an ERT ("Evil Red Text"), which you insert with Ctrl + L or Insert TeX code. In these you can type (La)TeX code directly, such as \hyperref[label]{Theorem \ref*{label}}. I don't know if it is possible to influence the built-in reference methods. –  Torbjørn T. Mar 29 '12 at 18:23
One thing I can say is that the "textual reference" uses the nameref package. What this does is print the name of whatever is referenced. E.g., if you have a section called My stuff with the label stuff, \nameref{stuff} will print My stuff. –  Torbjørn T. Mar 29 '12 at 18:26
@user10324 Sorry, I forgot to add the @user, so I'm not sure if you were notified about my comments. –  Torbjørn T. Mar 29 '12 at 19:47