# -*- CPERL -*-
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Package;
RequirePackage('problem');
RegisterNamespace('assig'=>"http://omdoc.org/ontology/assignments#");
RegisterDocumentNamespace('assig'=>"http://omdoc.org/ontology/assignments#");
DefEnvironment('{assignment} OptionalKeyVals:assig',
  "<omdoc:omgroup ?&KeyVal(#1,'id')(xml:id='&KeyVal(#1,'id')')() "
  .  "assig:dummy='for the namespace'>"
 .  "<omdoc:metadata>"
  .    "<dc:title>"
  .       "Assignment ?&KeyVal(#1,'num')(&KeyVal(#1,'num').)()"
  .       "?&KeyVal(#1,'title')((&KeyVal(#1,'title')))"
  .    "</dc:title>"
  .    "?&KeyVal(#1,'given')(<omdoc:meta property='assig:given'>&KeyVal(#1,'given')</omdoc:meta>)()"
  .    "?&KeyVal(#1,'due')(<omdoc:meta property='assig:due'>&KeyVal(#1,'due')</omdoc:meta>)()"
  .    "?&KeyVal(#1,'pts')(<omdoc:meta property='assig:pts'>&KeyVal(#1,'pts')</omdoc:meta>)()"
  .  "</omdoc:metadata>"
  .  "#body"
  ."</omdoc:omgroup>\n",
  afterDigest=> sub {
    my ($stomach, $kv) = @_;
    my $kvi = LookupValue('inclassig');
    my @keys = qw(id num title pts given due);
    my @vals = $kvi && map($kvi->getValue($_), @keys);
    foreach my $i(0..$#vals) {
       $kv->setValue($keys[$i],$vals[$i]) if $vals[$i];
     }});#$
DefMacro('\includeassignment [] {}', sub {
  my ($stomach, $arg1, $arg2) = @_;
  AssignValue('inclassig',$arg1) if $arg1;
  (Invocation(T_CS('\input'),$arg2)->unlist);
});
DefMacro('\inputassignment [] {}','\input{#2}');
DefEnvironment('{testheading}OptionalKeyVals:omdoc','');
DefConstructor('\testspace{}','');
DefConstructor('\testnewpage','');
DefConstructor('\testemptypage','');
1;
