@echo off perl -x %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 goto end # cut below this line to run on UNIX #!/usr/local/bin/perl # $inFile = $ARGV[0] || "paper.rtf"; $outFile = "paper.htm"; # settings $BODY = "BGCOLOR=#FFFFFF"; $TOCBODY = "BGCOLOR=#C0C0C0"; $INDEXHEAD =< EOM $man = < Xref - Tool to Generate Cross References in an Article

Xref - Tool to Generate Cross References in an Article, Paper or Report

XREF generates cross references to figures, tables, sections and bibliography entries in an article or paper which has been converted to HTML language using the Rtf TO Html tool.

Usage

  1. Write a paper. Obey the following rules:
    • Use Harvard citation style. References should look like (Turk, 1997) or Turk (1997) or (Turk and Smith, 1997) or (Turk et al, 1997). There should be a section called "References" where the entries should look like


    • Turk, Z. (1997). Etc, etc, etc. 

    • Number the sections numerically with arabic numbers and dots, like 2.3 Method or 1 Intoduction.
    • Make sure that the figure captions start with something like FIG. 5: or Figure 5: (the colon after the number and the Fig[ure] strings are necessary. Make sure that references to figures look like see fig. 5 (this time without the colon).
    • The same goes for tables.
  2. Save the paper as RTF.
  3. Run the RTFtoHTM program.
  4. Run Xref.
    Xref will do the following:
    • Insert paragraph marks before and after figures. For some reason rtf2htm does not do this.
    • Create links from any http:// or ftp:// URLs not already liked.
    • Make nicer bullet lists out of paragraphs starting with *
    • Create cross references to figures, tables and bibliographic references.
    • Remove tale of contents from the text.
    • Create index.htm file. This file will contain the paper up to the section heading numbered with 1. It will include pointers to framed and non-framed version of the paper and the possible paper.pdf, paper.rtf and paper.doc files.
    • It will also create the file "toc.htm" with the table of contents.

Planned features

None.

Author

Xref was written by dr. Ziga Turk from the University of Ljubljana in Slovenia.

Source

Xref is available at http://www.fagg.uni-lj.si/~zturk/works/xref/. EOM if ($ARGV[0] eq "-MAN") { open (h,">xref.htm"); print h $man; close(h); print "Manual printed to file xref.htm\n"; exit; } # --- get the input file open (h,$inFile) || die "Cannot open $infile\n"; @rows=; $text = join('',@rows); undef @rows; # --- remove table of contents ($head,$contents,$text,$foot) = split (/
/i,$text,4); ($intro,$rest) = split (/1/,$text,2); do writePaper(); do writeIndex($head,$contents,$intro); exit; sub writeIndex { ($head,$contents,$intro)=@_; $*=1; $head =~ m|([^<]+)|i; $Title = $1; $intro =~ s/\n$//i; $*=0; print "$Title"; $contents =~ s|
  • |
    |gi; $contents =~ s|
      ||gi; $contents =~ s|
    ||gi; $contents =~ s|

    ||gi; $Contents_c = $inFile; $Contents_c =~ s|_t\.|_c.|; $contents =~ s|[^<]*||g; $contents =~ s|HREF="#|HREF="paper.htm#|g; $contents =~ s|(\d+\.\s)|
    $1|g; $contents = "$contents"; $pointers = ''; $pointers .= &pointers("paperf.htm","
    Full text in .HTML format with contents frame"); $pointers .= &pointers("paper.htm","
    Full text in .HTML format without frames"); $pointers .= &pointers("paper.pdf","
    Full text in .PDF format"); $pointers .= &pointers("paper.doc","
    Full text in .DOC format"); $pointers .= &pointers("paper.rtf","
    Full text in .RTF format"); print "toc.htm\n"; open (h,">toc.htm"); print h < Contents: $Title $Generator TITLE PAGE

    $contents EOM print "paperf.htm\n"; open (h,">paperf.htm"); print h < Frames: $Title $Generator Your browser cannot display this. Please select <A HREF=paper.htm>non-frames</A>. EOM print "index.htm\n"; open (h,">index.htm"); print h < Index: $title $Generator $INDEXHEAD
    $intro

    $pointers

    $contents
    $INDEXFOOT EOM } sub pointers { ($file,$text)=@_; return '' unless -e $file; @x = stat($file); $k = int($x[3]/1024.); return "$text ($k K)"; } sub writePaper { # --- images need paragraph # --- r2h $text =~ s|[^<]*||g; $text =~ s|\n\*\t|\n
    o |g; $text =~ s|

    \n|
    \n|gi; $text =~ s|
    \n|

    |gi; # --- figures $text =~ s|Fig[ure\.]*\s+(\d+):|Figure $1:|gi; $text =~ s|Fig[ure\.]*\s+(\d+)([^:0-9])|Fig. $1$2|gi; # --- newline after figure captions $*=1; $text =~ s|(Figure \d+:[^<]+)|$1

    |gi; $*=0; # --- tables cross refereces $text =~ s|Table\s+(\d+):|TABLE $1:|gi; $text =~ s|Tab[le\.]*\s+(\d+)([^:0-9])|Table $1$2|gi; # --- section references (rtfToHtm specific) $text =~ s|()([0-9\.]*[0-9])|$1$2|gi; $text =~ s|section\s+([0-9\.]+)|Section $1|gi; # --- URLs not after = or " $text =~ s|([^="])(http://[^\s\n<\)]*)|$1\n\n$2\n|g; $text =~ s|([^="])(ftp://[^\s\n<\)]*)|$1\n\n$2\n|g; # --- references --- name bibliography entries --- @x = split(/([0-9\.]+\s+references)/i,$text); $refs = $x[$#x]; @x = split(//i,$refs); $refs = $x[0]; @refs=split(/

    /i,$refs); $i=0; $*=1; foreach $ref (@refs) { # remove any tags in front while ($ref =~ s/^<[^>]*>\s*//) {}; $refs[$i]=$ref; #print $ref; @x = split(/\)/,$ref); $x = $x[0]; $x =~ s/^\s+//; $y = $x; $x =~ s/[^A-Za-z0-9\n]/./g; $ns = ($text =~ s|$x|$y|); if ($ns == 0) { print "Poorly formatted reference:\n$ref\n"; } $i++; } $*=0; # --- make oiters from text to references --- @items = split (/\)/,$text); foreach $item (@items) { $item = $item . ')'; if ($item =~ m/\d{4}[a-z]*\)$/) { $item =~ m/(\([^\(]+$)/; # match to open brace $xref = $1; if ($xref =~ m/[A-Z]/) { # letter ? # (Turk, 1997) style } else { # Turk (1997) style or $item =~ m/([A-Z][^\s]+\s+\(\d{4}[a-z]*\))$/; $xref = $1; $pxref = $xref; $pxref =~ tr/()/../; if ($item =~ m/([A-Z][^\s]+\s+and\s+$pxref)$/ ) { # can we find and in front $xref=$1; } } # xref = cross reference information $pref = $xref; $oBrace = '\('; $cBrace = '\)'; $inits = '[ A-Z\,\.\-]+'; $pref =~ s/\(/ /g; $pref =~ s/\)/ /g; $pref =~ s/^\s+//; $pref =~ s/\s+$//; $pref =~ s/\s+et\s+al\.*\s+/ETALIA/i; $pref =~ s/(\d{4}[a-z]*)/$oBrace$1$cBrace/; $pref =~ s/ETALIA/[^\(]+/; $pref =~ s/\s+/$inits/g; @x = grep(/$pref/,@refs); if ($#x != '0') { $n = $#x + 1; print "Reference $xref matched $n times.\n"; } else { $j=0; foreach $ref (@refs) { last if $ref eq $x[0]; $j++; } if ($j <= $#refs) { $used[$j]=1; $_ = $xref; s/\(/\\\(/g; s/\)/\\\)/g; $ns = ( $item =~ s|$_$|$xref| ); if ($ns != 1) { print "Problems creating reference to $xref using $_\n"; } } else { print "Cannot resolve reference to $xref\n"; } } } else { # not a reference with a year } $newText .= $item; } for ($i=0;$i<=$#refs;$i++) { unless ($used[$i]) {print "Reference $refs[$i] not used\n\n"}; } print "$outfile\n"; # head , title ... open (h,">$outFile"); print h < $title $Generator $PAPERHEAD EOM print h $newText; print h $PAPERFOOT; close(h); } __END__ :end