0

I have a piece of code, which sometimes compiled correctly, other times it gives an error.

Is it possible that the package fp is unstable? Or might another package conflict with fp? How could I fix this error? I am also willing to switch to another package, if there is an alternative.

Here is the relevant code of the file (with all used packages):

\documentclass[addpoints,12pt]{exam}
\usepackage{array}
\usepackage[nomessages]{fp}%Számoláshoz


\newcommand{\gradekey}[4]{\begin{tabular}{rcrl>{\bfseries}l}
        \FPeval{\result}{round(#4*\numpoints,0)}\result&-&\numpoints&&5\\
        \FPeval{\result}{round(#3*\numpoints,0)}\result&-&\FPeval{\result}{round(#4*\numpoints-1,0)}\result&&4\\
        \FPeval{\result}{round(#2*\numpoints,0)}\result&-&\FPeval{\result}{round(#3*\numpoints-1,0)}\result&&3\\
        \FPeval{\result}{round(#1*\numpoints,0)}\result&-&\FPeval{\result}{round(#2*\numpoints-1,0)}\result&&2\\
        0&-&\FPeval{\result}{round(#1*\numpoints-1,0)}\result&&1\\
    \end{tabular}
}
\newcommand{\defaultgradekey}{%
    \begin{center}\gradekey{0.35}{0.5}{0.75}{0.9}\end{center}
}
%%



\begin{document}

\defaultgradekey
\begin{questions}
    \question[50] Question 1
    \end{questions}
\end{document}

Here is the error message from my logfile:

(Line numbers are larger, as I left all unrelevant code from the MWE)

! FP error: Illegal character \unhbox found in float number!. \FP@errmessage #1->\errmessage {FP error: #1!}

l.145 \defaultgradekey

This error message was generated by an \errmessage command, so I can't give any explicit help. Pretend that you're Hercule Poirot: Examine all clues, and deduce the truth by order and method.

! FP error: Illegal character \voidb@x found in float number!. \FP@errmessage #1->\errmessage {FP error: #1!}

l.145 \defaultgradekey

(That was another \errmessage.)

! FP error: Illegal character \hbox found in float number!. \FP@errmessage #1->\errmessage {FP error: #1!}

l.145 \defaultgradekey

(That was another \errmessage.)

! Missing control sequence inserted. \inaccessible l.145 \defaultgradekey

Please don't say \def cs{...}', say\def\cs{...}'. I've inserted an inaccessible control sequence so that your definition will be completed without mixing me up too badly. You can recover graciously from this error, if you're careful; see exercise 27.2 in The TeXbook.

The last part (from !Missing control sequence inserted) repeats many many (infinite?) times. I don't know whether it's infinite, as I killed the compilation after a reasonable amount of time.

If I comment out the lines containing \FPeval, there is no error, and the pdf file is generated. After that, there is no error even if I uncomment those lines.

But, if I delete the .aux file, the error is there again. So it seems to me that because of the \FPeval commands (inside of the \newcommand), the .aux file cannot be produced somehow.

I use pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016/Debian).

(On Windows, I could also reproduce my problem, with MikTex 2.9)

  • My problem is that sometimes it gives an error, and sometimes not. – bmv Dec 4 '17 at 8:47
  • 1
    The new (M)WE is way too long with lots of unnecessary stuff. Also, I do not get any error when compiling it with pdflatex. – Heiko Oberdiek Dec 4 '17 at 9:10
  • I can reproduce the error. – Ulrike Fischer Dec 4 '17 at 9:12
  • 2
    \numpoints is a macro and defined as \@ifundefined {exam@numpoints}{\mbox {\normalfont \bfseries??}}\exam@numpoints . This explodes in \FPeval. Give \exam@numpoints a sensible default definition (e.g. 0). – Ulrike Fischer Dec 4 '17 at 9:25
  • 1
    Btw: The class is rather buggy: tex.stackexchange.com/a/386844/2388 – Ulrike Fischer Dec 4 '17 at 9:34
4

From exam.cls:

\def\numpoints{\@ifundefined{exam@numpoints}%
  {\mbox{\normalfont\bf ??}}%
  \exam@numpoints
}% numpoints

If \exam@numpoints is not defined, then the result is \mbox{\normalfont\bf ??}. This is clearly not a number suited for package fp.

A workaround is to define \examnumpoints, an expandable version that just uses zero, if \exam@numpoints is not defined:

\makeatletter
\newcommand*{\examnumpoints}{%
  \@ifundefined{exam@numpoints}{0}{\exam@numpoints}%
}
\makeatother

Then, replace \numpoints by \examnumpoints in the calls of \FPeval.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.