# Using cleveref with newenvironment

I am trying to refer to a newenvironment using cref from the cleveref package. Here is a MWE that demonstrates what I am trying to do.

\documentclass{article}
\usepackage{cleveref}

% define a newenvironment
\newcounter{projectCounter}
\setcounter{projectCounter}{0}
20pt}\refstepcounter{projectCounter}{\bf\large Project

% define another newenvironment
\newcounter{subprojectCounter}
\setcounter{subprojectCounter}{0}
20pt}\refstepcounter{subprojectCounter}{\bf\large Sub-project

% define a nested new environment
\newenvironment{projectStack}{\begin{project}\begin{subproject}}{\end{subproject}\end{project}}

% give names to the cref calls.
\crefname{project}{ project }{ projects }
\Crefname{project}{ Project }{ Projects }
\crefname{subproject}{ sub-project }{ sub-projects }
\Crefname{subproject}{ Sub-project }{ Sub-projects }

\begin{document}
This is a document that talks about sub-projects within projects.

\begin{project}{A}
Some information related to the project.

% begin a sub-project
\begin{subproject}{AA}
Some information related to the subproject.
\label{subproj:AA}
\end{subproject}

% begin another sub-project
\begin{subproject}{BB}
Some information related to the subproject.
\label{subproj:BB}
\end{subproject}

% begin a sub-project
\begin{subproject}{CC}
Some information related to the subproject.
\label{subproj:CC}
\end{subproject}

\label{proj:A}
\end{project}

Now let me try to refer to the projects, like so, \cref{proj:A}, and to
the subprojects, like so, \cref{subproj:AA,subproj:BB,subproj:CC}.
\end{document}


Here, I define the project and subproject newenvironments, and then try to refer to them using the cleveref cref function. This however does not seem to work, even though I have used the crefname and the Crefname functions.

Any help in resolving this issue would be very helpful.

-

\crefname and the like should refer to a counter, not to an environment, so you should say

\crefname{projectCounter}{project}{projects}


Here's a complete example, with some corrections to your macros.

\documentclass{article}
\usepackage{cleveref}

% define a newenvironment
\newcounter{projectCounter}
\newenvironment{project}[1]
\refstepcounter{projectCounter}%
\noindent{\bfseries\large Project \theprojectCounter: #1}\newline}

% define another newenvironment
\newcounter{subprojectCounter}[projectCounter]
\renewcommand\thesubprojectCounter{\theprojectCounter.\arabic{subprojectCounter}}
\newenvironment{subproject}[1]
\refstepcounter{subprojectCounter}%
\noindent{\bfseries\large Sub-project \thesubprojectCounter: #1}\newline}

% define a nested new environment
\newenvironment{projectStack}
{\project\subproject}
{\endsubproject\endproject}

% give names to the cref calls.
\crefname{projectCounter}{project}{projects}
\Crefname{projectCounter}{Project}{Projects}
\crefname{subprojectCounter}{sub-project}{sub-projects}
\Crefname{subprojectCounter}{Sub-project}{Sub-projects}

\begin{document}
This is a document that talks about sub-projects within projects.

\begin{project}{A}
Some information related to the project.

% begin a sub-project
\begin{subproject}{AA}
Some information related to the subproject.
\label{subproj:AA}
\end{subproject}

% begin another sub-project
\begin{subproject}{BB}
Some information related to the subproject.
\label{subproj:BB}
\end{subproject}

% begin a sub-project
\begin{subproject}{CC}
Some information related to the subproject.
\label{subproj:CC}
\end{subproject}

\label{proj:A}
\end{project}

Now let me try to refer to the projects, like so, \cref{proj:A}, and to
the subprojects, like so, \cref{subproj:AA,subproj:BB,subproj:CC}.
\end{document}

-
egreg to the rescue! Many thanks. :) –  fg nu Jan 15 '13 at 8:04