This file is indexed.

/usr/share/perl5/LaTeXML/Package/graphics.sty.ltxml is in latexml 0.8.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# -*- mode: Perl -*-
# /=====================================================================\ #
# |  graphics                                                           | #
# | Implementation for LaTeXML                                          | #
# |=====================================================================| #
# | Part of LaTeXML:                                                    | #
# |  Public domain software, produced as part of work done by the       | #
# |  United States Government & not subject to copyright in the US.     | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov>                        #_#     | #
# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
# \=========================================================ooo==U==ooo=/ #
#**********************************************************************
package LaTeXML::Package::Pool;
use strict;
use warnings;
use LaTeXML::Package;
use LaTeXML::Util::Pathname;
use LaTeXML::Util::Image;

#======================================================================
# (See  LaTeXML::Post::Graphics for suggested postprocessing)
# Package options: draft, final, hiderotate, hidescale, hiresbb

DefParameterType('GraphixDimension', sub {
    my ($gullet) = @_;
    if ($gullet->ifNext(T_OTHER('!'))) {
      $gullet->readToken();
      Dimension(0); }
    else {
      $gullet->readDimension; } });

DefConstructor('\scalebox{}[] Digested',
  "<ltx:inline-block angle='#angle' width='#width' height='#height' depth='#depth'"
    . " innerwidth='#innerwidth' innerheight='#innerheight' innerdepth='#innerdepth'"
    . " xscale='#xscale' yscale='#yscale'"
    . " xtranslate='#xtranslate' ytranslate='#ytranslate'>"
    . "#3"
    . "</ltx:inline-block>",
  properties => sub {
    my ($stomach, $xscale, $yscale, $box) = @_;
    $xscale = ToString($xscale);
    $yscale = ($yscale ? ToString($yscale) : $xscale);
    my ($w, $h, $d) = $box->getSize;
    return () unless $w;
    (width => $w->multiply($xscale),
      height     => $h->multiply($yscale),
      depth      => $d->multiply($yscale),
      xscale     => $xscale,
      yscale     => $yscale,
      xtranslate => $w->multiply(($xscale - 1) / 2),
      ytranslate => $h->add($d)->multiply(($yscale - 1) / 2)); },
  mode => 'text');

DefConstructor('\resizebox OptionalMatch:* {GraphixDimension}{GraphixDimension} Digested', sub {
    my ($document, $star, $width, $height, $box, %props) = @_;
    insertBlock($document, $box,
      width  => $props{width},
      height => $props{height},
      depth  => $props{depth}); },    # ?
  properties => sub {
    my ($stomach, $star, $width, $height, $box) = @_;
    (($width ? (width => $width) : ()),
      ($height ? (height => $height) : ()),
      depth => Dimension(0)); },      # ?
  mode => 'text');

# TeX wants to rotate CCW, by default, about the left baseline,
# but some macros allow you to specify the point or corner about which to rotate.
# It then allocates the width of the resulting box.
# CSS3's rotation wants to rotate CW about the CENTER of the box!
# The resulting box should have it's origin at the leftmost corner
# But we're shifting the box from the position CSS thought that it WAS (before rotation!)
# However, I THINK that it is using the GIVEN width & height
# to determine the center!
# Presumably CSS has lost the sense of the box's baseline?
# Note that our transformable-attributes apply: translate, scale, rotate, in that order.

# NOTE: There's a bizarre interaction between these CSS transformations
# and position:absolute that I haven't sorted out!
sub rotatedProperties {
  my ($box, $angle, %options) = @_;
  $angle = $angle->valueOf if ref $angle;
  my $cwangle = -$angle;
  my ($width, $height, $depth) = $box->getSize;
  return () unless $width;
  my ($w, $h, $d) = map { $_->valueOf } $width, $height, $depth;
  my $x0 = 0;
  my $y0 = 0;
  if ($options{x}) { $x0 = $options{x}; $x0 = $x0->valueOf if ref $x0; }
  if ($options{y}) { $y0 = $options{y}; $y0 = $y0->valueOf if ref $y0; }

  if (my $origin = ToString($options{origin})) {
    if    ($origin =~ /l/) { $x0 = 0; }
    elsif ($origin =~ /r/) { $x0 = $w; }
    elsif ($origin =~ /c/) { $x0 = $w / 2; $y0 = ($h - $d) / 2; }
    if    ($origin =~ /t/) { $y0 = $h; }
    elsif ($origin =~ /b/) { $y0 = -$d; }
    elsif ($origin =~ /B/) { $y0 = 0; } }
##  print STDERR "ROTATE ".$width->ptValue." x ".$height->ptValue." + ".$depth->ptValue
##    ." by $angle about ".Dimension($x0)->ptValue.", ".Dimension($y0)->ptValue."\n";

  my $H        = $h + $d;
  my $rad      = $angle * 3.1415926 / 180;      # close enough
  my $s        = sin($rad);
  my $c        = cos($rad);
  my $wp       = abs($w * $c) + abs($H * $s);
  my @cornerys = (
    (-$d - $y0) * $c + (+0 - $x0) * $s + $y0,     # bottom left
    (-$d - $y0) * $c + ($w - $x0) * $s + $y0,     # bottom right
    (+$h - $y0) * $c + ($w - $x0) * $s + $y0,     # top right
    (+$h - $y0) * $c + (+0 - $x0) * $s + $y0);    # top left
  my $hp  = max(@cornerys);
  my $dp  = -min(@cornerys);
  my $xsh = Dimension(($wp - $w) / 2)->ptValue . 'pt';
  #   my $ysh = Dimension(-($hp + $dp - $h - $d) / 2)->ptValue . 'pt';
  #  my $ysh = Dimension(($h + $d - $hp + $dp) / 2)->ptValue . 'pt';
  # Not sure about the geometry here!
  my $ysh = Dimension(($h - $hp + $dp) / 2 + $d)->ptValue . 'pt';
  if ($options{smash}) {
    #    $wp = $hp = $dp = 0; }
    $wp = 0; }
  # Since $dp & $ysh both try to have the same effect
  # (& I don't think the CSS box really has a depth anymore)
  $hp += $dp; $dp = 0;
  my $widthp  = Dimension($wp);
  my $heightp = Dimension($hp);
  my $depthp  = Dimension($dp);
##  print STDERR " => ".$widthp->ptValue." x ".$heightp->ptValue." + ".$depthp->ptValue." => ".$xsh.", ".$ysh."\n";

## print STDERR "\nROTATE $angle of ".ToString($box)."\n"
##  ." == ".ToString($width).' x '.ToString($height).' + '.ToString($depth)."\n"
##  ." => ".ToString($widthp).' x '.ToString($heightp).' + '.ToString($depthp)."\n";
  return (
    angle       => $angle,
    width       => $widthp,
    height      => $heightp,
    depth       => $depthp,
    innerwidth  => $width,
    innerheight => $height,
    innerdepth  => $depth,
    xtranslate  => $xsh,
    ytranslate  => $ysh,
    ); }

# NOTE: Need to implement the origin of rotation!
# [code so far only reads them]
DefKeyVal('Grot', 'origin', '');            # c,l,r,t,b,B
DefKeyVal('Grot', 'x',      'Dimension');
DefKeyVal('Grot', 'y',      'Dimension');
DefKeyVal('Grot', 'units',  '');
DefConstructor('\rotatebox OptionalKeyVals:Grot {Float} Digested',
  "<ltx:inline-block angle='#angle' width='#width' height='#height' depth='#depth'"
    . " innerwidth='#innerwidth' innerheight='#innerheight' innerdepth='#innerdepth'"
    . " xscale='#xscale' yscale='#yscale'"
    . " xtranslate='#xtranslate' ytranslate='#ytranslate'>"
    . "#3"
    . "</ltx:inline-block>",
  afterDigest => sub {
    my ($stomach, $whatsit) = @_;
    my ($kv, $angle, $box) = $whatsit->getArgs();
    $whatsit->setProperties(rotatedProperties($box, $angle, ($kv ? $kv->getHash : ()))); });

DefConstructor('\reflectbox Digested',
  "<ltx:inline-block angle='#angle' width='#width' height='#height' depth='#depth'"
    . " innerwidth='#innerwidth' innerheight='#innerheight' innerdepth='#innerdepth'"
    . " xscale='#xscale' yscale='#yscale'"
    . " xtranslate='#xtranslate' ytranslate='#ytranslate'>"
    . "#1"
    . "</ltx:inline-block>",
  properties => sub {
    my ($stomach, $box) = @_;
    my ($w, $h, $d) = $box->getSize;
    return () unless $w;
    (width => $w,
      height => $h,
      depth  => $d,
      xscale => -1,
      yscale => 1); },
  mode => 'text');

DefConstructor('\graphicspath DirectoryList', sub {
    my ($document, $paths, %props) = @_;
    foreach my $path (@{ $props{paths} }) {
      $document->insertPI('latexml', graphicspath => $path); } },
  properties => sub {
    my ($stomach, $paths) = @_;
    my @paths = ();
    foreach my $dir ($paths->getValues) {
      my $path = pathname_absolute(pathname_canonical(ToString($dir)));
      push(@paths, $path);
      PushValue(GRAPHICSPATHS => $path); }
    return (path => [@paths]); });

# Basically, we're transforming the graphics options into graphicx format.
DefMacro('\includegraphics OptionalMatch:* [][] Semiverbatim',
  '\@includegraphics#1[#2][#3]{#4}');

DefConstructor('\@includegraphics OptionalMatch:* [][] Semiverbatim',
  "<ltx:graphics graphic='#graphic' candidates='#candidates' options='#options'/>",
  sizer      => \&image_graphicx_sizer,
  properties => sub {
    my ($stomach, $starred, $op1, $op2, $graphic) = @_;
    my $bb = ($op2 ? ToString($op1) . " " . ToString($op2) : ($op1 ? "0 0 " . ToString($op1) : ''));
    $bb =~ s/,/ /g;
    my $options = ($starred ? ($bb ? "viewport=$bb, clip" : "clip") : '');
    $graphic = ToString($graphic); $graphic =~ s/^\s+//; $graphic =~ s/\s+$//;
    my @candidates = pathname_findall($graphic, types => ['*'], paths => LookupValue('GRAPHICSPATHS'));
    if (my $base = LookupValue('SOURCEDIRECTORY')) {
      @candidates = map { pathname_relative($_, $base) } @candidates; }
    (graphic => $graphic,
      candidates => join(',', @candidates),
      options => $options); },
  alias => '\includegraphics');

# Also unimplemented... probably nothing useful to pass thru anyway?
DefConstructor('\DeclareGraphicsExtensions{}',          '');
DefConstructor('\DeclareGraphicsRule{}{}{} Undigested', '');
# Nothing done about the keyval package...
#======================================================================
1;