0

I have a lot of exams written using exam class. However, recently, I would like to move to xsim, which I couldn't understand how to properly do it.

So, I would like to get the following exam output using xsim with the structure of

question
|- part
   |- subpart
      |- subsubpart

while having boxed calculated marks printed on demand at the end of the line using something similar to \droppoints.

enter image description here

The following is the exam class code of the above shown layout for reference.

\documentclass[addpoints]{exam}

\usepackage[showframe]{geometry}

\usepackage{tcolorbox}

%%%%%%%%%%%%%%%%%  Formatting Questions %%%%%%%%%%%%%%%%%

\renewcommand{\questionshook}{%
    \setlength{\leftmargin}{0pt}%
    \setlength{\labelwidth}{-\labelsep}%
    \setlength{\topsep}{0\baselineskip}%
    \setlength{\itemsep}{0\baselineskip}%
}


\NewTColorBox{MarksTCBox} { O{} }{
    left skip= 0pt,
    right skip=0pt,
    left=2pt,
    right=2pt,
    capture=hbox,
    halign=center,
    valign=center,
    boxrule=0pt,
    arc=0pt,
    top=2pt,
    bottom=2pt,
    boxsep=0pt,
    nobeforeafter,
    box align = base,
    baseline=4pt,
    #1,
}

\ExplSyntaxOn

% https://tex.stackexchange.com/a/543320/2288

\keys_define:nn { Qoptions }
{
    label       .tl_set:N  = \l__Qoptions_label_tl,
    label       .initial:n = Question,
    sublabel    .tl_set:N  = \l__Qoptions_sublabel_tl,
}

% https://tex.stackexchange.com/a/543320/2288

\cs_new_protected:Npn \Qoptions_question_header:n #1
{
    \qformat
    {
        % \question appears to create a group, so the options are duly cleared
        % when the question title has been typeset.
        \keys_set:nn { Qoptions } {#1}
        \textbf
        {
            \underline
            {
                \large
                \tl_use:N \l__Qoptions_label_tl
                \c_space_tl
                (\thequestion)
                \c_space_tl
                \tl_if_blank:VF \l__Qoptions_sublabel_tl
                { [ \l__Qoptions_sublabel_tl ] \c_space_tl }
                \begin{MarksTCBox}
                    \scan_stop: [\totalpoints\ Marks]
                \end{MarksTCBox}
            }
        }
        \hfill % Otherwise, you'll have an Underfull \hbox for each question.
    }
}

\NewDocumentCommand { \myQFormat } { O{} }
{
    \Qoptions_question_header:n {#1}
}

\ExplSyntaxOff

\myQFormat% call the command to apply the default settings


%%%%%%%%%%%%%%%%%  Formatting Parts %%%%%%%%%%%%%%%%%%

\renewcommand\partlabel{(\alph{partno})}
\renewcommand{\partshook}{%
    \setlength{\labelwidth}{9mm}%
    \setlength{\leftmargin}{\labelwidth}%
    \setlength{\labelsep}{0pt}%
    \setlength{\topsep}{\baselineskip}%
    \setlength{\itemsep}{\baselineskip}%
    \def\makelabel##1{##1}% https://tex.stackexchange.com/a/278389/2288
}


%%%%%%%%%%%%%%%%%%% Formatting Subparts %%%%%%%%%%%%%%%%%%%

\renewcommand{\subpartshook}{%
    \setlength{\labelwidth}{8mm}%
    \setlength{\leftmargin}{\labelwidth}%
    \setlength{\labelsep}{0pt}%
    \setlength{\topsep}{0.5\baselineskip}%
    \setlength{\itemsep}{0.5\baselineskip}%
    \def\makelabel##1{##1}%
}

\renewcommand{\thesubpart}{(\roman{subpart})}
\renewcommand\subpartlabel{\thesubpart}

%%%%%%%%%%%%%%%% Formatting Subsubparts %%%%%%%%%%%%%%%%

\renewcommand{\subsubpartshook}{%
    \setlength{\labelwidth}{8mm}%
    \setlength{\leftmargin}{\labelwidth}%
    \setlength{\labelsep}{0pt}%
    \setlength{\topsep}{0.5\baselineskip}%
    \setlength{\itemsep}{0.5\baselineskip}%
    \def\makelabel##1{##1}%
}

\renewcommand\subsubpartlabel{(\thesubsubpart)}


%%%%%%%%%%%%%%%%%  Boxed marks at the end of the line %%%%%%%%%%%%%%%

\marksnotpoints

\pointformat{\fbox{\thepoints}\hspace{0mm}}
\pointsdroppedatright
\makeatletter
\def\droppoints{%
    \leavevmode\unskip\nobreak\hfill\penalty50\hskip2em
    \null\nobreak\hfill
    \textbf{\padded@point@block}%
    \par
}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
    \begin{questions}
        
        \question\hspace*{0pt}
        
        \begin{parts}
            \part[2] first part with 2 marks \droppoints
            \part can the total marks (4 marks) of this part children (subparts and subsubparts) be calculated and printed instead of the wrong value (2 marks)? \droppoints
            \begin{subparts}
                \subpart[2] subpart \droppoints
                \begin{subsubparts}
                    \subsubpart[2] subsubpart.... \droppoints
                \end{subsubparts}
            \end{subparts}
        \end{parts}
    \end{questions}
\end{document}

0

You must log in to answer this question.

Browse other questions tagged .