Background: I asked a rather muddled but related question earlier. I received an excellent answer from Manuel to that question but my confusion about the problem means that I unfortunately asked the wrong question. So this is a different question, despite the similar content, which I hope may be a right question, even if not the right question to ask.
I am trying to create a new environment to typeset an enumerated list. The environment is designed to take one mandatory argument, typically a single letter. This is used as a prefix for items in the list. So if the letter is a
, the items will be labelled a1
, a2
and so on. The labels are typeset so that the letter is in small-caps. References to items should also use small-caps except that sometimes I want the letter set in upper-case e.g. at the beginning of a sentence.
I have been trying to combine cleveref
and enumitem
to achieve this result. The labels within the list are unproblematic since label=\textsc{<letter>}\arabic*
does the job nicely.
In order to facilitate different formats at the beginning of sentences, however, I've used enumitem
's ref
option alongside label
. I then would like to have \Cref
and \cref
format the label appropriately. However, I cannot figure out how to do this.
If I include the letter in the item's reference e.g. ref=<letter>\arabic*
, then I can use \creflabelformat{<type>}{<format>}
to typeset the label in, say, small-caps. But this isn't sensitive to context. \Cref
and \cref
assume that any difference in capitalisation will affect the name associated with the reference type and not the content of the specific item reference itself.
For this reason, I'm using ref=\arabic*
and attempting to set the letter prefix using \crefname
and \Crefname
. However, this means that I need to create custom formats using \crefname
and \Crefname
inside my custom environment. The problem is that these definitions are not global so they are not defined when I use \cref
or \Cref
elsewhere in the document.
How can I achieve the desired result without predefining \crefname
and \Crefname
for the letters I need in advance?
\documentclass{article}
\usepackage{xparse,enumitem,cleveref,ebgaramond}
\NewDocumentEnvironment{lettered}{ O {} m }{%
\let\labelorig\label
\def\label##1{\labelorig[lettered#2]{##1}}%
\crefname{lettered#2}{\textsc{#2}}{\textsc{#2}}%
\Crefname{lettered#2}{\MakeUppercase{#2}}{\MakeUppercase{#2}}%
\begin{enumerate}[label=\textsc{#2}\arabic*., ref=\arabic*, #1]
}{%
\end{enumerate}%
}
\begin{document}
Some examples:
\begin{lettered}{t}
\item\label{t:thing} A thing.
\item\label{t:another} Another thing.
\end{lettered}
\begin{lettered}{c}
\item\label{c:claim} A claim.
\item\label{c:different} A different claim.
\end{lettered}
The actual output is the next sentence.
\Cref{t:thing} and \cref{t:another} are the subject of claims \cref{c:claim} and \cref{c:different}.
The desired output is the next sentence.
T1 and \textsc{t}2 are the subject of claims \textsc{c}1 and \textsc{c}2.
\end{document}