# Writing Your Own Homework Problems Using PGML

(→Typical PGML Problem Example) |
|||

Line 1: | Line 1: | ||

− | |||

− | |||

− | |||

= Writing Your Own Homework Problems Using PGML = | = Writing Your Own Homework Problems Using PGML = | ||

## Revision as of 04:13, 21 November 2012

## Contents |

# Writing Your Own Homework Problems Using PGML

## Introduction

- PGML makes writing your own homework problems so much nicer than what came before. Many chores which previously were difficult are now easier, if not automated away. The best part is that there is little to learn to get started. PGML is so elegant and intuitive that you can often get started by simply viewing and tweaking existing PGML based problem files.

## So Why Isn't PGML Used Everywhere If It Is So Great?

- If PGML is so great, you may wonder why you don't see it used everwhere in the publically available WebWork problem libraries. Many of those libraries were written before PGML existed. Since many newcomers base their own custom problems on those same libraries, there is a lot (and a growing!) amount of problems that are not PGML based. However, now that you know the truth you can be one of the fortunate ones to start using PGML now. Even better is the fact that you can convert non-PGML based problems you like to PGML often quite easily.

## Typical PGML Problem Example

DOCUMENT(); loadMacros( "PGstandard.pl", "PGML.pl", "MathObjects.pl", "PGcourse.pl", "parserNumberWithUnits.pl", "contextArbitraryString.pl", "parserMultiAnswer.pl", "parserPopUp.pl", "contextInequalities.pl", "PGgraphmacros.pl", ); TEXT(beginproblem()); $showPartialCorrectAnswers = 1; ######################################################################

The contents in the above box will rarely change much in your custom WebWork homework problems. Depending on what features you use in your problems, you may or may not need all the macros I have loaded above. On the other hand, one strategy is to always include any and every macro you have ever used in the past, or will use in the future, so as to not have to bother thinking about this initial boilerplate.

Context("Numeric") ; Context()->flags->set(tolerance => 0.01);

You will want to define a "context" for your PGML homework problem. If your answers will be numbers or formulas, then just set it to Numeric and do not worry about it for now. Later you may want to learn about other contexts to allow things like strings and inequalities. The second line tells WebWork to accept student submissions as correct if they differ from the correct answer given below by 1% or less.

BEGIN_PGML Simplify [`2 + 4 \cdot 5`]. [____________]{Compute("22")} Now simplify [`2x + 4x + 5x`]. [____________]{Compute("11*x")} END_PGML

The is the central part of a PGML homework problem and what you will be working on the most as you create your own problems. What the student sees always goes in between BEGIN_PGML and END_PGML. If you want to include LaTeX, simply enlose it inside [` and `]. Your answer field is represented by the [____________]. After the answer field you specify the correct answer in braces. In this case the correct answer is an algebraic expression. If your answer is a number or formula, you can happily use the Compute function for a long time. This example include two questions. Your problems can have only 1 question or even more than 2 if you wish.

###################################################################### ENDDOCUMENT();

This last part is more boilerplate that should not change much if at all.