File: ex7.pl

package info (click to toggle)
libxml-dt-perl 0.69-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 388 kB
  • sloc: perl: 1,432; xml: 438; makefile: 16
file content (134 lines) | stat: -rw-r--r-- 3,840 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl
#
# see comments in the end
#

use XML::DT ;
my $filename = shift;
my $beginLatex = '\documentclass{article}
  \usepackage[latin1]{inputenc}
  \usepackage{t1enc}
  \bibliographystyle{plain}
  \begin{document}
';
my $endLatex = '\end{document}
';

my @aut=();

%handler=(
    '-outputenc' => 'ISO-8859-1',
#    '-default'   => sub{"<$q>$c</$q>"},
     '-begin'  => sub{print"BEGIN\n"},
     '-end'  => sub{print"end\n";"$beginLatex$c$endLatex"},
     '-pcdata' => sub{ 
         if(inctxt('(SECTION|SUBSEC1)')) {$c =~ s/[\s\n]+/ /g; $c }
         $c },
     'RANDLIST' => sub{"\\begin{itemize}$c\\end{itemize}"},
     'AFFIL' => sub{""},
     'TITLE' => sub{
                  if(inctxt('SECTION')){"\\section{$c}"}
               elsif(inctxt('SUBSEC1')){"\\subsection{$c}"}
               else                    {"\\title{$c}"}
            },
     'GCAPAPER' => sub{"$c"},
     'PARA' => sub{"$c\n\n"},
     'ADDRESS' => sub{"\\thanks{$c}"},
     'PUB' => sub{"} $c"},
     'FNAME' => sub{" $c"},
     'EMAIL' => sub{"(\\texttt{$c}) "},
     'FRONT' => sub{"$c\n"},
     'REAR' => sub{"$c"},
     'BIB' => sub{"$c"},
     'BODY' => sub{"$c"},
     'AUTHOR' => sub{ push @aut, $c ; ""},
     'ABSTRACT' => sub{
       sprintf('\author{%s}\maketitle\begin{abstract}%s\end{abstract}',
               join ('\and', @aut) ,
               $c) },
     'CODE.BLOCK' => sub{"\\begin{verbatim}\n$c\\end{verbatim}\n"},
     'XREF' => sub{"\\cite{$v{REFLOC}}"},
     'SECTION' => sub{"$c"},
     'LI' => sub{"\\item $c"},
     'SUBSEC1' => sub{"$c"},
     'BIBLIOG' => sub{"\n\\begin{thebibliography}{1}\n$c\n\\end{thebibliography}\n"},
     'HIGHLIGHT' => sub{" \\emph{$c} "},
     'BIO' => sub{""},
     'SURNAME' => sub{" $c "},
     'CODE' => sub{"\\verb!$c!"},
     'BIBITEM' => sub{"\n\\bibitem{$c"},
);
print dt($filename,%handler); 

=head1 NAME

gcapaper2tex.pl - a perl script to translate XML gcapaper DTD to latex

=head1 SYNOPSIS

   gcapapape2tex.pl mypaper.xml > mupaper.tex

=head1 notes

This is an example of the use of XML::DT module

=head1 The Code

 use XML::DT ;
 my $filename = shift;
 my $beginLatex = '\documentclass{article}
   \usepackage[latin1]{inputenc}
   \usepackage{t1enc}
   \bibliographystyle{plain}
   \begin{document}
 ';
 my $endLatex = '\end{document}
 ';

 my @aut=();

 %handler=(
     '-outputenc' => 'ISO-8859-1',
 #    '-default'   => sub{"<$q>$c</$q>"},
      '-pcdata' => sub{ 
 	 if(inctxt('(SECTION|SUBSEC1)')) {$c =~ s/[\s\n]+/ /g; $c }
 	 $c },
      'RANDLIST' => sub{"\\begin{itemize}$c\\end{itemize}"},
      'AFFIL' => sub{""},
      'TITLE' => sub{
 		  if(inctxt('SECTION')){"\\section{$c}"}
 	       elsif(inctxt('SUBSEC1')){"\\subsection{$c}"}
 	       else                    {"\\title{$c}"}
 	    },
      'GCAPAPER' => sub{"$beginLatex $c $endLatex"},
      'PARA' => sub{"$c\n\n"},
      'ADDRESS' => sub{"\\thanks{$c}"},
      'PUB' => sub{"} $c"},
      'FNAME' => sub{" $c"},
      'EMAIL' => sub{"(\\texttt{$c}) "},
      'FRONT' => sub{"$c\n"},
      'REAR' => sub{"$c"},
      'BIB' => sub{"$c"},
      'BODY' => sub{"$c"},
      'AUTHOR' => sub{ push @aut, $c ; ""},
      'ABSTRACT' => sub{
        sprintf('\author{%s}\maketitle\begin{abstract}%s\end{abstract}',
 	       join ('\and', @aut) ,
 	       $c) },
      'CODE.BLOCK' => sub{"\\begin{verbatim}\n$c\\end{verbatim}\n"},
      'XREF' => sub{"\\cite{$v{REFLOC}}"},
      'SECTION' => sub{"$c"},
      'LI' => sub{"\\item $c"},
      'SUBSEC1' => sub{"$c"},
      'BIBLIOG' => sub{"\n\\begin{thebibliography}{1}\n$c\n\\end{thebibliography}\n"},
      'HIGHLIGHT' => sub{" \\emph{$c} "},
      'BIO' => sub{""},
      'SURNAME' => sub{" $c "},
      'CODE' => sub{"\\verb!$c!"},
      'BIBITEM' => sub{"\n\\bibitem{$c"},
 );
 print dt($filename,%handler); 

=head1 author

J.Joao Almeida (jj@di.uminho.pt)