2

At the moment I am writing a template used for homework. For style reasons, I would like to have a title page with a table containing all maximum points per exercise and free space, for the number of points I got.

I defined an own theorem-environment exercise that becomes the maximum amount of points possible in this exercise. e.g. an exercise with 4 points maximum

\begin{exercise}[4]
     Some text here...
\end{exercise}

I can use this number (stored as a counter) later in the document, but I would like to have the table as first page.

Is it possible to access a value before it is defined? Something like the table-of-contents would be ok. First compilation all values are stored, the table shows zeroes. Second compilation, the table shows the correct numbers. In short words, I would like to see something like in the exam class, where you are able to define points and they are shown on titlepage. But since our exercises are quite more complex, I would like to use my own package and replicate this mechanic.

1
  • 2
    Welcome to TeX.SE. You don't mean 'counters' itself that aren't defined, you mean that counter values are used before they are assigned, rather
    – user31729
    Oct 25, 2017 at 22:40

1 Answer 1

4

This stores the credit points to a .exer file, which is like a .toc, begin displayed with \listofcredits, the total number of credit points is displayed at the end of the list.

The \@starttoc macro loads the .exer file.

More information is needed however, to improve design and features.

\documentclass{article}
\usepackage{totcount}
\newcounter{exercise}

\newtotcounter{totalcredits}



\newenvironment{exercise}[1][1]{%
  \refstepcounter{exercise}%
  \addtocontents{exer}{\protect\contentsline{section}{\protect\numberline{\theexercise}}{#1}}
  \addtocounter{totalcredits}{#1}%
}{}

\AtEndDocument{%
  \addtocontents{exer}{\protect\addvspace{10pt}\par\protect\hrule}
  \addtocontents{exer}{\protect\contentsline{section}{Total}{\number\totvalue{totalcredits}}}
}


\makeatletter
\newcommand{\listofcredits}{%
  \section*{Credit points}
  \@starttoc{exer}
}
\makeatother

\begin{document}

\listofcredits

\clearpage

\begin{exercise}[4]
  Foo
\end{exercise}


\begin{exercise}[17]
  Foobar
\end{exercise}



\end{document}

enter image description here

1
  • Since exercise is apparently defined without any title, there's not much left to write to the .exer file, giving more information on the exercise in \listofcredits
    – user31729
    Oct 26, 2017 at 8:31

You must log in to answer this question.

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