convert-to-pgml.pl -- Convert pg problem with non-pgml structure to PGML structure.
convert-to-pgml -b -s pgml file1.pg file2.pg ...
Options:
-b|--backup Create a backup of the original file before converting.
-e|--extension-prefix=s Extension prefix for the converted files. Default is 'pgml'.
-p|--output-path=s Output directory in which to save the converted problem files.
-v|--verbose Print verbose output.
-h|--help Show the help message.
This converts each pg file to PGML formatting. In particular, text blocks are converted to their PGML forms. This includes BEGIN_TEXT/END_TEXT, BEGIN_HINT/END_HINT, BEGIN_SOLUTION/END_SOLUTION.
Within each block, the following are converted: math modes to their PGML version, $BR and $PAR to line breaks or empty lines, $HR to ---, bold and italics pairs, any variables of the form $var to [$var], scripts from \{ \} to [@ @], and $var->ans_rule() to the form [_]{$var}.
A bare ans_rule() call with no answer object cannot be paired with its ANS call reliably from the source alone, so it is left as a raw Perl call inside a [@ @] block instead of being converted to a [_]{} answer blank. ANS commands are never modified or commented out; pairing them with converted or unconverted answer rules is left entirely to manual review.
Many code features that are no longer needed are removed including TEXT(beginproblem()), Context()->texStrings; and Context()->normalStrings;.
The loadMacros command is parsed, the PGML.pl is included and MathObjects.pl is removed (because it is loaded by PGML.pl) and PGcourse.pl is added to the end of the list.
Note: many of the features are converted correctly, but there may be errors after the conversion. Generally after using this script, the answer rules and answer evaluators will need to be reviewed and paired up by hand.
The option -b or --backup will create a .bak file with the original code and replace the current file with the converted code.
The option -e xyz or --extension-prefix=xyz will convert the code and write the results in a file with the given extension prefix xyz before the .pg extension. If this is not given pgml is used. So, for example, with the default value of this option, if the file problemFile.pg is converted, the file problemFile.pgml.pg will be written. If the -b flag is used, this option will be ignored.
The option -p path or --output-path=path is the location to save the converted problem files to. If this option is not provided, then the converted files will be saved in the same directory as the original file. Note that if this option is used, then the -b or --backup and -e or --extension-prefix options are ignored unless the path chosen by this option is the directory containing the original problem file. Also note that if this option is used, then files in the provided output path will be unconditionally overwritten unless the file happens to be the original input file.