GeneralConditional Constructs in Counter Definition

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
dinya
Posts: 11
Joined: Sat Oct 24, 2009 6:24 pm

Conditional Constructs in Counter Definition

Post by dinya »

Hello all!

I need to implement different value of \thefigure as a function of \value{section}.
Something like that:

Code: Select all

\renewcommand{\thefigure}{%
  \ifthenelse{\value{section} = 0}}%
      {\theappendix.\arabic{figure}}
      {\thesection.\arabic{figure}}
  }
But this construction causes

Code: Select all

! Illegal parameter number in definition of \@currentlabel.
I use XeLaTeX, but I don't think it's reason.

Thanks in advance.

Recommended reading 2024:

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

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

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Conditional Constructs in Counter Definition

Post by cgnieder »

Hi,

the definition is flawed: the braces are not balanced. But it isn't working even when they are. The test by \ifthenelse is going wrong. I would do something like this:

Code: Select all

% arara: pdflatex
\documentclass{article}
\begin{document}
\newcommand*\theappendix{A}

\renewcommand\thefigure{%
  \ifnum\value{section}=0%
    \theappendix.\arabic{figure}%
  \else
    \thesection.\arabic{figure}%
  \fi}

\begin{figure}[ht]
 a figure
 \caption{blub}
\end{figure}

\section{Test}

\begin{figure}[ht]
 a figure
 \caption{blah}
\end{figure}

\end{document}
I don't know where \theappendix is defined? Do you have more than one appendix and are counting them?

Regards
site moderator & package author
dinya
Posts: 11
Joined: Sat Oct 24, 2009 6:24 pm

Conditional Constructs in Counter Definition

Post by dinya »

Thanks.

TeX \ifnum works for me. I have more than one appendix.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Conditional Constructs in Counter Definition

Post by cgnieder »

I was being sloppy... please change the line

Code: Select all

\ifnum\value{section}=0%
from my code into

Code: Select all

\ifnum\value{section}=0\relax
if you're using it.
site moderator & package author
Post Reply