# Check if macro argument has specific prefix

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?

-

\def\reftitle#1{\xreftitle#1:\relax}
\def\xreftitle#1:#2\relax{%
\def\tmp{#1}%
\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)

-