3

I'm trying to convert my exercise / test sheets from LaTeX to ConTeXt and a lot of features are already included, thus it is far less work than I expected. Especially the block system in combination with the Modes is great to generate a student version and a teacher version with answers / points etc. I've set up a worksheet and try to find a good way to include points in exercises. They should be displayed in the right margin (xx-Part below) and I want to process them later on to do some things like calculating the total amount of points, getting a grade distribution table etc. Is there an possibility to add an additional parameter "points" to either of the enumeration or block "Exercise", which could be readout in other parts of the document? Here's the current state of the worksheet:

\mainlanguage[en]
\setuppapersize[A4]
\setupbodyfont[modern,ss,13pt]
\usesymbols[fontawesome]
\usesymbols[cc]

\definehspace[date][7 em]

\definecolor[schoolcolor][c=1,m=0.68,y=0,k=0.14]
\setupheader[text][
    before={\startframed[frame=off,bottomframe=on,framecolor=schoolcolor]},
    after={\stopframed},
    ]
\setupheadertexts[Title]
\setupheadertexts[Class][{\symbol[fontawesome][calendar]\hspace[date]\color[schoolcolor]{School}}]
\setupfootertexts[Page \currentpage~of \lastpage]
\setupfootertexts[teacher][{\symbol[cc][cc]\symbol[cc][by]\symbol[cc][sa]}]
\defineenumeration[Exercise][
    location=top,
    text=\llap{\getglyphdirect{ZapfDingbats*dingbats}{\number"270E}~}Exercise, 
    title=yes,
    right=:,
    titleleft=,
    titleright=,
]
\defineblock[Exercise]
\keepblocks[Exercise]
\defineenumeration[answer][
    location=top,
    text=Answer, 
]
\defineblock[answer]
% \keepblocks[answer]

\starttext
\section{Part 1}
\beginExercise
\startExercise{Questiontitle 1}\inrightmargin{ \hl[2] / xx}
Question 1...
\beginanswer
\startanswer
Answer 1...
\stopanswer
\endanswer
\stopExercise
\endExercise
\beginExercise
\startExercise{Questiontitle 2}
Question 2...
\beginanswer
\startanswer
Answer 2...
\stopanswer
\endanswer
\stopExercise
\endExercise

\section{Part 2}
\beginExercise
\startExercise{Questiontitle 3}
Question 3...
\beginanswer
\startanswer
Answer 3...
\stopanswer
\endanswer
\stopExercise
\endExercise

\subject{Answers}
\resetanswer
\useblocks[answer]

\subject{Points}
TODO: Process points
- get all points from exercises
- calculate max points
- setup linear grade distribution
- get points from grade distribution
\stoptext
2
  • 1
    Welcome to TeX S.E.! Is fontawesome usefull for your MWE? If not, please delete the related lines to make the MWE minimal indeed.
    – sztruks
    Commented Apr 2, 2022 at 18:21
  • There are some ideas in my old article: tug.org/pracjourn/2006-4/mahajan
    – Aditya
    Commented Jul 16, 2022 at 5:05

1 Answer 1

1

I give a try. You can use different names for your enumeration, and for the actual start/stop you use. Lets keep the name you used for the enumeration and define an exo start/stop. The code below allows to ads an optionnal [points] argument before the title. Here is a working example.

% macros=mkvi

\defineenumeration[Exercise][
    location=top,
    text=Exercise, 
    title=yes,
    right=:,
    titleleft=,
    titleright=,
]
\defineblock[Exercise]
\keepblocks[Exercise]
\defineenumeration[answer][
    location=top,
    text=Answer, 
]
\defineblock[answer]
% \keepblocks[answer]

\unprotect
\def\startexo{\dosingleempty\do_startexo}
\def\do_startexo[#pointsexo]#titleexo{%
    \iffirstargument{\inrightmargin{ \hl[2] / #pointsexo}}\fi
    \startExercise{#titleexo}\par%
}
\def \stopexo{\stopExercise}
\protect

\starttext

\beginExercise
    \startexo{title 1}
    Question 1...
    \startanswer
    Answer 1...
    \stopanswer
    \endanswer
    \stopexo
\endExercise    

\beginExercise
    \startexo[3]{title 2} 
    Question 2...
    \startanswer
    Answer 2...
    \stopanswer
    \endanswer
    \stopexo
\endExercise

\stoptext

Please note the % macro=mkvi which seems to be needed in the first line of your code. I don't know the details.

I mostly used this page : Are \def and \define the same in ConTeXt? and hope I didn't add clumsiness.

1
  • Welcome to TeX.SE!
    – Mensch
    Commented Jun 26, 2022 at 13:39

You must log in to answer this question.

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