1

When referencing a theorem environment, you get an output consisting of just the number of the theorem. What I need is a theorem that, when referenced, displays the letter "T" next to the number (I'm using "T" as an example but I might want to use something else). Example:

Theorem 1. In a Hausdorff space, every compact subspace is closed.

T1 is important since, among other things, it's a crucial step on the proof that every continuous bijection from a compact to a Hausdorff is a homeomorphism.

Here, T1 is the reference to Theorem 1.

How could I achieve this result?

0

2 Answers 2

4

One option is to define \p@<cnt> to hold T where <cnt> is the counter used by that theorem environment.

LaTeX2e provides a \labelformat{<cnt>}{<format>} command which can be used to set a costumed reference format for counter <cnt>. In <format>, #1 will be replaced by \the<cnt>, the normal counter representation.

See an example:

\documentclass{article}
\usepackage{amsmath}

\newtheorem{theo}{Theorem}
\labelformat{theo}{T#1}

\begin{document}
\begin{theo}\label{key}
  content
\end{theo}
\ref{key}
\end{document}

enter image description here

Update: If the theorem counter is shared with other theorem-like environment(s)

\documentclass{article}
\usepackage{aliascnt}

\newtheorem{theo}{Theorem}

\newaliascnt{lemma}{theo}
\newtheorem{lemma}[lemma]{Lemma}
\aliascntresetthe{lemma}

\labelformat{theo}{T#1}

\begin{document}
\begin{theo}\label{thm}
  content
\end{theo}

\begin{lemma}\label{lem}
  content
\end{lemma}

Theorem~\ref{thm} and Lemma~\ref{lem}
\end{document}

enter image description here

5
  • Also \labelformat{theo}{T\thetheo} (no @) Jul 2 at 13:45
  • @JohnKormylo \labelformat is better, I'll adjust my answer. Thank you! Jul 2 at 13:56
  • 1
    I discovered it by searching for \csname p@ in the tex folder (base/latexrelease.sty). Jul 2 at 18:45
  • This has the disadvantage that you cannot use \newtheorem{lemma}[theo]{Lemma}, because also references to lemmas would be in the same format as for theorems.
    – egreg
    Jul 2 at 21:05
  • @egreg True. A workaround using \newaliascnt from aliascnt package is added. Jul 2 at 22:32
2

The cleveref package allows such formatting:

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{cleveref}

\newtheorem{theo}{Theorem}
\newtheorem{lem}[theo]{Lemma}

\crefformat{theo}{#2T#1#3}
\crefformat{lem}{#2L#1#3}

\begin{document}

\begin{lem}\label{test}
A lemma
\end{lem}

\begin{theo}\label{key}
  Content
\end{theo}

Consider \cref{key}, which has content. And \cref{test}.

\end{document}

enter image description here

4
  • I took the liberty of fixing a couple of bits: the most important is that \newtheorem should appear after loading cleveref; next I showed how to make the T in the link. I also added a lemma to see that the output is as expected with a suitable \crefformat declaration.
    – egreg
    Jul 2 at 21:10
  • @egreg: Aha! That finally explains to me the docs for cleveref, section 8.2.1, saying that "The other two [#2 and #3] are used to mark the beginning and end of the part of the cross-reference that forms the hyperlink..."
    – murray
    Jul 2 at 21:11
  • @egreg: If one uses thmtools, then declarations of theorem-like environments can come before loading cleveref.
    – murray
    Jul 2 at 21:24
  • I consider that bad style nonetheless: first packages, then settings.
    – egreg
    Jul 2 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.