I defined myself a counter for Examples and want it to be displayed in uppercase Roman numerals.
\newcounter{exampleCounter}
\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
\documentclass{report}
\usepackage[ngerman,english]{babel}
\usepackage[utf8]{inputenc}
\newcounter{exampleCounter}
\newenvironment*{Example}{\refstepcounter{exampleCounter}~\\ \noindent \textbf{Example \Roman{exampleCounter}}~\\ \begin{itshape}}{\end{itshape}}
\begin{document}
\begin{Example}
\label{EX:BLAH}
This is an Example, I want to reference
\end{Example}
\noindent
Arabic example \ref{EX:BLAH} \\
Roman example \uppercase\expandafter{\romannumeral 0\ref{EX:BLAH}}
\end{document}
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
(fromlatex.ltx
, with comments added):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.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.