The way to define current reference string for your own LaTeX environment
That is, the way to define output style of
\ref{foo}
when \label{foo}
is within your own environment.
\newcounter{sidebar}[chapter] \renewcommand{\thesidebar}{\thechapter.\arabic{sidebar}} \newenvironment{sidebar}{% \refstepcounter{sidebar}}{% ... ...}
\refstepcounter
is essential. It is this command that defines the current reference string which is available as \thesidebar
command ('sidebar' is that in 'thesidebar'). All you have to do is renewcommand this \thesidebar
command to your favorite style like above example.