# -*- mode: Perl -*-
# /=====================================================================\ #
# |  wrapfig                                                            | #
# | 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;

#**********************************************************************
# New environment from package wrapfigure:
# \caption will handle refnums, etc.
DefEnvironment('{wrapfigure} [Number] {} [Dimension] {Dimension}',
  "<ltx:figure refnum='#refnum' frefnum='#frefnum' rrefnum='#rrefnum' xml:id='#id' float='#float'>"
    . "#body"
    . "</ltx:figure>",
  afterDigestBegin => sub {
    my $dir = ToString($_[1]->getArg(2));
    $_[1]->setProperty(float => ($dir eq 'r' ? 'right'
        : ($dir eq 'l' ? 'left'
          : undef))); },
  beforeDigest => sub { DefMacroI('\@captype', undef, 'figure'); },
  afterDigest => sub { RescueCaptionCounters('figure', $_[1]); });

DefEnvironment('{wraptable} [Number] {} [Dimension] {Dimension}',
  "<ltx:table refnum='#refnum' frefnum='#frefnum' rrefnum='#rrefnum' xml:id='#id' float='#float'>"
    . "#body"
    . "</ltx:table>",
  afterDigestBegin => sub {
    my $dir = ToString($_[1]->getArg(2));
    $_[1]->setProperty(float => ($dir eq 'r' ? 'right'
        : ($dir eq 'l' ? 'left'
          : undef))); },
  beforeDigest => sub { DefMacroI('\@captype', undef, 'table'); },
  afterDigest => sub { RescueCaptionCounters('table', $_[1]); });

DefMacro('\WFclear', '\par');
DefRegister('\wrapoverhang' => Dimension(0));

#**********************************************************************

1;
