# -*- CPERL -*-
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Global;
use LaTeXML::Package;
RequirePackage('sref');
sub getKeyValue_noDelim {
my ($keyval,$key)=@_;
my $valuelist = ToString($keyval->getValue($key));
$valuelist =~ s/^{(.*)}$/$1/g if $valuelist;
return $valuelist;
}
sub ExportMetadata {
my $keys = shift;
my($id, $email,$affill,$address,$url,$name)=$keys
&& map(getKeyValue_noDelim($keys,$_),qw(id email affiliation address url name));
if ($id) {
AssignValue('DCM_'.$id.'_email',$email,'global') if $email;
AssignValue('DCM_'.$id.'_affiliation',$affill,'global') if $affill;
AssignValue('DCM_'.$id.'_address',$email,'global') if $email;
AssignValue('DCM_'.$id.'_url',$url,'global') if $url;
AssignValue('DCM_'.$id.'_name',$name,'global') if $name;
} else {print STDERR "Warning: key 'id' undefined in \\DCMperson\n"};
return;}
DefKeyVal('dcm@person','id','Semiverbatim');
DefKeyVal('dcm@person','birthdate','Semiverbatim');
DefKeyVal('dcm@person','email','Semiverbatim');
DefKeyVal('dcm@person','url','Semiverbatim');
DefKeyVal('dcm@person','affiliation','Semiverbatim');
DefKeyVal('dcm@person','personaltitle','Semiverbatim');
DefKeyVal('dcm@person','academictitle','Semiverbatim');
DefKeyVal('dcm@person','department','Semiverbatim');
DefKeyVal('dcm@person','workaddress','Semiverbatim');
DefKeyVal('dcm@person','privaddress','Semiverbatim');
DefKeyVal('dcm@person','worktel','Semiverbatim');
DefKeyVal('dcm@person','privtel','Semiverbatim');
DefKeyVal('dcm@person','workfax','Semiverbatim');
DefKeyVal('dcm@person','privfax','Semiverbatim');
DefKeyVal('dcm@person','worktelfax','Semiverbatim');
DefKeyVal('dcm@person','privtelfax','Semiverbatim');
DefConstructor('\DCMperson OptionalKeyVals:dcm@person {}','',
afterDigest=>sub {
my ($stomach,$whatsit)=@_;
my $keys=$whatsit->getArg(1);
my $name=ToString($whatsit->getArg(2));
$keys->setValue('name',$name);
ExportMetadata($keys);
return;
});#$
sub FishOutMetadata {
my ($document,$keyvals)=@_;
foreach my $role(qw(creators contributors)) {
my $idlist_string=getKeyValue_noDelim($keyvals,$role);
my @ids = split(/,\s*/, $idlist_string);
foreach my $id(@ids) {
my $name = LookupValue('DCM_'.$id.'_name');
if ($name) {
my $prop_role = $role;
chop $prop_role if $prop_role;
$document->insertElement("dc:$prop_role",$name) if $role;
} else {print STDERR "Warning: no $role with 'id' $id !\n";}
}
}
return;}#$
DefEnvironment('{DCmetadata}[]', "#body");
DefConstructor('\DCMcreators{}',sub{
my ($document,$args,%properties) = @_;
my $keyval = LaTeXML::KeyVals->new('dcm@person',T_BEGIN,T_END,('creators'=>$args));
FishOutMetadata($document,$keyval);
return;});
DefConstructor('\DCMcontributors{}',sub{
my ($document,$args,%properties) = @_;
my $keyval = LaTeXML::KeyVals->new('dcm@person',T_BEGIN,T_END,('contributors'=>$args));
FishOutMetadata($document,$keyval);
return;});
DefConstructor('\DCMtitle{}',"#1");
DefConstructor('\DCMsubject{}',"#1");
DefConstructor('\DCMdescription{}',"#1");
DefConstructor('\DCMpublisher{}',"#1");
DefConstructor('\DCMdate{}',"#1");
DefConstructor('\DCMtype{}',"#1");
DefConstructor('\DCMidentifier{}{}',"#2");
DefConstructor('\DCMsource{}',"#1");
DefConstructor('\DCMlanguage{}',"#1");
DefConstructor('\DCMrelation{}',"#1");
DefConstructor('\DCMrights{}',"#1");
DefMacro('\DCMlicensenotice{}','\DCMrights{#1}');
DefMacro('\DCMcopyrightnotice{}{}','\DCMrights{Copyright {\copyright} #1: #2}');
DefConstructor('\cclicense{}',"#1");
DefConstructor('\attribution',"");
DefConstructor('\noncommercial',"");
DefConstructor('\sharealike',"");
DefConstructor('\noderivativeworks',"");
DefConstructor('\DCMabstract{}',"#1");
Tag('omdoc:omgroup', autoClose=>1);
DefConstructor('\DCMchapter OptionalKeyVals:omgroup {}',sub {
my ($document,$keyvals,$title,%properties) = @_;
my $id=$keyvals->getValue('id')||"";
$document->openElement('omdoc:chapter',('xml:id'=>$id));
$document->openElement('omdoc:metadata');
$document->insertElement('dc:title',$title);
FishOutMetadata($document,$keyvals);
return;});
DefConstructor('\DCMsection OptionalKeyVals:omgroup {}',sub{
my ($document,$keyvals,$title,%properties) = @_;
my $id=$keyvals->getValue('id')||"";
$document->openElement('omdoc:section',('xml:id'=>$id));
$document->openElement('omdoc:metadata');
$document->insertElement('dc:title',$title);
FishOutMetadata($document,$keyvals);
return;});
DefConstructor('\DCMsubsection OptionalKeyVals:omgroup {}',sub{
my ($document,$keyvals,$title,%properties) = @_;
my $id=$keyvals->getValue('id')||"";
$document->openElement('omdoc:subsection',('xml:id'=>$id));
$document->openElement('omdoc:metadata');
$document->insertElement('dc:title',$title);
FishOutMetadata($document,$keyvals);
return;});
DefConstructor('\DCMsubsubsection OptionalKeyVals:omgroup {}',sub{
my ($document,$keyvals,$title,%properties) = @_;
my $id=$keyvals->getValue('id')||"";
$document->openElement('omdoc:subsubsection',('xml:id'=>$id));
$document->openElement('omdoc:metadata');
$document->insertElement('dc:title',$title);
FishOutMetadata($document,$keyvals);
return;});
DefConstructor('\DCMparagraph OptionalKeyVals:omgroup {}',sub{
my ($document,$keyvals,$title,%properties) = @_;
my $id=$keyvals->getValue('id')||"";
$document->openElement('omdoc:paragraph',('xml:id'=>$id));
$document->openElement('omdoc:metadata');
$document->insertElement('dc:title',$title);
FishOutMetadata($document,$keyvals);
return;});
Tag('omdoc:chapter',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('omdoc:section',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('omdoc:subsection',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('omdoc:subsubsection',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('omdoc:paragraph',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('omdoc:subparagraph',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:description',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:date',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:creator',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:contributor',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:title',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:subject',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:publisher',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:type',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:identifier',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:language',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
Tag('dc:rights',afterOpen=>\&numberIt,afterClose=>\&locateIt,autoClose=>1);
RawTeX('\def\ISOtimestamp{\count1=\time\divide\count1 by 60 % hours
\count2=\count1\multiply\count2 by 60% minutes in \count1 hours
\count3=\time\advance\count3 by -\count2 % minutes
\the\year -\the\month-\the\day T\the\count1:\the\count3:00Z}');
Tag('dc:title',afterOpen=>\&numberIt,afterClose=>\&locateIt);
1;