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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
# graphicx.perl by Ross Moore <ross@mpce.mq.edu.au> 98/1/7
# same as ...
#
# graphics.perl by Herbert Swan <dprhws.edp.Arco.com> 12-22-95
#
# Extension to LaTeX2HTML V 96.1 to supply support for the "graphics"
# and "graphicx" standard LaTeX2e packages.
#
# extended and revised for LaTeX2HTML V 98.1
# by Ross Moore <ross@mpce.mq.edu.au> 98/1/7
#
# Change Log:
# ===========
# - Extended \includegraphics to simply include an existing pixel image file
# provided one of the appropriate type (jpeg,gif,png) already exists,
# rather than always punt to latex to create an image;
# optionally, copies the image into the HTML directory.
# Also, minor tweaks to \graphicspath.
#
# Question: Should some options to \includegraphics (eg. rotate, clip...)
# disable the reuse of the pixel image, or is it a valid assumption that
# such an image file will already be appropriately formatted? Or, does
# there need to be some option to control it.
# Also, there's no mechanism (yet) to put a meaningful alt attribute.
# Bruce Miller <bruce.miller@nist.gov> 2001-01-23
package main;
# BRM: These are the extensions that we'll look specifically for.
$GRAPHICS_EXTENSIONS=['png','jpg','jpeg','gif'];
# BRM: Whether to copy existing graphics files into the html tree.
$COPY_GRAPHICS = 0 unless defined($COPY_GRAPHICS);
# BRM: The path to search for graphics files (extended by \graphicspath)
@GRAPHICS_PATH = () unless defined(@GRAPHICS_PATH);
# Suppress option-warning messages:
sub do_graphics_dvips {
}
sub do_graphicx_dvips {
}
# BRM: modified to remove \Q ..\E from replacement patterns.
# and to save the declared path.
sub do_cmd_graphicspath {
local($_) = @_;
local($paths);
$paths = &missing_braces unless (
(s/$next_pair_pr_rx/$paths=$2;''/e)
||(s/$next_pair_rx/$paths=$2;''/e));
$paths = &revert_to_raw_tex($paths);
#RRM: may only work correctly for Unix
# $dd holds the directory-delimiter, usually /
$paths =~ s/\s*({|})\s*/$1/g;
local(@paths) = split (/}/, $paths);
if ($DESTDIR eq $FILE) {
# given paths are relative to parent directory
map(s|^{([^/~\.\$\\][^}]*)|{..$dd$1|, @paths);
map(s/^{\.\Q$dd\E/{\.\.\Q$dd\E/, @paths);
} elsif ($DESTDIR eq '.') {
# paths are already relative to working directory
} else {
# specify full paths, by prepending source directory
map(s|^{([^/~\.\$\\][^}]*)|{$orig_cwd$dd$1|, @paths);
map(s/^{\.\Q$dd\E/{$orig_cwd\Q$dd\E/, @paths);
}
$paths = join('}', @paths).'}';
map(s/^{//,@paths); # Strip leading { and trailing $dd
map(s/\Q$dd\E$//,@paths);
@GRAPHICS_PATH = (@GRAPHICS_PATH,@paths);
$latex_body .= "\n\\graphicspath{$paths}\n\n" unless ($PREAMBLE);
$_
}
sub do_cmd_DeclareGraphicsRule {
local($_) = @_;
local($arg1,$arg2,$arg3,$arg4);
$arg1 = &missing_braces unless (
(s/$next_pair_pr_rx/$arg1=$&;''/e)
||(s/$next_pair_rx/$arg1=$&;''/e));
$arg2 = &missing_braces unless (
(s/$next_pair_pr_rx/$arg2=$&;''/e)
||(s/$next_pair_rx/$arg2=$&;''/e));
$arg3 = &missing_braces unless (
(s/$next_pair_pr_rx/$arg3=$&;''/e)
||(s/$next_pair_rx/$arg3=$&;''/e));
$arg4 = &missing_braces unless (
(s/$next_pair_pr_rx/$arg4=$&;''/e)
||(s/$next_pair_rx/$arg4=$&;''/e));
# need a full path to the filename
$arg4 =~ s/(\#1)/$orig_cwd$dd$1/g
unless ($arg4 =~ /^\Q$dd\E|\Q$env_key\E/);
$latex_body .= "\n".&revert_to_raw_tex(
'\DeclareGraphicsRule'.$arg1.$arg2.$arg3.$arg4)."\n";
$_;
}
# Utility: Find a file in one of a set of directories, with one of a
# set of file extensions.
sub find_file {
my($name,$dirs,$exts)=@_;
$dirs = [@$dirs,$texfilepath]; # Include the tex source dir.
# file name may already have an absolute or partial path
my @comps=split(/\Q$dd\E/,$name);
$name=$comps[$#comps];
if($comps[0] eq ''){ # Started w/$dd => absolute path (too unixy!?!)
$dirs = [join($dd,@comps[0..$#comps-1])]; }
elsif(@comps > 0){ # else prepend path components, if any
my $pre=join($dd,@comps[0..$#comps-1]);
$dirs = [map("$_$dd$pre",@$dirs)]; }
# file name may already have an extension. If so, we're stuck with it (?)
if($name =~ /^(.*)\.([^\.]*)$/){
return '' unless grep($2 eq $_, @$exts);
$name = $1; $exts = [$2]; }
# Now start searching.
my($dir,$ext);
foreach $dir (@$dirs){
foreach $ext (@$exts){
my $file = "$dir$dd$name.$ext";
return $file if (-f $file); }}
return ''; }
# Another utility: copy a file into the HTML tree.
# returns the relative path to the file.
# This is a little too unixy, but I'd like to check & preserve timestamps.
sub maybe_copy_file {
my($src)=@_;
my @comps=split(/\Q$dd\E/,$src);
my $dst=".$dd".$comps[$#comps];
# L2hos->Copy($src,$dst); # Now, copy to HTML tree
# Use unix cp so we can preserve timestamp
if(!(-f $dst) || (-M $dst > -M $src)){
system("cp -p $src $dst")
&& warn "Couldn't copy $src to HTML tree: $!\n"; }
return $dst;
}
# ignore clipping request ?
sub do_cmd_includegraphicsstar { do_cmd_includegraphcs(@_); }
sub do_cmd_includegraphics {
local($_)=@_;
my($parms)=get_next_optional_argument();
local($file);
$file = &missing_braces unless (
(s/$next_pair_pr_rx/$file=$2;''/e)
||(s/$next_pair_rx/$file=$2;''/e));
$parms = &revert_to_raw_tex($parms);
$file = &revert_to_raw_tex($file);
my $after = $_;
# Should probably test $parms to see that it is appropriate to subst gif.
my $grfile = find_file($file,[@GRAPHICS_PATH],$GRAPHICS_EXTENSIONS);
my $image;
if($grfile){ # Found an image file!
$grfile = maybe_copy_file($grfile) if $COPY_GRAPHICS;
$image = embed_image($grfile,'external image',0,"Image $grfile",
'','','','','',''); }
else { # Otherwise, put in images.tex as usual.
$image = process_in_latex("\\includegraphics[$parms]\{$file\}"); }
join('',$image,$after); }
&process_commands_wrap_deferred (<<_RAW_ARG_CMDS_);
graphicspath # {}
_RAW_ARG_CMDS_
&process_commands_in_tex (<<_RAW_ARG_CMDS_);
rotatebox # [] # {} # {}
scalebox # {} # [] # {}
reflectbox # {}
resizeboxstar # {} # {} # {}
resizebox # {} # {} # {}
_RAW_ARG_CMDS_
&process_commands_nowrap_in_tex (<<_RAW_ARG_CMDS_);
DeclareGraphicsExtensions # {}
#DeclareGraphicsRule # {} # {} # {} # {}
psfragstar # {} # {}
psfrag # {} # {}
_RAW_ARG_CMDS_
&ignore_commands( <<_IGNORED_CMDS_);
setkeys # {} # {}
_IGNORED_CMDS_
1; # Must be last line
|