The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2195 hornik 1
#! @PERL@
7357 hornik 2
#
3
# ${R_HOME}/bin/Sd2Rd for converting S documentation to Rd format
2195 hornik 4
 
12256 pd 5
# Copyright (C) 1997-2001 The R Core Development Team
2195 hornik 6
#
7
# This document is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2, or (at your option)
10
# any later version.
11
#
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
# General Public License for more details.
16
#
17
# A copy of the GNU General Public License is available via WWW at
18
# http://www.gnu.org/copyleft/gpl.html.  You can also obtain it by
5458 ripley 19
# writing to the Free Software Foundation, Inc., 59 Temple Place,
20
# Suite 330, Boston, MA  02111-1307  USA.
2195 hornik 21
 
7357 hornik 22
use Getopt::Long;
11515 hornik 23
use R::Utils;
2195 hornik 24
 
14558 ripley 25
my $revision = ' $Revision: 1.21 $ ';
7357 hornik 26
my $version;
27
my $name;
2195 hornik 28
 
7357 hornik 29
$revision =~ / ([\d\.]*) /;
30
$version = $1;
31
($name = $0) =~ s|.*/||;
2195 hornik 32
 
7357 hornik 33
sub usage {
34
  print STDERR <<END;
8245 leisch 35
Usage: R CMD Sd2Rd [options] FILE
2195 hornik 36
 
7357 hornik 37
Convert S documentation in FILE to R documentation format.
38
 
39
Options:
40
  -h, --help		print short help message and exit
31770 ripley 41
  -v, --version		print Sd2Rd version info and exit
7357 hornik 42
  -n			render examples non-executable by wrapping them
43
			into a \\dontrun{} environment
12256 pd 44
  -x			(S3 docs) interpret all single-quoted names 
45
                        as code names
7357 hornik 46
 
10633 hornik 47
Email bug reports to <r-bugs\@r-project.org>.
7357 hornik 48
END
49
  exit 0; 
50
}
51
 
11515 hornik 52
@knownoptions = ("v|version", "h|help", "n", "x");
53
GetOptions(@knownoptions) || &usage();
54
&R_version($name, $version) if $opt_v;
7357 hornik 55
&usage() if $opt_h;
56
 
12256 pd 57
@lines = <>;
58
## peek at the first line of the file, then dispatch to
59
## S3-style (nroff) or S4-style (SGML spec).
60
if(@lines[0] =~ /^<!doctype/) { doS4(); } else { doS3(); }
61
exit 0;
62
 
63
sub doS3 {
13792 pd 64
  $braceLevel = 0;
65
  $inReferences = 0;
66
  $inVerbatim = 0;
67
  $inSeeAlso = 0;
68
  $inCode = 0;
69
  $isDataSet = 0;
70
  $doprint = 1;
71
  $needArg = 1;
72
  $needVal = 0;
73
  $underlineNext = 0;
74
  $output = "";
7357 hornik 75
 
12256 pd 76
  foreach $_ (@lines) {
77
    chop;
78
    &substitute unless /^\./;
79
    my @word = split;
2195 hornik 80
 
12256 pd 81
    if (/^\s*$/) { &output("\n"); }
82
    if (/^[^.]/) { 
83
      if ($underlineNext) {
84
	$_ = "\\emph{" . $_ ."}";
85
	$underlineNext = 0;
86
      }
87
      &output($_);
88
    }
10338 hornik 89
 
12256 pd 90
    ## Added by BDR 1998-08-27
91
    if (/^\.\\\"/o) {
92
      s/^\.\\\"/%/;
93
      &output($_);
94
    }
95
    ## End
96
 
97
    if (/^\.BG D/) {
98
      $isDataSet = 1;
99
    }
100
    if (/^\.AG/) {
101
      if ($isDataSet) {
102
	if ($needArg) {
103
	  &section(1, "\\describe\{");
104
	  $needArg = 0;
105
	}
106
	$arg = $_;
107
	$arg =~ s/^\.AG\s//;
108
	&section(2, "\\item\{\\code\{$arg\}\}\{");
109
      } else {
110
	if ($needArg) {
111
	  &section(0, "\\arguments\{");
112
	  $needArg = 0;
113
	}
114
	$arg = $_;
115
	$arg =~ s/^\.AG\s//;
116
	&section(1, "\\item\{$arg\}\{");
10338 hornik 117
      }
12256 pd 118
    }
119
    if (/^\.CS/) {
120
      &section(0, "\\usage\{");
121
      $inVerbatim = 1;
122
    }
123
    if (/^\.DN/) { &section(0, "\\description\{"); }
124
    if (/^\.DT/) { &section(0, "\\details\{"); }
125
    if (/^\.EX/) {
126
      if ($opt_n) {
127
	&section(1, "\\examples\{\\dontrun\{");
128
      } else {
129
	&section(0, "\\examples\{");
10338 hornik 130
      }
12256 pd 131
      $inVerbatim = 1;
2195 hornik 132
    }
12256 pd 133
    if (/^\.FN/) {
134
      unless($fun) { $fun = $word[1]; }
135
      push(@aliases, $word[1]);
2195 hornik 136
    }
12256 pd 137
    if (/^\.(IP|PP)/) { &output("\n"); }
138
    if (/^\.KW/) { 
139
      if ($braceLevel > 0) {
140
	&section(0, "");
141
	$braceLevel = 0;
142
      }
143
      if ($word[1] =~ /sysdata/) {
144
	&output("\\keyword\{datasets\}");
145
      } else {
146
	&output("\\keyword\{$word[1]\}");
147
      }
148
    }
149
    if (/^\.RC/) {
150
      if ($needVal) {
151
	$needVal = 0;	    
152
	&section(0, "\\value\{\n$output\n");
153
	$doprint = 1;
154
      }
155
      &section(1, "\\item\{" . join(" ", @word[1..$#word]) . "\}\{");
156
    }
157
    if (/^\.RT/) {
158
      $needVal = 1;
159
      $doprint = 0;
160
      $output = "";
161
    }
162
    if (/^\.SA/) {
163
      &section(0, "\\seealso\{");
164
      $inSeeAlso = 1;
165
    }
166
    if (/^\.SE/) { &section(0, "\\section\{Side Effects\}\{"); }
167
    if (/^\.SH/) {
168
      if ($word[1] =~ /REFERENCE/) {
169
	&section(0, "\\references\{");
170
	$inReferences = 1;
14558 ripley 171
      } elsif ($word[1] =~ /AUTHOR/) {
172
	&section(0, "\\author\{");
12256 pd 173
      } elsif ($word[1] =~ /NOTE/) {
174
	&section(0, "\\note\{");
175
      } elsif ($word[1] =~ /SOURCE/) {
176
	&section(0, "\\source\{");
177
	$inReferences = 1;
178
      } elsif ($word[1] =~ /SUMMARY/) {
179
	&section(0, "\\description\{");
14558 ripley 180
      } elsif ($word[1] =~ /WARNINGS/) {
181
	&section(0, "\\section{Warnings}\{");
182
      } elsif ($word[1] =~ /WARNING/) {
13792 pd 183
	&section(0, "\\section{Warning}\{");
12256 pd 184
      } elsif (join(" ", @word[1..2]) =~ /DATA DESCRIPTION/) {
185
	&section(0, "\\usage\{\ndata($fun)");
186
	&section(0, "\\format\{");
187
      } else {
188
	# This line may be of the form .SH "A B C"
189
	($tmp = join(" ", @word[1..$#word])) =~ s/\"(.*)\"/$1/;
190
	&section(0, "\\section\{$tmp\}\{");
191
      }
192
    }
14558 ripley 193
    if (/^\.sp/) {
194
      if($word[1] == 0) {
195
	output("\\cr")
196
      } else {
197
	output("\n")
198
      }
199
    }
12256 pd 200
    if (/^\.TL/) {
201
      print("\\name\{$fun\}\n");
202
      print("\\alias\{", join("\}\n\\alias\{", @aliases), "\}\n");
203
      &section(0, "\\title\{");
204
      $inVerbatim = 1;
205
    }
206
    if (/^\.WR/) {
2195 hornik 207
      &section(0, "");
12256 pd 208
      print("% Converted by $name version $version.\n");
2195 hornik 209
    }
12256 pd 210
    if (/^\.AO/) {
211
      output("Arguments for function \\code\{$word[1]()\} can also be");
212
      output("supplied to this function.");
3609 pd 213
    }
12256 pd 214
    if (/^\.GE/) {
215
      output("This is a generic function.");
216
      output("Functions with names beginning in \\code\{$fun.\} will be");
217
      output("methods for this function.");
218
      output("Classes with methods for this function include:");
2195 hornik 219
    }
12256 pd 220
    if (/^\.GR/) {
221
      output("Graphical parameters (see \\code\{\\link\{par\}\}) may also");
222
      output("be supplied as arguments to this function.");
223
    }
224
    if (/^\.ME/) {
225
      output("This function is a method for the generic function");
226
      output("\\code\{$word[1]()\} for class \\code\{\"$word[2]\"\}.");
227
      output("It can be invoked by calling \\code\{$word[1](x)\} for an");
228
      output("object \\code\{x\} of the appropriate class, or directly by");
229
      output("calling \\code\{$word[1].$word[2](x)\} regardless of the");
230
      output("class of the object.");
231
    }
232
    if (/^\.NA/) { output("Missing values (\\code\{NA\}s) are allowed."); }
233
    if (/^\.Tl/) {
234
      output("In addition, the high-level graphics control arguments");
235
      output("described under \\code\{\\link\{par\}\} and the arguments to");
236
      output("\\code\{\\link\{title\}\} may be supplied to this function.");
237
    }
238
    if (/^\.ul/) { $underlineNext = 1; }
239
    ## End
2195 hornik 240
  }
241
}
242
 
243
sub substitute {
244
  if (!$inVerbatim) {
245
    s/\{/\\\{/g;
246
    s/\}/\\\}/g;
10338 hornik 247
#    s/&/\\&/g; removed BDR 2000-02-10
248
    ## Added by BDR 1998-06-20
2195 hornik 249
    s/\\\(aa/'/g;		# extra ' for highlight matching
250
    s/\\\(em/--/g;		# em dash
251
    s/\\\(tm/ (TM) /g;		# Trademark
252
    s/\\\(mu/ x /g;		# multiply sign
253
    s/\\\(\*a/\alpha/g;		# greek
254
    s/\\\(\*b/\beta/g;
255
    s/\\\(\*e/\epsilon/g;
256
    s/\\\(\*l/\lambda/g;
257
    s/\\\(\*m/\mu/g;
258
    s/\\\(\*p/\pi/g;
259
    s/\\\(\*s/\sigma/g;
260
    ## End
261
  }
10217 pd 262
  s/\.\.\./\\dots/g;
2195 hornik 263
  s/\\fB/\\bold\{/g;
264
  s/\\fR/\}/g;
10338 hornik 265
  ## Added by BDR 1998-06-20
2195 hornik 266
  s/\\fI/\\emph\{/g;
267
  s/\\fP/\}/g;
268
  ## End
269
  s/\%/\\%/g;
270
  s/\\\.(.*)$/# $1)/g;
10439 hornik 271
  if($inCode && s/\'/\}/) {
272
    $inCode = 0;
273
  }
2195 hornik 274
  if ($inSeeAlso) {
275
    if ($opt_x) {
276
      s/\`?([\.\w]*\w+)\'?/\\code{\\link{$1}}/g;
277
    } else {
278
      s/\`([^\']*)\'/\\code{\\link{$1}}/g;
279
    }
280
  } elsif (!$inVerbatim) {
10439 hornik 281
    if(s/\`([^\']*)$/\\code\{$1/) {
282
      $inCode = 1;
283
    }
10338 hornik 284
    s/\`([^\']*)\'$/\\code{$1}/g;
285
    s/\`([^\']*)\'([^\'])/\\code{$1}$2/g;  
2195 hornik 286
  }
10338 hornik 287
  if ($inReferences) {
288
    s/([0-9])-([0-9])/$1--$2/g;
289
  }
2195 hornik 290
}
291
 
292
sub section {
7357 hornik 293
  my($level, $text) = @_;
2195 hornik 294
  $n = $braceLevel - $level;
7636 hornik 295
  print "\}" x $n, "\n" if ($n > 0);
2195 hornik 296
  if ($needVal) {
7636 hornik 297
    print("\\value\{\n$output\n\}\n");
2195 hornik 298
    $needVal = 0;
299
  }
7636 hornik 300
  print("$text\n") if $text;    
2195 hornik 301
  $braceLevel = $level + 1;
10338 hornik 302
  $inReferences = 0;
2195 hornik 303
  $inVerbatim = 0;
304
  $inSeeAlso = 0;
305
  $doprint = 1;    
306
}
307
 
308
sub paragraph {
7357 hornik 309
  my($name) = @_;
2195 hornik 310
  &output("\n\\bold\{$name.\} ");
311
}
312
 
313
sub output {
7357 hornik 314
  my($text) = @_;
2195 hornik 315
  if ($doprint) {
7636 hornik 316
    print("$text\n");
2195 hornik 317
  } elsif ($output) {
318
    $output .= "\n$text";
319
  } else {
320
    $output = $text;
321
  }
322
}
323
 
12256 pd 324
 
325
## ---------------------------- S4 section -------------------------
326
 
327
my $skipping = 0;
328
my $nextskipping = 0;
329
my $text = "";
330
my $fun;
331
my $InArgs = 0;
332
 
34091 hornik 333
my $nalias = 0;
334
my $nexamples = 0;
335
 
12256 pd 336
sub doS4 {
337
  foreach $_ (@lines) {
338
    # skip header
339
    if (/^<!doctype/) {
340
      $skipping = 1;
341
      $nextskipping = 1 unless />\s*$/s;
342
    }
343
    if($skipping && /^>/) { $nextskipping = 0;}
344
    # skip comments
345
    $skipping = $nextskipping = 1 if (/^\s*<\!-- /);
346
    if($skipping && /-->\s*$/) { $nextskipping = 0;}
347
    if(!$skipping) {
348
      $text = $text . $_;
349
    }
350
    $skipping = $nextskipping;
351
  }
352
 
353
  ($type, $text, $rest) = get_group($text); # s-function-doc or whatever
354
  if($type ne "function-doc" && $type ne "method-doc") {
34091 hornik 355
    die "Document class 's-$type' is not supported";
12256 pd 356
  }
357
 
358
  chomp $text;
359
 
360
  while(length($text) > 0) {
361
    ($type, $body, $text) = get_group($text);
362
    process_group($type, $body);
363
  }
364
  print "% Converted by $name version $version.\n";
365
  ## End
366
}
367
 
368
sub get_group
369
{
370
    my $text = $_[0];
371
    my $body;
372
    my $rest;
373
 
374
    die "not at beginning of a group in |$text|" unless 
375
	$text =~ /^\s*<s-(.+?)>/s;
376
    my $type = $1;
377
    my $tt = $type;
378
    $tt =~ s/([a-zA-Z-]+).*/$1/;
379
    if($text =~ /^\s*<s-\Q$type\E>(.*?)<\/s-$tt>(.*)/s) {
380
	$body = $1;
381
	$rest = $2;
382
    } else { 
34091 hornik 383
	warn "no match for 's-$tt'";
12256 pd 384
	$text =~ /^\s*<s-\Q$type\E>\s*(.*)/s;
385
	$body = $1;
386
	$rest = "";
387
    }
388
    ($type, $body, $rest);
389
}
390
 
391
sub process_group {
392
    my $type = $_[0];
393
    my $text = $_[1];
394
 
395
    if($InArgs && ($type =~ /^args/) != 1) {
396
	print "}\n";
397
	$InArgs = 0;
398
    }
399
 
400
    $text =~ s/^\n*//;
401
    $text =~ s/\n*$//;
402
 
403
    if ($type eq "topics") {
404
	process_sub_groups($text, "topic");
405
 
406
    } elsif ($type eq "title") {
407
	print "\\title{\n  $text\n}\n";
408
 
409
    } elsif ($type eq "description") {
410
	print "\\description{\n", sub4($text), "\n}\n";	
411
 
412
    } elsif ($type eq "usage") {
413
	## new-style usage is not catered for here: no examples seen
414
	## it will be passed through verbatim.
415
	if ($text =~ /^\s*<s-old-style-usage>\s*(.*?)\s*<\/s-old-style-usage>/s) {
416
	    $text = $1;
417
	}
418
	print "\\usage{\n$text\n}\n";	
419
 
420
    } elsif ($type eq "args" || $type eq "args-optional" 
421
	     || $type eq "args-required" ) {
422
	if(!$InArgs) {
423
	    print "\\arguments{\n";
424
	    $InArgs = 1;
425
	}
426
	## some files seem to have text before args
427
	my $pre = $text =~ /^\s*<s-arg/;
428
	if($pre != 1) {
429
	    my $pre;
430
	    if($text =~ s/^\s*(.*?)(<s-arg)/$2/s) {
431
		$pre = $1;
432
	    } else {
433
		## There are no <s-arg> groups!
434
		$pre = $text;
435
		$text = "";
436
	    }
437
	    print sub4($pre), "\n";
438
	}
439
	process_sub_groups($text, "arg");
440
 
441
    } elsif ($type eq "value") {
442
	print "\\value{\n";
443
	my $t;
444
	my @groups = split /<s-return-component /, $text;
445
	foreach $t (@groups) {
446
	    if ($t =~ /name=\"(.*?)\">\s*(.*)<\/s-return-component>/s) {
447
		my $name=$1;
448
		$t = $2;
12778 pd 449
		print "\\item{$1}{\n", sub4($t), "}\n";
12256 pd 450
	    } else {
451
		print sub4($t), "\n";
452
	    }
453
	}
454
	print "}\n";
455
 
456
    } elsif ($type eq "details") {
457
	print "\\details{\n", sub4($text), "\n}\n";	
458
 
459
    } elsif ($type eq "see") {
460
 	print "\\seealso{\n", makelinks($text), "\n}\n";	
461
 
462
    } elsif ($type eq "examples") {
463
	print "\\examples{\n";
464
	print "\\dontrun{\n" if $opt_n;
465
	process_sub_groups($text, "example");
466
	print "}\n" if $opt_n;
467
	print "}\n";
468
 
469
    } elsif ($type eq "note" || $type eq "notes") {
470
	print "\\note{\n", sub4($text), "\n}\n";	
471
 
472
    } elsif ($type eq "bugs") {
473
 	print "\\section{Bugs}{\n", sub4($text), "\n}\n";	
474
 
475
    } elsif ($type eq "references") {
476
	print "\\references{\n", inref(sub4($text)), "\n}\n";	
477
 
478
    } elsif ($type =~ /^section\s+name\s*=\s*(.*)/) {
479
	my $name = $1;
480
	$name =~ s/\s*\"(.*?)\"/$1/o;
481
	$name =~ s/^\s*//o;
482
	if ($name =~ /^reference$/io) {
483
	    print "\\references{\n", inref(sub4($text)), "\n}\n";	
484
	} elsif ($name =~ /^source$/io) {
485
	    print "\\source{\n", inref(sub4($text)), "\n}\n";	
486
	} elsif ($name =~ /^note$/io) {
487
	    print "\\note{\n", sub4($text), "\n}\n";	
488
	} elsif ($name =~ /^summary$/io) {
489
	    print "\\description{\n", sub4($text), "\n}\n";	
490
	} elsif ($name =~ /^data description$/io) {
491
	    print "\\usage{\ndata($fun)\n}\n";
492
	    print "\\format{\n", sub4($text), "\n}\n";	
493
	} else {
494
	    $name = lc($name);
495
	    $name =~ s/^([a-z])/\U$1/;
496
	    print "\\section{$name}{\n", sub4($text), "\n}\n";	
497
	}
498
 
499
    } elsif ($type eq "docclass") {
500
	print "% docclass is $text\n";
501
 
502
    } elsif ($type eq "warnings") {
503
	process_sub_groups($text, "warning");
504
 
505
    } elsif ($type eq "warning") {
506
	print "\\section{Warning}{\n", sub4($text), "\n}\n";	
507
 
508
    } elsif ($type eq "background") {
509
	print "\\section{Background}{\n", sub4($text), "\n}\n";	
510
 
511
    } elsif ($type eq "side-effects") {
512
	print "\\section{Side Effects}{\n", sub4($text), "\n}\n";	
513
 
514
    } elsif ($type eq "author") {
515
	print "\\author{\n", sub4($text), "\n}\n";	
516
 
517
    } elsif ($type eq "keywords") {
518
	process_sub_groups($text, "keyword");
519
 
520
    } else {
34091 hornik 521
	warn "unknown SGML entity '$type'";
12256 pd 522
	print "%type:\n%$text\n";
523
    }
524
}
525
 
34091 hornik 526
sub process_sub_groups {
527
 
12256 pd 528
    my $text = $_[0];
529
    my $topic = $_[1];
530
 
531
    while(length($text) > 0) {
532
	($type, $body, $text) = get_group($text);
533
	die "invalid subgroup" unless $type =~ /^$topic/;
534
	process_sub_group($type, $body);
535
    }
536
}
537
 
34091 hornik 538
sub process_sub_group {
539
 
12256 pd 540
    my $topic = $_[0];
541
    my $text = $_[1];
542
 
543
    $text =~ s/^\n*//;
544
    $text =~ s/\n*$//;
545
    if ($type eq "topic") {
546
	 $text =~ s/^\s*//; $text =~ s/\s*$//;
547
	if(!$nalias) {
548
	    print "\\name{$text}\n";
549
	    $nalias = 1;
550
	    $fun = $text;
551
	}
552
	print "\\alias{$text}\n";
553
    } elsif ($type eq "warning") {
554
	print "\\section{Warning}{\n", sub4($text), "\n}\n";	
555
    } elsif ($type eq "keyword") {
556
	print "\\keyword{$text}\n";
557
    } elsif ($type =~ /^example/) {
558
	if ($nexample++ > 0) { print "\n"; }
559
	print verbsub($text), "\n";
560
    } elsif ($type =~ /^arg/) {
561
	$type =~ /^arg\s+name\s*=\s*(.*)/;
562
	my $name = $1;
563
	$name =~ s/\s*\"(.*?)\"/$1/o;
564
	$name =~ s/\s*(\w*)\s*/$1/o;
565
	$name =~ s/\.\.\./\\dots/;
566
	print "\\item{$name}{\n", sub4($text), "\n}\n";	
567
    } else {
34091 hornik 568
	warn "unknown SGML entity '$type'";
12256 pd 569
	print "%type:\n%$text\n";
570
    }
571
}
572
 
573
sub inref {
574
    my $text = $_[0];
575
    $text =~ s/([0-9])-([0-9])/$1--$2/go;
576
    $text;
577
}
578
 
579
sub verbsub {
580
    my $text = $_[0];
581
    $text =~ s/&gt;/>/go;
582
    $text =~ s/&lt;/</go;
583
    $text =~ s/&#38;/&/go;
584
    $text =~ s/\%/\\%/go;
585
    $text;
586
}
587
 
588
sub sub4 {
589
    my $text = $_[0];
590
    $text =~ s/\{/\\\{/go;
591
    $text =~ s/\}/\\\}/go;
592
 
593
    ## These tags can have id's
594
    $text =~ s+<s-expression(.*?)>(.*?)</s-expression>+\\code{$2}+go;
595
    $text =~ s+<s-object(.*?)>(.*?)</s-object>+\\code{$2}+go;
596
    $text =~ s+<s-function(.*?)>(.*?)</s-function>+\\code{$2}+go;
597
    $text =~ s+<s-class(.*?)>(.*?)</s-class>+\\code{$2}+go;
598
    $text =~ s+<s-method(.*?)>(.*?)</s-method>+\\code{$2}+go;
599
    $text =~ s+<s-dataset(.*?)>(.*?)</s-dataset>+\\code{$2}+go;
600
    ## I have never seen these used
601
    $text =~ s+<s-expref(.*?)>(.*?)</s-expref>+\\code{$2}+go;
602
    $text =~ s+<s-objref(.*?)>(.*?)</s-objref>+\\code{$2}+go;
603
    $text =~ s+<s-function-ref(.*?)>(.*?)</s-function-ref>+\\code{$2}+go;
604
    $text =~ s+<s-clsref(.*?)>(.*?)</s-clsref>+\\code{$2}+go;
605
    $text =~ s+<s-mthref(.*?)>(.*?)</s-mthref>+\\code{$2}+go;
606
    $text =~ s+<s-datref(.*?)>(.*?)</s-datref>+\\code{$2}+go;
607
    $text =~ s+<s-chpref(.*?)>(.*?)</s-chpref>+\\code{$2}+go;
608
 
609
    $text =~ s+<it>(.*?)</it>+\\emph{$1}+go;
610
    $text =~ s+<sl>(.*?)</sl>+\\emph{$1}+go;
611
    $text =~ s+<em>(.*?)</em>+\\emph{$1}+go;
612
    # not clear what to do with <sf>
613
    $text =~ s+<sf>(.*?)</sf>+\\bold{$1}+go;
614
    $text =~ s+<bf>(.*?)</bf>+\\bold{$1}+go;
615
    $text =~ s+<tt>(.*?)</tt>+\\code{$1}+go;
616
    $text =~ s+<url>(.*?)</url>+\\url{$1}+go;
617
    $text =~ s/\n*<p>\n*/\n\n/go;
618
    $text =~ s/(<br>\n*)+/\n/go;
619
    $text =~ s/\$/\\\$/go;
620
    $text =~ s/@/\\@/go;
621
 
622
    verbsub($text);
623
}
624
 
625
sub makelinks {
626
    my $text = $_[0];
627
 
628
    $text =~ s+<s-function name="(.*?)">(.*?)</s-function>+\\code{\\link{$2}}+go;
629
    $text;
630
}
631
 
632
 
2195 hornik 633
### Local Variables: ***
634
### mode: perl ***
635
### perl-indent-level: 2 ***
636
### End: ***