[Tex/LaTex] Roman numeral of defined counter

cross-referencingroman numerals

I defined myself a counter for Examples and want it to be displayed in uppercase Roman numerals.

\newenvironment*{Example}{\refstepcounter{exampleCounter}~\\ \noindent \textbf{Example\Roman{exampleCounter}}~\\ \begin{itshape}}{\end{itshape}}

This works perfectly fine, but when I am trying to reference an example, I am just recieving arabic numbers.
I tried

\uppercase\expandafter{\romannumeral 0\ref{blah}}

(a solution I found here but this stopped working, when I needed ö,ä,ü in my text.

At first, it was not finding the lowercase references, I got to workaround by CAPSLOCKING the labels, but roman numbering is still not possible.

Working Example



\newenvironment*{Example}{\refstepcounter{exampleCounter}~\\ \noindent \textbf{Example \Roman{exampleCounter}}~\\ \begin{itshape}}{\end{itshape}}


    This is an Example, I want to reference

Arabic example \ref{EX:BLAH}    \\
Roman example \uppercase\expandafter{\romannumeral 0\ref{EX:BLAH}}


Does anyone has an idea, how to get this roman numbers back in?

Best Answer

When you define a counter, LaTeX performs two actions. It creates the actual counter by assigning it to a register, but it also creates a counter representation macro. For some counter <cntr>, the latter is given by \the<cntr>. Internally, this is handled by the macro \@definecounter (from latex.ltx, with comments added):

\def\@definecounter#1{\expandafter\newcount\csname c@#1\endcsname% <- Defined \c@<cntr>
     \setcounter{#1}\z@% <------------------------------------------- Sets counter to 0
     \global\expandafter\let\csname cl@#1\endcsname\@empty% <-------- Clear/reset list \cl@<cntr>
     \global\expandafter\let\csname p@#1\endcsname\@empty% <--------- Reference prefix \p@<cntr>
     \gdef\csname the#1\expandafter\endcsname\expandafter% <--------- Sets \the<cntr>
          {\expandafter\@arabic\csname c@#1\endcsname}}%              to be \arabic{<cntr>}

So, for your purposes, the use of


LaTeX creates


(and some other stuff). By default, \the<cntr> is set to \arabic{<cntr>}. But you can redefine that the way you want to. Specifically, in your case, use \Roman{<cntr>} and use \the<cntr> elsewhere.

enter image description here


  {\refstepcounter{exampleCounter}% \begin{Example}
   \ignorespacesafterend}% \end{Example}


\noindent Here is some regular text.
This is an Example, I want to reference
This is a reference to Example~\ref{EX:BLAH}.

It's important to change \the<cntr> since that's exactly what is used when you make a \label - LaTeX stores in the label/reference the value of the last \the<cntr> that was stepped.