Points question xsim package precision decimal
fabinholima opened this issue · comments
fabinholima commented
How can I customize the score accurately as a 1.0 is not able to recognize.
Look in MWE
I like show points 1.0 and 2.0, if points is major 1.001 show in points questions, how change this
\usepackage{tikz}
\usepackage{needspace}
\usepackage[no-files]{xsim}
\newcommand*\circled[2]{\tikz[baseline=(char.base)]{
\node[shape=circle,fill,inner sep=2pt, text=white] (char) {#1};}}
%%%%%-Custom Xsim exercises %%%%%
\DeclareExerciseEnvironmentTemplate{custom}
{%\item[\GetExerciseProperty{counter}]
\Needspace*{0\baselineskip}
\noindent
\circled{\XSIMmixedcase{\GetExerciseProperty{counter}}}~~~%
\noindent
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{ % notice the space
(%
\printgoal{\PropertyValue}
\IfExerciseGoalSingularTF{points}
{%\XSIMtranslate{point}
}
%{\XSIMtranslate{points}}%
)%
}
}}
{\vspace{\baselineskip}}
\xsimsetup{
collect = false,
exercise/within = section,
exercise/template = custom,
exercise/the-counter = \arabic{exercise},
}
\begin{document}
\begin{exercise}[points=1.0]
Example 1
\end{exercise}
\begin{exercise}[points=1.001]
Example 1
\end{exercise}
\begin{exercise}[points=2.0]
Example 2
\end{exercise}
\begin{exercise}[points=1.5]
Example 3
\end{exercise}
\end{document}```
Yukai Chou commented
By applying a zero filling number format (\pgfmathprintnumber
is provided by pgfmath
, which is auto loaded by tikz
)
\xsimsetup{
goal-print={\pgfmathprintnumber[fixed zerofill,precision=1]{#1}}
}
If in the future l3fp
provides its way to round and zero fill a decimal number (see latex3/latex3#1226), setting goal-print=\fpeval{func_name(#1)})
will work too.
Before | After |
---|---|
Full example (the missing \documentclass
line is added)
\documentclass{article}
\usepackage{tikz}
\usepackage{needspace}
\usepackage[no-files]{xsim}
\xsimsetup{
goal-print={\pgfmathprintnumber[fixed zerofill,precision=1]{#1}}
}
\newcommand*\circled[2]{\tikz[baseline=(char.base)]{
\node[shape=circle,fill,inner sep=2pt, text=white] (char) {#1};}}
%%%%%-Custom Xsim exercises %%%%%
\DeclareExerciseEnvironmentTemplate{custom}
{%\item[\GetExerciseProperty{counter}]
\Needspace*{0\baselineskip}
\noindent
\circled{\XSIMmixedcase{\GetExerciseProperty{counter}}}~~~%
\noindent
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{ % notice the space
(%
\printgoal{\PropertyValue}
\IfExerciseGoalSingularTF{points}
{\XSIMtranslate{point}}
{\XSIMtranslate{points}}%
)%
}
}}
{\vspace{\baselineskip}}
\xsimsetup{
collect = false,
exercise/within = section,
exercise/template = custom,
exercise/the-counter = \arabic{exercise},
}
\begin{document}
\begin{exercise}[points=1.0]
Example 1
\end{exercise}
%\begin{exercise}[points=1.001]
% Example 1
%\end{exercise}
\begin{exercise}[points=2.0]
Example 2
\end{exercise}
\begin{exercise}[points=1.5]
Example 3
\end{exercise}
\end{document}
fabinholima commented
Perfect thanks very much