0
\newcounter{tenMarksQ}
\setcounter{tenMarksQ}{0}
\DTLforeach{Q}{\Marks=Marks}
{
    \ifnum\Marks=10
    \addtocounter{tenMarksQ}{1}
    \fi
}
\FPeval{\10}{clip(10*\thetenMarksQ)}
\section{ELABORATE ON: \hfill $\text{\thetenMarksQ\times10}=\text{\10}$}
\begin{questions}
\DTLforeach{Q}{\Marks=Marks, \Question=Question,
\Subquestion=Subquestion}
{\ifnum\Marks=10
    \question \Question
    \ifx\Subquestion\empty 
        \else
        \begin{parts}
            \part \Subquestion
        \end{parts}
    \fi
\fi
}
\end{questions}

the above code is working great for 3 marks, 5 marks but when it comes to 10 marks the number of question(here,4) multiplied with 10 gives 400, but I anticipated to get 40. enter image description here

1
  • 2
    You can't use \10. Legal control sequences have either letters only or a single nonletter.
    – egreg
    Feb 12, 2023 at 14:47

1 Answer 1

1

The problem is in using \10. A shortened version showing the same problem is as follows:

\documentclass{article}
\usepackage{fp}

\begin{document}

\FPeval{\10}{clip(10*4)}

\10

\end{document}

which produces

400

Why? Because you cannot define a macro \10. Macro names can be of two flavors: either letters only or a single nonletter.

In your case, the result of the operation is stored in \1 and the 0 is lost for reasons of how \FPeval is implemented.

Next, when you do \10, the value stored in \1 is printed and it is 40; then TeX typesets the 0.

Use something like \byten or whatever.

Well, you might use 10 as a command name, but only inside the \csname...\endcsname construct. This would work:

\expandafter\FPeval\csname 10\endcsname{clip(10*4)}

\csname 10\endcsname

but are you wanting to do that just for the sake of having a macro with that name?

By the way, you shouldn't use \thetenMarksQ, but \arabic{tenMarksQ}.

\documentclass{article}
\usepackage{fp}

\newcounter{tenMarksQ}
\setcounter{tenMarksQ}{4}

\begin{document}

\FPeval{\byten}{clip(10*\arabic{tenMarksQ})}

\byten

\end{document}

This will print 40.

1
  • Thanks a lot it worked, you guys are always better than AIs. Feb 13, 2023 at 3:14

You must log in to answer this question.

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