summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/stex/dcm/dcm.sty.ltxml
blob: c4dbe33283e5a4c6e406f0dc6c280c17ea11aae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*- 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 {}','',
beforeDigest=> sub { AssignValue(inPreamble=>0); },
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}[]', "<omdoc:metadata>#body</omdoc:metadata>");
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{}',"<dc:title>#1</dc:title>");
DefConstructor('\DCMsubject{}',"<dc:subject>#1</dc:subject>");
DefConstructor('\DCMdescription{}',"<dc:description>#1</dc:description>");
DefConstructor('\DCMpublisher{}',"<dc:publisher>#1</dc:publisher>");
DefConstructor('\DCMdate{}',"<dc:date>#1</dc:date>");
DefConstructor('\DCMtype{}',"<dc:type>#1</dc:type>");
DefConstructor('\DCMidentifier{}{}',"<dc:identifier scheme='#1'>#2</dc:identifier>");
DefConstructor('\DCMsource{}',"<dc:source>#1</dc:source>");
DefConstructor('\DCMlanguage{}',"<dc:language>#1</dc:language>");
DefConstructor('\DCMrelation{}',"<dc:relation>#1</dc:relation>");
DefConstructor('\DCMrights{}',"<dc:rights>#1</dc:rights>");
DefMacro('\DCMlicensenotice{}','\DCMrights{#1}');
DefMacro('\DCMcopyrightnotice{}{}','\DCMrights{Copyright {\copyright} #1: #2}');
DefConstructor('\cclicense{}',"<cc:license>#1</cc:license>");
DefConstructor('\attribution',"<cc:attribution/>");
DefConstructor('\noncommercial',"<cc:noncommercial/>");
DefConstructor('\sharealike',"<cc:sharealike/>");
DefConstructor('\noderivativeworks',"<cc:noderivativeworks>");
DefConstructor('\DCMabstract{}',"<dc:description>#1</dc:description>");
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;