LaTeXML

 view release on metacpan or  search on metacpan

lib/LaTeXML/Package/pgfsys-latexml.def.ltxml  view on Meta::CPAN

    digestAlignmentBody($stomach, $whatsit);
    $stomach->egroup;
    $LaTeXML::ALIGN_STATE--;    # Balance the opening { OUTSIDE of the masking of ALIGN_STATE
    return; });

sub tikzAlignmentBindings {
  my ($template, $mode, %properties) = @_;
  $mode = LookupValue('MODE') unless $mode;
  my $ismath    = $mode =~ /math$/;
  my $container = 'svg:g';
  my $rowtype   = 'svg:g';
  my $coltype   = 'svg:g';
  my $alignment = LaTeXML::Core::Alignment->new(
    template       => $template,
    openContainer  => sub { openTikzAlignment($container, @_); },
    closeContainer => sub { closeTikzAlignmentElement($container, @_); },
    openRow        => sub { openTikzAlignmentRow($rowtype, @_); },
    closeRow       => sub { closeTikzAlignmentElement($container, @_); },
    openColumn     => sub { openTikzAlignmentCol($coltype, @_); },
    closeColumn    => sub { closeTikzAlignmentElement($container, @_); },
    isMath         => $ismath,
    properties     => { preserve_structure => 1, %properties });
  AssignValue(Alignment => $alignment);
  Let(T_MATH, ($ismath ? '\@dollar@in@mathmode' : '\@dollar@in@textmode'));
  return; }

# Note that pgf *seems* to have set the coordinate system to the center(?) (w/ \pgfsys@transformcm)
# Additionally, there's a svg:g outside the alignment (w/ ltx_svg_fog)
# The following tweaks (heuristically) the transform to position the alignment object
#
# Coordinates are currently pgf: y moves UP
# Coordinates of alignment are : y moves DOWN
sub openTikzAlignment {
  my ($tag, $doc, %props) = @_;
  my $w          = ($props{cwidth}  && $props{cwidth}->pxValue)  || 0;
  my $h          = ($props{cheight} && $props{cheight}->pxValue) || 0;
  my $d          = ($props{cdepth}  && $props{cdepth}->pxValue)  || 0;
  my @rowheights = ($props{rowheights}   ? @{ $props{rowheights} }   : (Dimension(0)));
  my @colwidths  = ($props{columnwidths} ? @{ $props{columnwidths} } : (Dimension(0)));
  my $x          = 0;
  # This SHOULD be just $h+$d, but the shift is necessary to align
  # w/additional material outside the \halign ( arrows & such)
  my $y = ($h + $d) - $rowheights[-1]->pxValue / 2;    # HEURISTIC adjustment! half of LAST row!?
  Debug("TIKZ Alignment size $w x $h + $d"
      . "  rows: " . join(',', map { $_->pxValue; } @rowheights)
      . "  cols: " . join(',', map { $_->pxValue; } @colwidths)
      . " => alignment adjustment = $x, $y") if $LaTeXML::DEBUG{pgf};
  my $array = $doc->openElement($tag, class => 'ltx_tikzmatrix',
    _scopebegin => 1,
    transform   => "matrix(1 0 0 -1 $x $y)",
    %props);
  $doc->insertElement('svg:rect', undef, class => 'ltx_debug',
    x => -4, y => -4, width => $w + 8, height => $h + $d + 8, stroke => '#FF0000', fill => 'none')
    if $LaTeXML::DEBUG{pgf};
  return $array; }

sub closeTikzAlignmentElement {
  my ($tag, $document) = @_;
  my $node = $document->closeElement($tag);
  if ($LaTeXML::DEBUG{pgf} && $node && (($node->getAttribute('class') || '') eq 'ltx_debug')) {
    my $rect = $node->firstChild;    # Move the rectangle to the end, so it overlays
    $node->removeChild($rect);
    $node->appendChild($rect); }
  return $node; }

sub openTikzAlignmentRow {
  my ($tag, $doc, %props) = @_;
  my $class = 'ltx_tikzmatrix_row' . ($props{class} ? ' ' . $props{class} : '');
  my $y     = ($props{y}       && $props{y}->pxValue)       || 0;
  my $w     = ($props{cwidth}  && $props{cwidth}->pxValue)  || 0;
  my $h     = ($props{cheight} && $props{cheight}->pxValue) || 0;
  my $d     = ($props{cdepth}  && $props{cdepth}->pxValue)  || 0;
  my $yy    = $y + $h;
  Debug("TIKZ alignment Row ($w x $h + $d); y=$yy; ") if $LaTeXML::DEBUG{pgf};
  my $row = $doc->openElement($tag, class => $class,
    _scopebegin => 1,
    transform   => "matrix(1 0 0 1 0 $yy)",
  );
  $doc->insertElement('svg:rect', undef,
    x => -2, y => -$h - 2, width => $w + 4, height => $h + $d + 4, stroke => '#00FF00', fill => 'none')
    if $LaTeXML::DEBUG{pgf};
  return $row; }

sub openTikzAlignmentCol {
  my ($tag, $doc, %props) = @_;
  my $class = 'ltx_tikzmatrix_col' . ($props{class} ? ' ' . $props{class} : '');
  # BEWARE: pgf places each column at 0 width, preceded by an \hskip width/2
  # and followed by an extra column of width/2.
  # Be careful accounting for rowwidths, etc while pruning & positioning in Alignment.pm
  my $w = ($props{cwidth}  && $props{cwidth}->pxValue)  || 0;
  my $h = ($props{cheight} && $props{cheight}->pxValue) || 0;
  my $d = ($props{cdepth}  && $props{cdepth}->pxValue)  || 0;
  my $x = ($props{x}       && $props{x}->pxValue)       || 0;
  my $y = 0;
  Debug("TIKZ alignment Cell ($w x $h + $d); x=$x; "
      . join(',', map { $_ . "=" . ToString($props{$_}); } sort keys %props)) if $LaTeXML::DEBUG{pgf};
  my $col = $doc->openElement($tag, class => $class,
    _scopebegin => 1,
    transform   => "matrix(1 0 0 -1 $x $y)",    # NOTE: Flip!!!
  );
  $doc->insertElement('svg:rect', undef,
    x => -1, y => -$h - 1, width => $w + 2, height => $h + $d + 2, stroke => '#0000FF', fill => 'none')
    if $LaTeXML::DEBUG{pgf};
  return $col; }

#=====================================================================
# Dealing with quick commands

# Coordinates
# Let(T_CS('\pgfqpoint'),T_CS('\pgfpoint'));
# Let(T_CS('\pgfqpointxy'),T_CS('\pgfpointxy'));
# Let(T_CS('\pgfqpointxyz'),T_CS('\pgfpointxyz'));
# Let(T_CS('\pgfqpointscale'),T_CS('\pgfpointscale'));

# Path construction

1;



( run in 1.152 second using v1.01-cache-2.11-cpan-f56aa216473 )