On Sun, 31 Aug 1997 12:07:05, Boris Veytsman <[EMAIL PROTECTED]> wrote:
Boris> Sometimes one need to reference equation, table or figure in another
Boris> document. Both LaTeX itself and LaTeX2HTML have facilities to do this.
Boris> Unfortunately, they are NOT integrated.
[SNIP]
Boris> I would like to suggest a package xrhtml.sty/xrhtml.pl. It would define a
Boris> command
Boris> \externalhtmldoc[Prefix]{path to .aux file}{URL}{path to labels.pl}
Boris> After this command, \ref{Prefix-label} should produce both LaTeX number
Boris> *and* hyperlink.
[I haven't seen a response to this --- please let me know if there is one...]
Here's what I've recently come up with, which does roughly what I
want, and seems to work ok. In the LaTeX source it does force you to
distinguish between internal and external refs, but this is probably a
reasonable thing:
For the latex2html version:
(a) Ive modified \externallabels so that it takes an optional TAG
(as in the xr package \externaldocument[TAG]{FILE})
\externallabels[TAG]{URL}{LABELSFILE}
This prefixes TAG to all labels defined in LABELSFILE, and with
URL as the base location of the document
(b) \niceexternalref[CITE]{TEXT}{REF}
links TEXT to external REF (REF may now include a prefix TAG). CITE
is ignored.
(note: \niceexternalref also modifies the display of links to
external refs, so that it uses TEXT as an anchor for REF,
instead of having a gif)
For the LaTeX version:
\externallabels does nothing
For \niceexternalref[CITE]{TEXT}{REF}, if CITE is present, then
produce a citation with a reference, i.e.
TEXT\cite[\ref{REF}]{CITE}
otherwise simply produce TEXT. You still need to use
\externaldocument to load the external refs and add in any TAG
prefixes...
These are in files niceexternal.[sty,perl] (below)
An example of \externallabels etc to include in a document is:
\externallabels[AHV:]{http://www.cs.man.ac.uk/fmethods/projects/AHV-PROJECT}
{/tmp/AHV/html/ahv-project/labels.pl}
\externaldocument[AHV:]{/tmp/AHV/tex/ahv-project}
regards,
Alan.
--
Dr. A Williams, Room 2.116, email: [EMAIL PROTECTED]
Department of Computer Science Tel: +44 (0) 161-275-6137
University of Manchester, fax: +44 (0) 161-275-6211
Manchester, M13 9PL, ENGLAND
Computer 50
The University of Manchester Celebrates the Birth of the Modern Computer
Digital Summer 1998
URL: http://www.computer50.org/
----------------------------------------------------------------------
niceexternal.sty
----------------------------------------------------------------------
%% define a `nice' external reference (could probably be done differently)
%%\newcommand{\niceexternalref}[2]{#1}
\RequirePackage{ifthen}
\RequirePackage{xr}
\newcommand{\niceexternalref}[3][NOPREFIX]{%
\ifthenelse{\equal{#1}{NOPREFIX}}%
{#2}%
{#2\cite[\S\ref{#3}]{#1}}}
%% REdefine external labels, to take an extra optional argument, and
%% to ignore everything
\renewcommand{\externallabels}[3][]{}
----------------------------------------------------------------------
niceexternal.perl
----------------------------------------------------------------------
# must be loaded after html.sty, since it redefines do_cmd_externallabels
# 1. modified usage of \externallabels:
# \externallabels[TAG]{URL}{labelsfile}
# prefixes TAG to all labels defined in labelsfile
# This gives similar functionality to the xr.sty package in LaTeX.
# (it would be nice to replicate this exactly...)
# 2. modified display of links to external refs (use TEXT as anchor for REF)
# \niceexternalref[CITE]{TEXT}{REF}
#
# links TEXT to external REF (ref may include a prefix TAG).
# In LaTeX if CITE is present, produce TEXT\cite[\ref{REF}]{CITE},
# otherwise simply produce TEXT.
package main;
print "\n\n(alanw) niceexternal.perl: uses replace_external_references_hook
(instead of replace_external_references from latex2html)\n\n
Redefining do_cmd_externallabels from html.perl\n\n";
$replace_external_references_hook = 1;
# \niceexternalref[cite]{TEXT}{URL} uses TEXT to link to URL, instead of
# having a (rather ugly) gif.
# very similar to \externalref
#(I think there are still bugs in process_ref)
sub do_cmd_niceexternalref{
local($_) = @_;
local($text);
local($ignore,$dum) = &get_next_optional_argument;
s/$next_pair_pr_rx/$text = $2; ''/eo;
&process_ref($external_ref_mark,$external_ref_mark,$text);
}
sub replace_external_references_hook {
# Modifies $_
s/$external_ref_mark#([^#]+)#([^>]+)>$external_ref_mark/
&replace_external_references_hook_helper($1,$2);/geo;
}
# Find if $label has a prefix appearing in $LABELPREFIXES;
# If so, remove it to create the actual label
# (but look up in the external_labels database using the original extended label)
sub replace_external_references_hook_helper {
my ($label,$id) = @_;
my ($basiclabel, $link);
($basiclabel = $label) =~ s/$LABELPREFIXES//go;
$link = $external_labels{$label};
# $link will be empty if it can't be found
print "\nLabel: $label (changed to $basiclabel); Link: $link" if ($VERBOSITY >1);
'"' . "$link#$basiclabel" . "\">\n" . &get_ref_mark("$label",$id);
}
# accumulate the prefixes
$LABELPREFIXES = "";
# modify \externallabels to take an optional argument which acts as
# a distinguishing tag on those external labels (as with \externaldocument)
sub do_cmd_externallabels{
local($_) = @_;
local($URL,$labelfile);
local($PREFIX,$dum) = &get_next_optional_argument;
s/$next_pair_pr_rx/$URL = $2; ''/eo;
s/$next_pair_pr_rx/$labelfile = $2; ''/eo;
# add $PREFIX to the list of known prefixes:
$LABELPREFIXES .= (length($LABELPREFIXES) ? "|" : "") . $PREFIX
unless ($PREFIX eq "");
# print out what we've got so far:
if ($VERBOSITY >1) {
print "niceexternal: LABELPREFIXES: $LABELPREFIXES\n" unless ($PREFIX eq "");
}
local($dir,$nosave) = ('','');
if (-f "$labelfile") {
if ($PREFIX eq "") {
require($labelfile);
} else {
open(LABELFILE,"<$labelfile");
print "niceexternal: reading file: $labelfile; label prefix: $PREFIX\n"
if ($VERBOSITY >1);
my ($translated_stream, $instream);
while ($instream = <LABELFILE>) {
# prepend $PREFIX to each $key in labels.pl
$instream =~ s/\$key = q\//\$key = q\/$PREFIX/sg;
$translated_stream .= $instream;
}
close(LABELFILE);
eval $translated_stream;
}
} else {
&write_warnings(
"Could not find the external label file: $labelfile\n");
}
$_;
}
&ignore_commands( <<_IGNORED_CMDS_);
externaldocument # [] # {}
_IGNORED_CMDS_
1;