How to increment a counter
Hi all, I have a counter in an itemize environment which I need to increment by using \incrementcounter[NameOfTheCounter] However this does not work in the following example, maybe due to the use of blocks, or some other reason. I define two blocks, one for exercises, one for the solutions. Then in each exercise I have a certain number of questions, presented with an itemgroup named Questions. Analogously I have an itemgroup named Answers, which appear in the solution to an exercise. Now my problem is that some questions don’t have an answer included (for instance they are too easy…) and I need to increment the counter by saying \incrementcounter[Answers] But this does not work, for an unknown reason. (See below) Can anyone give an advice? Thanks in advance. Best regards: OK %%%% begin question-answers-block.tex \defineblock[Exoblock] \defineblock[Solblock] \defineenumeration[exo] [alternative=hanging, width=fit, text=Exercise, stopper={.}, before=, after=\blank] \defineenumeration[solution] [alternative=hanging, width=fit, text=Solution of exercise, stopper={.}, before=, after=\blank] \defineitemgroup[Questions] \defineitemgroup[Answers] \defineconversion[Questions][\numbers] \defineconversion[Answers][\numbers] \setupitemgroup[Questions][style=bold, width=1.5em, packed, alternative=hanging, stopper=, right=)] \setupitemgroup[Questions][n] \setupitemgroup[Answers][style=bold, width=1.5em, packed, alternative=hanging, stopper=, right=)] \setupitemgroup[Answers][n] \hideblocks[Exoblock] \hideblocks[Solblock] \starttext %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \beginExoblock \startexo Solve the following problems. \startQuestions \startitem This is Question 1 of exercise 1. \stopitem \startitem This is Question 2 of exercise 1. \stopitem \startitem This is Question 3 of exercise 1. An easy question, without answer\dots \stopitem \stopQuestions \stopexo \endExoblock \beginSolblock \startsolution We give only solutions to non trivial questions\dots \startAnswers \startitem This is Answer 1 of exercise 1. \stopitem \startitem This is Answer 2 of exercise 1. \stopitem \stopAnswers \stopsolution \endSolblock %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \beginExoblock \startexo Solve the following problems. \startQuestions \startitem This is Question 1 of exercise 2. \stopitem \startitem This is Question 2 of exercise 2. An easy question, without answer\dots \stopitem \startitem This is Question 3 of exercise 2. \stopitem \stopQuestions \stopexo \endExoblock \beginSolblock \startsolution We give only solutions to non trivial questions\dots \startAnswers \startitem This is Answer 1 of exercise 2. \stopitem \incrementcounter[Answers] % <———— This does not have any effect \startitem This is Answer 3 of exercise 2. \stopitem \stopAnswers \stopsolution \endSolblock %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \chapter{List of Exercises} \useblocks[Exoblock] \chapter{List of Solutions} \useblocks[Solblock] \stoptext %%%% end question-answers-block.tex
Am 05.02.2015 um 17:19 schrieb Otared Kavian
: Hi all,
I have a counter in an itemize environment which I need to increment by using \incrementcounter[NameOfTheCounter]
However this does not work in the following example, maybe due to the use of blocks, or some other reason. I define two blocks, one for exercises, one for the solutions. Then in each exercise I have a certain number of questions, presented with an itemgroup named Questions. Analogously I have an itemgroup named Answers, which appear in the solution to an exercise. Now my problem is that some questions don’t have an answer included (for instance they are too easy…) and I need to increment the counter by saying \incrementcounter[Answers]
But this does not work, for an unknown reason. (See below) Can anyone give an advice?
This doesn’t work because the name of the counter is “itemgroup:Answers” and you have to use \incrementcounter[itemgroup:Answers] to increase the counter for the items. Wolfgang
Hi Wolfgang, Thanks for your answer which solves the problem I encountered. However the block mechanism seems to have some limitations regarding how a certain block is absent (for instance when the whole solution to a problem is absent). In another thread I’ll be more precise regarding what I think is missing in the block mechanism: Hans talked about a « coupling » mechanism in mkiv, but I don’t know whether this is already done or not. In my opinion, what we need is a coupling mechanism which couples for instance each exercise with its hint, and its solution, with a built-in interaction and when for instance a hint or a solution is not there, one does not need to increment manually a counter. Best regards: OK
On 07 Feb 2015, at 12:46, Wolfgang Schuster
wrote: Am 05.02.2015 um 17:19 schrieb Otared Kavian
: Hi all,
I have a counter in an itemize environment which I need to increment by using \incrementcounter[NameOfTheCounter]
However this does not work in the following example, maybe due to the use of blocks, or some other reason. I define two blocks, one for exercises, one for the solutions. Then in each exercise I have a certain number of questions, presented with an itemgroup named Questions. Analogously I have an itemgroup named Answers, which appear in the solution to an exercise. Now my problem is that some questions don’t have an answer included (for instance they are too easy…) and I need to increment the counter by saying \incrementcounter[Answers]
But this does not work, for an unknown reason. (See below) Can anyone give an advice?
This doesn’t work because the name of the counter is “itemgroup:Answers” and you have to use \incrementcounter[itemgroup:Answers] to increase the counter for the items.
Wolfgang
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
participants (2)
-
Otared Kavian
-
Wolfgang Schuster