[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Macro's for making an exam.

From: Oliver Corff
Subject: Re: Macro's for making an exam.
Date: Mon, 7 Jun 2021 20:04:20 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1

Hi Hans,

That sounds like an interesting challenge to learn groff, especially
after being familiar with LaTeX.

Groff is certainly more terse as a language and has some tricky points
when defining macros and nested commands (you'll need multiple escapes)
but the basics are easy to grasp and the language is quite forgiving in
the sense that faulty code won't crash anything. There are plenty of
warning messages issued by groff if things do not go as expected, and
the best proof that something went fundamentally wrong is a blank sheet
of output.

If you have defined "building blocks" for the composition of your exam
sheets you can store them in external files which you call with

.so myfile.roff

(.so mnemonic: source file). Don't forget piping everything via soelim
to the groff processor if you do that.

That helps visually declobber the file where you keep your macros.

Conditionals are called with

.if cond anything

(see groff(7) for a summary list of all requests ("Request Short

A detailed overview of conditionals can be found, e.g., on p. 46 of the
Nroff/Troff User's Manual that comes with Heirloom Documentation Tools
(I just happen to find this one first); a thorough discussion of
"Conditional Execution" can be found on pp. 278 of Unix Text Processing
by Dale Dougherty and Tim O'Reilly (the book is better known as UTP,

Your question if you have to run groff twice if you want to present
collected information on the first page: in general, yes. That is, as
long as you deal with the traditional macro packages (that is also the
reason why with the defaultĀ  commands of the -ms macros a table of
contents is placed at the end of the book, not the beginning, if no
measure is taken). However, the mom macro package and its wrapper
pdfmom, will help you place collected material near the beginning of the
document as pdfmom takes care of the necessary number of steps to
compile a complete document.

Hope that helps,


On 07/06/2021 15:37, Hans Bezemer wrote:
Dear all,

I've started working with groff recently.
Being a teacher I have three types of documents I mainly create:
1. Articles;
2. Presentations;
3. Exams.

I'm using LaTeX (article, beamer, exam) for those documents at the moment.

To get my feet wet with groff I want to create a set of macros for making a 

Goal is to make it compatible with the mm, ms and mom macrosets.
The macro's have to be able to print the number of questions, the sum of the 
points when called for.
the format of question is simple and should be:
<numberofpointS>  <Question>
whereas the <numberofpoints> are placed in the margin.

I would like to be able to toggle between printing the solution or space to 
answer the question, thus
something along these lines (with arbitrary choosen macronames):

Introduction on the question

.Q1 2
.\" 2 is the number of points
.\" start of answer block
All sorts of formatting to use to answer the question:
lines, grid, drawing.
.\"start of solution block
Block to explain the answer to the question

And when a variable `a' is set 0 then A1/A2 block is printed
and S1/2 block is ignored.
When `a' is 1 then the other way around.

I would like to get a few pointers.
What would be a good way to conditional ignore a specific block of text?
It could be done with sed of course, letting it delete anything between and 
including S1 and S2 before piping the text into groff, but I would like to do 
it within groff.

Secondly, I want to put the sum of the points and number of questions on the 
first page.
Is it needed to run groff twice to get does values?

Thanks in advance.

Kind regards,

Hans Bezemer

reply via email to

[Prev in Thread] Current Thread [Next in Thread]