6

When using the book class, pgfplots, hyperref, and section labeling according to "How to reset chapter and section counter with \part", I get the following error

! You can't use `the character -' after \the.
\value ->-
          1.60942
l.51     \end{axis}

in the following MWE

\documentclass[a4paper, 12pt]{book} 

\usepackage{pgfplots}
\pgfplotsset{compat=1.7} % to use more recent defaults

\usepackage{hyperref}

%section restarts at each part
%see https://tex.stackexchange.com/questions/54383/how-to-reset-chapter-and-section-counter-with-part/123777#123777
\makeatletter\@addtoreset{chapter}{part}\makeatother

\begin{document}

\begin{figure}
  \centering
\pgfplotsset{
    colormap/hot,
}%
\pgfmathparse{-ln(0.1)}%
\let\BEMAX=\pgfmathresult

\pgfmathparse{-ln(5)}%
\let\BEMIN=\pgfmathresult

% FIRST: define one color for every value of \be : 
\pgfplotsforeachungrouped \be in {
        0.1,
        0.5,
        0.8,
        1.0,
        2.0,
        5.0} {
    \pgfmathparse{-ln(\be)}
    \let\value=\pgfmathresult
}


\begin{tikzpicture}
    \begin{axis}[ylabel={$p(x)$},
        legend to name={fig:mm_temp_legend}
    ]
      \pgfplotsforeachungrouped \be/\zedd in {
                0.1/12.4595,
                0.5/18.3263,
                0.8/29.6888,
                1.0/43.0372,
                2.0/403.539,
                5.0/1.07923e6 } {
       \addplot+ gnuplot {x};
      }
    \end{axis}
  \end{tikzpicture}
\end{figure}

\end{document}

which was adapted from Christian Feuersänger's answer to "line legend for mesh plots". I tried to make the example as small as possible. In particular, removing any of \usepackage{hyperref}, \makeatletter\@addtoreset{chapter}{part}\makeatother, \let\value=\pgfmathresult or legend to name={fig:mm_temp_legend} makes it compile.

1 Answer 1

7

\value is an important command of LaTeX related to counters and redefining it is a bad idea. Use \VALUE or some other name.


Note that you can simplify your construct

\pgfmathparse{-ln(0.1)}\let\BEMAX=\pgfmathresult

as

\pgfmathsetmacro\BEMAX{-ln(0.1)}

and similarly for the other alike calls.

It's also a bad idea, in my opinion, to reset chapter numbers for each part, which makes cross references very clumsy

as we saw in chapter 2 of part III

Anyway, with the chngcntr package the change is easier:

\usepackage{chngcntr}
\counterwithin*{chapter}{part}

With the * the chapter counter representation is not modified; it would become \thepart.\arabic{chapter} if the *-variant is not used.

1
  • what can I say... it's a 2 in 1 answer that should get +2! thanks. I would just add that the algorithmx package is not affected by \counterwithin, so it needs to be done manually.
    – yannick
    Aug 26, 2013 at 12:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .