2 # Below is a stripped down version of bib2xhtml used by doxygen.
3 # For the full version see http://www.spinellis.gr/sw/textproc/bib2xhtml/
5 # Convert from bibtex to XHTML.
7 # (C) Copyright 1995, 1996 David Hull.
8 # (David Hull / hull@cs.uiuc.edu / http://www.uiuc.edu/ph/www/dlhull)
10 # (C) Copyright 2002-2010 Diomidis Spinellis
11 # http://www.spinellis.gr
13 # This program is free software. You can redistribute it and/or modify
14 # it under the terms of the GNU General Public License. See the
15 # files README and COPYING for details.
17 # This source code contains UTF-8 characters. You might want to use
18 # an appropriate editor, if you want to view/modify the LaTeX to Unicode
19 # substitution commands.
23 use open IO => ':crlf';
24 $label_styles{'numbered'} = $LABEL_NUMBERED = 2;
25 $list_start[$LABEL_NUMBERED] = 'dl class="citelist"';
26 $list_end[$LABEL_NUMBERED] = "/dl";
30 s/\\\'(\001\d+)\{([AEIOUaeiou])\1\}/&$2acute;/gs;
31 s/\\\'([AEIOUaeiou])/&$1acute;/g;
32 s/\\\`(\001\d+)\{([AEIOUaeiou])\1\}/&$2grave;/gs;
33 s/\\\`([AEIOUaeiou])/&$1grave;/g;
34 s/\\\"(\001\d+)\{([AEIOUaeiouy])\1\}/&$2uml;/gs;
35 s/\\\"([AEIOUaeiouy])/&$1uml;/g;
36 s/\\\~(\001\d+)\{([ANOano])\1\}/&$2tilde;/gs;
37 s/\\\~([ANOano])/&$1tilde;/g;
38 s/\\\^(\001\d+)\{([AEIOUaeiou])\1\}/&$2circ;/gs;
39 s/\\\^([AEIOUaeiou])/&$1circ;/g;
40 s/\\c(\001\d+)\{([Cc])\1\}/&$2cedil;/gs;
41 s/\\u(\001\d+)\{(.)\1\}/$2/gs;
42 s/\\v(\001\d+)\{(.)\1\}/$2/gs;
44 s/\\\=(\001\d+)\{(.)\1\}/$2/gs;
46 s/\\\.(\001\d+)\{(.)\1\}/$2/gs;
48 s/\\([Oo])\b\s*/&$1slash;/g;
49 s/\\AA\b\s*/Å/g;
50 s/\\aa\b\s*/å/g;
51 s/\\AE\b\s*/Æ/g;
52 s/\\ae\b\s*/æ/g;
53 s/\\ss\b\s*/ß/g;
56 s/\\pounds\b\s*/£/g;
60 s/([^\!])\-\-([^>])/$1–$2/g;
61 s/\\([aA]lpha)\b/&$1;/g;
62 s/\\([bB]eta)\b/&$1;/g;
63 s/\\([gG]amma)\b/&$1;/g;
64 s/\\([dD]elta)\b/&$1;/g;
65 s/\\varepsilon\b/ε/g;
66 s/\\([eE]psilon)\b/&$1;/g;
67 s/\\([zZ]eta)\b/&$1;/g;
68 s/\\([eE]ta)\b/&$1;/g;
69 s/\\([tT]heta)\b/&$1;/g;
70 s/\\vartheta\b/θ/g;
71 s/\\([iI]ota)\b/&$1;/g;
72 s/\\([kK]appa)\b/&$1;/g;
73 s/\\([lL]ambda)\b/&$1;/g;
77 s/\\([oO]micron)\b/&$1;/g;
80 s/\\([rR]ho)\b/&$1;/g;
82 s/\\([sS]igma)\b/&$1;/g;
83 s/\\varsigma\b/ς/g;
84 s/\\([tT]au)\b/&$1;/g;
85 s/\\([uU]psilon)\b/&$1;/g;
86 s/\\([pP]hi)\b/&$1;/g;
88 s/\\([cC]hi)\b/&$1;/g;
89 s/\\([pP]si)\b/&$1;/g;
90 s/\\([oO]mega)\b/&$1;/g;
93 s/\\infty\b/∞/g;
94 s/\\emptyset\b/∅/g;
96 s/\\times\b/×/g;
98 s/\\partial\b/∂/g;
99 s/\\nabla\b/∇/g;
100 s/\\surd\b/√/g;
106 s/\\approx\b/≈/g;
108 s/\\equiv\b/≡/g;
109 s/\\propto\b/∝/g;
112 s/\\leftarrow\b/←/g;
113 s/\\rightarrow\b/→/g;
115 s/\\notin\b/∉/g;
116 s/\\lceil\b/⌈/g;
117 s/\\rceil\b/⌉/g;
118 s/\\lfloor\b/⌊/g;
119 s/\\rfloor\b/⌋/g;
124 $bibfile =~ s/\.bib$//;
125 push(@bibfiles,$bibfile);
130 exit(1) unless defined($htmlfile);
131 $bibdatacmd="\\bibdata{".join(',',@bibfiles)."}";
132 $label_style = $LABEL_NUMBERED;
133 $bstfile = "doxygen";
135 open(HTMLFILE,">$htmlfile$$");
136 if (open(OHTMLFILE, "$htmlfile")) {
137 $mode = (stat OHTMLFILE)[2] & 0xfff;
139 print "Error opening $htmlfile\n";
142 $beginstring = "<!-- BEGIN CITATIONS -->";
143 $endstring = "<!-- END CITATIONS -->";
146 while (<OHTMLFILE>) {
148 last loop if m/^$beginstring$/;
151 while (<OHTMLFILE>) {
153 last loop if m/^$endstring$/;
154 push(@citations, $2) if m/^([^\\]*)?(.+\})(.*)?$/;
156 push(@citations, $bibdatacmd);
158 push(@tmpfiles, "$auxfile.aux");
159 open(AUXFILE, ">$auxfile" . ".aux");
160 print AUXFILE "\\relax\n\\bibstyle{$bstfile}\n";
161 foreach $citation (@citations) {
162 print AUXFILE "$citation\n";
165 push(@tmpfiles, "$auxfile.blg");
166 push(@tmpfiles, "$auxfile.bbl");
167 `bibtex $auxfile 2>&1`;
170 print "bibtex command failed: $!\n";
172 $beginstring = "<!-- BEGIN BIBLIOGRAPHY -->";
173 $endstring = "<!-- END BIBLIOGRAPHY -->";
175 while (<OHTMLFILE>) {
176 last loop if m/^$beginstring$/;
180 while (<OHTMLFILE>) {
181 last loop if m/^$endstring$/;
183 print HTMLFILE "$beginstring\n";
184 $t = $auxfile . ".bbl";
186 open(BBLFILE, "<$t") || die "error opening $t: $!\n";
190 if (($nentry == 0) && (m/^#/)) {
191 if ((m/#\s*label-style:\s*(\S+)/) && (! defined $label_style)) {
192 $label_style = $label_styles{$1};
193 if (! defined $label_style) {
194 print STDERR "label style unknown: \n";
201 ($bcite, $blabel) = m+<dt><a name=\"([^\"]*)\">\[([^\]]*)\]</a></dt><dd>+;
203 $bibcite{$bcite} = $blabel;
206 $label_style = $LABEL_DEFAULT if (! defined $label_style);
207 $list_start = $list_start[$label_style];
208 $list_end = $list_end[$label_style];
209 print HTMLFILE "<$list_start>\n\n";
210 open(BBLFILE, "<$t") || die "error opening $t: $!\n";
214 next loop if (($nentry == 0) && (m/^#/));
220 local ($c, $l, $z) = (0, 0, ());
221 s/([\{\}])/join("","\001",($1 eq "\{" ? $z[$l++]=$c++ : $z[--$l]),$1)/ge;
224 s/(\.(<\/cite>|<\/a>|\')+)\./$1/g;
225 s:(<dt><a name=\"[^\"]*\">\[)[^\]]*(\]</a></dt><dd>):$1$nentry$2:;
226 while (m/(\\(cite(label)?)(\001\d+)\{([^\001]+)\4\})/) {
229 $doxref = defined($3);
231 if (! defined $bibcite{$bcite}) {
232 $blabel = " [" . $bcite . "]";
234 $blabel = " <a href=\"#$bcite\">[" . $bibcite{$bcite} . "]<\/a>";
236 $blabel = " [" . $bibcite{$bcite} . "]";
238 $old =~ s/(\W)/\\$1/g;
241 s/In (<a href=\"[^\"]*\">)([^\[]+) \[(\2)/In $1\[$2/;
242 s/\\htmladdnormallink(foot)?(\001\d+)\{([^\001]+)\2\}(\001\d+)\{([^\001]+)\4\}/<a href="$5">$3<\/a>/gs;
247 while (m/\\char([\'\"]?[0-9a-fA-F]+)/) {
251 } elsif ($r =~ s/^\"//) {
254 s/\\char$o\s*/&#$r;/g;
256 s/{\\etalchar\001(\d+)\{(.)}\001\1\}/$2/g;
258 s/\\url(\001\d+)\{(.*)\1\}/<a href="$2">$2<\/a>/gs;
259 s/\\href(\001\d+)\{(.*)\1\}(\001\d+)\{([^\001]*)\3\}/<a href="$2">$4<\/a>/gs;
260 s/\\href(\001\d+)\{(.*)\1\}/<a href="$2">$2<\/a>/gs;
261 s/(\001\d+)\{\\rm\s+(.*)\1\}/$2/gs;
262 s/\\textrm(\001\d+)\{(.*)\1\}/$2/gs;
263 s/(\001\d+)\{\\em\s+(.*)\1\}/<em>$2<\/em>/gs;
264 s/(\001\d+)\{\\it\s+(.*)\1\}/<i>$2<\/i>/gs;
265 s/(\001\d+)\{\\bf\s+(.*)\1\}/<b>$2<\/b>/gs;
266 s/(\001\d+)\{\\tt\s+(.*)\1\}/<tt>$2<\/tt>/gs;
267 s/\\emph(\001\d+)\{(.*)\1\}/<em>$2<\/em>/gs;
268 s/\\textit(\001\d+)\{(.*)\1\}/<i>$2<\/i>/gs;
269 s/\\textbf(\001\d+)\{(.*)\1\}/<b>$2<\/b>/gs;
270 s/\\texttt(\001\d+)\{(.*)\1\}/<tt>$2<\/tt>/gs;
271 s/\\mathrm(\001\d+)\{(.*)\1\}/$2/gs;
272 s/\\mathnormal(\001\d+)\{(.*)\1\}/$2/gs;
273 s/\\mathsf(\001\d+)\{(.*)\1\}/$2/gs;
274 s/\\mathbf(\001\d+)\{(.*)\1\}/<b>$2<\/b>/gs;
275 s/\\mathcal(\001\d+)\{(.*)\1\}/<i>$2<\/i>/gs;
276 s/\\mathit(\001\d+)\{(.*)\1\}/<i>$2<\/i>/gs;
277 s/\\mathtt(\001\d+)\{(.*)\1\}/<tt>$2<\/tt>/gs;
278 s/\\bibxhtmlname(\001\d+)\{(.*)\1\}/$2/ges;
281 $t =~ s/\^(\001\d+)\{\\circ\1\}/\&\#176;/gs;
282 $t =~ s/\^\\circ/\&\#176;/g;
283 $t =~ s/\^(\001\d+)\{(.*)\1\}/<sup>$2<\/sup>/gs;
284 $t =~ s/\^(\w)/<sup>$1<\/sup>/g;
285 $t =~ s/\_(\001\d+)\{(.*)\1\}/<sub>$2<\/sub>/gs;
286 $t =~ s/\_(\w)/<sub>$1<\/sub>/g;
289 s/(\$([^\$]+)\$)/&domath($2)/ge;
290 s/(\\\((([^\\]|\\[^\(\)])+)\\\))/&domath($2)/ge;
291 s/\\mbox(\001\d+)\{(.*)\1\}/$2/gs;
292 while (s/(<a href\=\"[^"]*?)\~/$1\005/g) { ; }
293 s/([^\\])~/$1 /g;
295 s/\\ldots\b/…/g;
296 s/\\dots\b/…/g;
299 s/\\textasciitilde\b\s*/~/g;
300 s/\\([\#\&\%\~\_\^\|])/$1/g;
302 s/\001(\d+)\{\\[A-Za-z]+\001(\d+)\{([^\001]*)\001\2\}\001\1\}/$3/g;
303 s/\\([A-Za-z]+)/ $1 /g;
304 s+In <a href=\"[^\"]*\"></a>++;
306 tr/\002\003\004/{}$/;
310 print HTMLFILE "<$list_end>\n\n$endstring\n";
311 while (<OHTMLFILE>) {
316 chmod($mode, "$htmlfile$$");
317 rename("$htmlfile$$", $htmlfile);