# hyperref and cleveref together with enumitem

I am working on lecture paper and I am referencing theorem-like environments a lot. I have written down a simple example how my layout might look like:

\documentclass[a4paper]{article}
% references
\usepackage{hyperref}
% theorem-like environments
\usepackage{amsthm}
% languages
\usepackage[utf8]{inputenc}
\usepackage[czech]{babel}

\usepackage{enumitem}
% new theorem-like environments
\theoremstyle{definition}
\newtheorem{_def}{Definice}[section]

\theoremstyle{plain}
\newtheorem{veta}[_def]{Věta}

\crefname{_def}{D.}{D.}

\begin{document}

\section{First section}

\begin{_def}
\label{sec:def:first}
First definition of this paper.
\end{_def}

\begin{veta}
First theorem with enumerate environment
\begin{enumerate}[label=(\roman*)]
\item Item in the list\label{sec:th:li}
\item Another item in the list
\end{enumerate}
\end{veta}

As you can see in \cref{sec:def:first} and together with \cref{sec:th:li}

\end{document}


The output of the example is this:

The problem is the reference to the item in the enumerate environment. I would like the \cref to print (the red boxes are not a problem, they aren't there since I wrote this output myself, that is without any referencing):

Thanks!

Is there a way of choosing, what form of name should \cref choose? For instance I would like to choose between:

Note A. I am mixing two languages. Partially for you to understand, but also because I need it to work in my native language. Might seem like not a big deal, but I think that it was \autoref, which prints the name e.g. Definition which works neatly in English language, but not in my native - because for instance the suffix changes with the context.

Might seem like I care too much, but I think it is important. I am referencing theorem in mostly two ways:

• inside a sentence, where using whole word looks, I think, better - especially in mathematical texts, where there is no lack of symbols and abbreviations.
• above =,==>, etc. symbols in proof, equations,...

Note B. Sorry for the image quality, I followed the simplest procces: prt sc and then cut in Gimp.

I think you can achieve your stated objectives by making two modifications.

• Insert the instructions

\makeatletter
\renewcommand{\p@enumi}{\theveta~}
\makeatother


in the preamble. This instructs LaTeX to "prefix" the value of the veta counter to the enumi (first-level enum) counter when constructing a cross-reference.

Note that this approach will likely cause confusion if you use first-level enumerations in more places than just "vetas". If this happens in your document, you should probably "clone" the enumerate environment to create a new, dedicated enumerated environment that occurs only inside vetas. (For suggestions on how to clone enumerated environments see, e.g., https://tex.stackexchange.com/a/180192/5001.)

\crefname{enumi}{V.}{V.}


to the preamble as well. I think you can guess what it does.

Separately, remember that it's always a good idea to load hyperref and cleveref last. In particular, cleveref should be loaded after amsthm, but before you define any theorem-like environments (_def and veta in your case).

\documentclass[czech,a4paper]{article}
% languages
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel,lmodern}

% theorem-like environments
\usepackage{amsthm}

\usepackage{enumitem}

\makeatletter
\renewcommand{\p@enumi}{\theveta~} % prefix value of veta to enumi
\makeatother

% cross-references

% new theorem-like environments
\theoremstyle{definition}
\newtheorem{_def}{Definice}[section]
\theoremstyle{plain}
\newtheorem{veta}[_def]{Věta}

\crefname{_def}{D.}{D.}
\crefname{enumi}{V.}{V.}

\begin{document}
\section{First section}

\begin{_def}
\label{sec:def:first}
First definition of this paper.
\end{_def}

\begin{veta}
First theorem with enumerate environment
\begin{enumerate}[label=(\roman*)]
\item Item in the list\label{sec:th:li}
\item Another item in the list
\end{enumerate}
\end{veta}

As you can see in \cref{sec:def:first} and together with \cref{sec:th:li}, \dots

\end{document}


Addendum: Here's a modified solution that sets up a dedicated enumeration environment for use in veta environments, using the macros \newlist and \setlist of the enumitem package. One advantage of having such dedicated environments is that you don't have to mess with the basic LaTeX enumerate environment. Another advantage is that you can specify the form of the list labels and cross-references all in one fell swoop. Just the code is shown; the result will be identical to the screenshot shown above.

\documentclass[czech,a4paper]{article}
% languages
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel,lmodern}

% theorem-like environments
\usepackage{amsthm}

\usepackage{enumitem}
\newlist{venum}{enumerate}{1} % this creates a dedicated counter named 'venumi'
\setlist[venum,1]{label=(\roman*),
ref=\theveta~(\roman{venumi})}
% define appearance of labels and cross-references

% cross-references

% new theorem-like environments
\theoremstyle{definition}
\newtheorem{_def}{Definice}[section]
\theoremstyle{plain}
\newtheorem{veta}[_def]{Věta}

\crefname{_def}{D.}{D.}
\crefname{venumi}{V.}{V.}

\begin{document}
\section{First section}

\begin{_def}
\label{sec:def:first}
First definition of this paper.
\end{_def}

\begin{veta}
First theorem with enumerate environment
\begin{venum}  % use 'venum' instead of 'enumerate' inside a veta env.
\item Item in the list\label{sec:th:li}
\item Another item in the list
\end{venum}
\end{veta}

As you can see in \cref{sec:def:first} and together with \cref{sec:th:li}, \dots
\end{document}


A personal comment on the advisability or desirability of creating separate dedicated enumeration-like environments for theorems, definitions, corollaries, etc. I can't think of a compelling reason for why it might be advantageous to have a potential multitude of such enumeration-like environments. Does it really enhance the readability and intelligibility of your document if you write "in V 1.2 (i)" instead of -- slightly more verbosely -- "in item (i) of Veta 1.2". As with almost everything else in life, being terse needn't be a virtue.

• Well, looks like it gets the job done. But I am using first-level enumerations in different \theoremstyles, since I am writing like 60+pages long paper. I need it in definitions, theorems, exercises, etc. You mentioned "cloning" the environment. Although I am not sure, how to achieve that precisely (possibly something like \renewenvironment?) do you think, it would be the right way to do that? That is, if I understand corretly: "clone" the enumerate for each theorem-like environment, as you mention it for "vetas"? – quapka May 31 '14 at 17:26
• By the way, any ideas for the additional question?:) – quapka May 31 '14 at 19:11
• @quapka - I'll post an addendum that shows how to set up a dedicate enumeration environment using the methods of the enumitem package. On your additional question: Readers might forget quickly what "D" and "V" are supposed to mean. :-( I understand that Czech is a language in which nouns decline; the nouns (singular and plural forms) given in \crefname will in general only be correct for nominative cases. For other cases, have you considered using \labelcref instead of \cref -- and writing the appropriate noun forms yourself? Your readers may appreciate if you do this. – Mico May 31 '14 at 21:06
• It is too late today to make a reasonable edit, but I will try to explain my situation bit more later. Nevertheless thanks a lot. I haven't used \labelcref, but I'll have a look at it. – quapka Jun 1 '14 at 21:33