cgnieder / xsim

eXercise Sheets IMproved
65 stars 20 forks source link

Points question xsim package precision decimal #114

Closed fabinholima closed 1 year ago

fabinholima commented 1 year ago

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}```
muzimuzhi commented 1 year ago

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 https://github.com/latex3/latex3/issues/1226), setting goal-print=\fpeval{func_name(#1)}) will work too.

Before After
image image

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 1 year ago

Perfect thanks very much