0

I am currently trying to create an exam template for my institute. What I want to receive is like this:


Task 1 [8 Points]

(text text text)

Subtask 1.1 [3 Points]

(text text text)

Subask 1.2 [5 Points]

(text text text)


And the [8 Points] of Task 1 is actually the result of the subtasks 3+5 Points.

I've been trying to tackle this thing with the package 'calculator'. The problem was to update the final result of the task. Here is my short Latex script:

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{calculator}
\usepackage{lipsum}

\begin{document}
\newcommand{\res}{0}
\section{First Task [\res\, Points]}
\newcommand{\temp}{5}
\subsection{[\temp\, Points]}
\lipsum[1]
\ADD{\res}{\temp}{\res}
\renewcommand{\temp}{8}
\subsection{[\temp \,Points]}
\lipsum[1]
\ADD{\res}{\temp}{\res}
\end{document}

Thank you very much for your ideas!

1
2

There are many packages available for this kind of task (see https://www.ctan.org/topic/exam), but if you want to do it manually, you can use the xcntperchap package:

\documentclass{article}

\usepackage{xcntperchap}
\usepackage{multido}

\newcounter{points}
\RegisterCounters{section}{points}
\RegisterCounters{subsection}{points}

\usepackage{xpatch}
\newcounter{totalsubsection}
\xpretocmd{\subsection}{\stepcounter{totalsubsection}}{}{}


\begin{document}


\section{Sectiona \ObtainTrackedValueExp{section}{points}}

\subsection{subsectiona \ObtainTrackedValueExp[\value{totalsubsection}]{subsection}{points} }
\multido{}{2}{\refstepcounter{points}}

\subsection{subsectionb \ObtainTrackedValueExp[\value{totalsubsection}]{subsection}{points} }
\multido{}{3}{\refstepcounter{points}}


\section{Sectionb \ObtainTrackedValueExp{section}{points}}

\subsection{subsectionc \ObtainTrackedValueExp[\value{totalsubsection}]{subsection}{points} }
\multido{}{1}{\refstepcounter{points}}


\subsection{subsectiond \ObtainTrackedValueExp[\value{totalsubsection}]{subsection}{points} }
\multido{}{2}{\refstepcounter{points}}

\end{document}

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.