Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing a math paper, and I've got macros which take labels of theorems, corollaries, etc. as arguments. I'm wondering, is there a way to check if the label starts with a particular prefix?

That is, a command \reftitle which does "Theorem" for \reftitle{thm:122}, "Corollary" for \reftitle{cor:124}, "Statement" for \reftitle{stmt:122}.

The idea is the macro needs to check if the argument starts with cor, thm, etc.

I'm very new to macros in LaTeX, but I haven't been able to find how to do this. Anybody have ideas?

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

enter image description here

\def\tmpb{thm}\ifx\tmp\tmpb Theorem\fi
\def\tmpb{cor}\ifx\tmp\tmpb Corollary\fi

a \reftitle{thm:foo}

b \reftitle{cor:foo}

c \reftitle{foo}

However rather than relying on label prefixes it is perhaps better to record the type of unit that is being referenced automatically at the time of the \label (as hyperref does for example)

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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