2

My code is:

\documentclass{scrbook}
\usepackage[utf8]{inputenc}

%Rahmenumgebung
\usepackage{tcolorbox}
\usepackage[ngerman]{babel}
\tcbuselibrary{skins,breakable,xparse}

\usepackage[%
    blank,%With this option enabled xsim will not dene the default environments exercise 
]{xsim}
\DeclareExerciseProperty{level}
\DeclareExerciseProperty{symbole}
\DeclareExerciseProperty{notenstufe}
\DeclareExerciseEnvironmentTemplate{aufgabe-template}{%
    \tcolorbox[
      parbox=false,
      enhanced jigsaw,
      breakable,%auskommentieren, wenn die Aufgaben in einer einzigen Box zusammenhängen sollen
      left=1mm,%Abstand links zum Rahmen
      right=1mm,%Abstand rechts zum Rahmen
      colframe=blue!30!white,%Rahmenfarbe
      colback=white,%Hintergrundfarbe
      %colbacktitle=white,%Hintergrundfarbe im Titel
      coltitle=white,%Schriftfarbe im Titel
      beforeafter skip = .5\baselineskip,
      title ={
        \textbf{\GetExerciseName~\GetExerciseProperty{section}.\GetExerciseProperty{counter}}%Aufgabe mit Nummer ausgeben
        \GetExercisePropertyT{level}{ Level:\PropertyValue}%evtl. Level mit Knödeln anzeigen
        \GetExercisePropertyT{symbole}{ \PropertyValue}%evtl. Symbole anzeigen
        \GetExercisePropertyT{notenstufe}{ (N:\PropertyValue)}%evtl. Symbole anzeigen
        \IfInsideSolutionF{%Wenn nicht(F=False) in der Lösung
            \GetExercisePropertyT{points}{ % notice the space
                (%
                \printgoal{\PropertyValue}
                \IfExerciseGoalSingularTF{points}
                    {\XSIMtranslate{point}}
                    {\XSIMtranslate{points}}%
                )%
            }%
        }%
        \GetExercisePropertyT{subtitle}{\\\PropertyValue}%evtl Subtitle in neuer Zeile (\\) ausgeben
      },
      pad at break*=0mm,%sollte immer letzte Option sein, weil diverse Anpassungen dadurch ausgelöst werden.
    ]
    %nachfolgender Befehl wird nicht gebraucht, wenn mit parbox=false oben gearbeitet wird.
    %\setlength{\parskip}{0.5\baselineskip plus2pt minus2pt}%
}
{\endtcolorbox}
\DeclareExerciseType{Aufgabe}{
    exercise-env = n-Aufgabe,
    solution-env = n-Solution,
    exercise-name = Aufgabe,
    exercises-name = Aufgaben,
    solution-name = Lösung von Aufgabe,
    solutions-name = Lösungen,
    exercise-template = aufgabe-template,
    solution-template = aufgabe-template,
    counter=counter-aufgabe,
    within=section,
    the-counter = \thesection.\arabic{counter-aufgabe}
}




\begin{document}
\chapter{Chapter 1}
\section{Section 1.1}
%====================================================================
\begin{n-Aufgabe}[%
    level=1,%
    %symbole=,%
    subtitle={Subtitle 1},%
    notenstufe=2,%
    points=1,%
]
Exercise Text 1
\end{n-Aufgabe}
\begin{n-Solution}
Solution Text 1
\end{n-Solution}


\begin{n-Aufgabe}[%
    level=1,%
    %symbole=,%
    subtitle={Subtitle 2},%
    notenstufe=2,%
    points=2,%
]
Exercise Text 2
\end{n-Aufgabe}
\begin{n-Solution}
Solution Text 2
\end{n-Solution}



\section{Section 1.2}
%==========================================================================
\begin{n-Aufgabe}[%
    level=3,%
    %symbole=,%
    subtitle={Subtitle 3},%
    notenstufe=4,%
    points=20,%
]
Exercise Text 3
\end{n-Aufgabe}
\begin{n-Solution}
Solution Text 3
\end{n-Solution}


\begin{n-Aufgabe}[%
    level=2,%
    %symbole=,%
    subtitle={Subtitle 4},%
    notenstufe=1,%
    %points=,%
]
Exercise Text 4
\end{n-Aufgabe}
\begin{n-Solution}
Solution Text 4
\end{n-Solution}

\end{document}

The goal is that the counter for the exercises (in German: Aufgabe) starts anew in each section:

1 Chapter 1

1.1 Section 1.1

Aufgabe 1.1.1

Aufgabe 1.1.2

1.2 Section 1.2

Aufgabe 1.2.1

Aufgabe 1.2.2

Whats the best way to do this?

The usage of

counter = counter-aufgabe,
within = section,
the-counter = \ thesection. \ arabic {counter-aufgabe}

is not really clear for me. I miss a working example to this. Most the examples I found for sectionwise numbering are based on the standard xsim environments. I had to switch off the standard environments (option: "blank" for xsim see above) because I have already defined an environment with the name "exercise" myself and the name for the environment is therefore no longer free.

1 Answer 1

2

I'm always amazed how things wander around in the internet. I have never seen the code before yet I recognize one of my own comments there (% notice the space) maybe copy-pasted from xsim.style.layouts.code.tex file (or not, it's % <<< notice the space there) or from one of my answers until it found its way to you.


My original answer was wrong and I've deleted it.


You cannot set within and the-counter as parameters in \DeclareExerciseType. Unfortunately undefined parameters are simply ignored by that command. The next version will throw an error in these cases.

Both within and the-counter only exist as options and can be set with \xsimsetup:

\documentclass{book}
\usepackage[blank]{xsim}

\DeclareExerciseType{Aufgabe}{
  exercise-env = n-Aufgabe,
  solution-env = n-Solution,
  exercise-name = Aufgabe,
  solution-name = Lösung von Aufgabe,
  exercise-template = default ,
  solution-template = default ,
  counter=counter-aufgabe
}

\xsimsetup{
  n-Aufgabe/within=section ,
  n-Aufgabe/the-counter = \thesection.\arabic{counter-aufgabe}
}

\begin{document}

\chapter{Chapter 1}
\section{Section 1.1}
\begin{n-Aufgabe}
  Exercise Text 1
\end{n-Aufgabe}
\begin{n-Aufgabe}
  Exercise Text 2
\end{n-Aufgabe}

\section{Section 1.2}
\begin{n-Aufgabe}
  Exercise Text 3
\end{n-Aufgabe}
\begin{n-Aufgabe}
  Exercise Text 4
\end{n-Aufgabe}

\end{document}

enter image description here

3
  • I've implemented both as parameters now. The next version will support the setting in \DeclareExerciseType
    – cgnieder
    Jan 24, 2021 at 10:12
  • I prefer the parameter setup, because then is everything together. I understand that this is not currently possible because of the bug. The reason for the self-set counter was that I wanted to explicitly specify the name of the counter. So I can reuse the counter in other styles of exercises and I know the name explicitly, so it is not derived from a name (here the name of the environment for the exercise: the value of exercise-env).
    – Michael.H
    Jan 24, 2021 at 12:07
  • @Michael.H actually it is not a bug, I was wrong and updated my answer accordingly. I also implemented the setting as paramater for the next version :) If structures are supposed to share the counter it is sensible to specify it.
    – cgnieder
    Jan 24, 2021 at 12:14

You must log in to answer this question.

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