GeneralImage in Counter Declaration

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
error792
Posts: 2
Joined: Fri Aug 15, 2008 2:23 am

Image in Counter Declaration

Post by error792 »

I'm trying to do something a bit odd. I want to put a small icon in a counter, such as

Code: Select all

\renewcommand{\thecounter}{\includegraphics[height=11pt]{image.png}}
The code that calls this looks like

Code: Select all

\newcommand{\showcounter}[0]{
\refstepcounter{counter}
{\thecounter}
}
The image displays fine when I use it with \showcounter; however, when I use a \label after this and then try to refer to it with \ref later on, I get the error

Code: Select all

! Undefined control sequence.
\reserved@a ->\@nil
Any ideas on how to fix this?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Image in Counter Declaration

Post by Stefan Kottwitz »

Hi,

welcome to the board!
Try \protect right before \includegraphics.

Stefan
LaTeX.org admin
error792
Posts: 2
Joined: Fri Aug 15, 2008 2:23 am

Re: Image in Counter Declaration

Post by error792 »

Wow, thanks! That fixed the errors. However, now I have a new problem: sometimes the icon used depends on the value of the counter. There is no problem with this dependency at the \label point, but when when I \ref the \label, it uses the current value of the counter instead of the value at the point where the \label was. I'm guessing this has to do with the \protect-induced robustness - can this be remedied, while still keeping the images intact?
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Image in Counter Declaration

Post by T3. »

error792 wrote:Wow, thanks! That fixed the errors. However, now I have a new problem: sometimes the icon used depends on the value of the counter. There is no problem with this dependency at the \label point, but when when I \ref the \label, it uses the current value of the counter instead of the value at the point where the \label was. I'm guessing this has to do with the \protect-induced robustness - can this be remedied, while still keeping the images intact?
From your description I infer that you want to change the included image depending on the counter value. You probably need to use expanding definitions somewhere. Please, provide a minimal working example so it's easier for us to come up with the right solution.

Cheers,

Tomek
Post Reply