1

I am writing exercises and their detailled answers, and I'd like to reset the formula numbering between each exercise. Is it even possible? If it is, how can it be done? I can't find anything like this in the manual or on the wiki...

EDIT 2

I know I can use the bysection option, but the point is that I don't use sections in order to label exercise titles : I already use them for the lesson itself. The structure of my document is the following (I use conditionnal processing a lot to create documents with only questions, questions and answers, hints, with or without the lesson etc...)

I finally found time to post a proper MWE. I tested it in a separate directory.

\enablemode[lesson]

\starttext

%% The lesson itself
\startmode[lesson]
   \section{Bla}

   ...

\stopmode

%% The exercises
\def\exs{
  \exercisepath[/home/adrien/dev/test]  %% to be adapted
  \inputexercise[exercise_file]
  \inputexercise[exercise_file2]
}

\hairline
\enablemode[exercise]
\exs
\disablemode[exercise]

\hairline
\enablemode[answers]
\exs
\disablemode[answers]

\stoptext

and each file exercise_file has the following structure :

\exercisetitle[The title]

\startmode[exercise]
  questions
\stopmode

\startmode[answers]
  detailed answers

  \placeformula[eq:test]
  \startformula
    a = b
  \stopformula

  The eq is \eqref[eq:test]

\stopmode

The personnal commands are the following (defined in an environment file, can be pasted before the starttext for testing purposes) :

%% eq ref
\definereferenceformat[eqref][left={$(},right={)$}]

%% manage the exercise files directories 
\unprotect
\def\exercisepath[#1]{
  \gdef\@exercisepath{#1}
  \setupexternalfigures[directory={#1}]
}
\def\inputexercise[#1]{
  \ReadFile{\@exercisepath/#1}\flushsidefloats
}   
\protect

%% format the exercise title with a possible precision (eg the difficulty) 
\def\doExercisetitle[#1][#2]{
  \blank\noindenting
  {\hskip 1cm \bs #1
    \ifsecondargument \\ \tf \it [#2] \fi
  }
  \blank[small,samepage]
}

\def\exercisetitle{\dodoubleempty\doExercisetitle}

I would like each exercise file to be "independant" regarding the formula numbering. Is this possible ?

3
  • 3
    When you normal section levels for each exercise you can reset the formula counter with each new exercise, e.g. \setupformulas[way=bysection]. For a better answer you have to show us a example of your document. Commented Dec 10, 2019 at 16:17
  • 3
    You can reset the value of the formula counter with \resetcounter[formula]. Commented Dec 12, 2019 at 20:48
  • Thank you. Can you post this as an answer ? I could mark it as accepted. As a side question, how can I find the list (and names) of counters defined in ConTeXt ? Commented Dec 12, 2019 at 21:06

1 Answer 1

1

The easy way is to use the \resetcounter command to reset the value of a given counter, e.g. \resetcounter[formula] to reset the formula number.

\usemodule[visual]

\setuppapersize[A5]

\startbuffer[formula]
    \startplaceformula
        \startformula
            \fakeformula
        \stopformula
    \stopplaceformula
\stopbuffer

\starttext

\dorecurse{3}{\getbuffer[formula]}

\blank[2*line] \resetcounter[formula]

\dorecurse{3}{\getbuffer[formula]}

\stoptext

Manual reset of the formula counter

The better solution is to create a new section for the exercises and reset the formula counter with the start of each exercise. To reset the counter with each new exercise you pass the name of the section as argument to the way key in \setupformula.

\usemodule[visual]

\setuppapersize[A5]

\definehspace [exercise] [1cm]

\definehead [exercisetitle] [subject]

\define[2]\ExerciseTitleCommand
  {\vbox\bgroup
     \dontleavehmode\hspace[exercise]\structuretitle
     \doifsomething{\structureuservariable{subtitle}}
       {\par{\tf\it[\structureuservariable{subtitle}]}}%
   \egroup}

\setuphead
  [exercisetitle]
  [command=\ExerciseTitleCommand,
   style=boldslanted]

\startbuffer[formula]
    \startplaceformula
        \startformula
            \fakeformula
        \stopformula
    \stopplaceformula
\stopbuffer

% \setupformula
%   [way=bysection]

\setupformula
  [way=byexercisetitle]

\starttext

\startexercisetitle [title={First exercise}]
    \dorecurse{3}{\getbuffer[formula]}
\stopexercisetitle

\startexercisetitle [title={Second exercise}] [subtitle={Counter reset}]
    \dorecurse{3}{\getbuffer[formula]}
\stopexercisetitle

\stoptext

Automatic reset of the formula counter

You must log in to answer this question.

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