File: float.sty.ltxml

package info (click to toggle)
latexml 0.8.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 29,128 kB
  • sloc: xml: 98,982; perl: 29,706; sh: 179; javascript: 28; makefile: 15
file content (88 lines) | stat: -rw-r--r-- 4,174 bytes parent folder | download | duplicates (3)
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
# -*- mode: Perl -*-
# /=====================================================================\ #
# |  float                                                              | #
# | 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.     | #
# |---------------------------------------------------------------------| #
# | Thanks to the arXMLiv group for initial implementation              | #
# |    http://arxmliv.kwarc.info/                                       | #
# | Released to the Public Domain                                       | #
# |---------------------------------------------------------------------| #
# | 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;

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Choose the current float style (plain, plaintop, boxed, ruled)
DefMacro('\float@style',  'plain');
DefMacro('\floatstyle{}', '\def\float@style{#1}');
# \restylefloat{style}  Ignore for now...
DefMacro('\restylefloat OptionalMatch:* {}', undef);
# \floatplacement{style}{placement}  Ignorable
DefMacro('\floatplacement{}{}', undef);

# \listof{type}{title}   Ignorable
DefMacro('\listof{}{}', undef);

# \floatname{type}{name}
#DefMacro('\floatname{}{}', '\@namedef{#1name}{#2}');
DefMacro('\floatname{}{}', '\@namedef{lx@name@#1}{#2}');
our %float_outerframe = (ruled => 'top');
our %float_innerframe = (ruled => 'topbottom', boxed => 'rectangle');
DefPrimitive('\newfloat{}{}{}[]', sub {
    my ($gullet, $type, $placement, $auxext, $within) = @_;
    $type   = ToString($type);
    $within = ToString($within);
    my $style = ToString(Digest(T_CS('\float@style')));
    NewCounter($type, $within);
    DefMacroI('\the' . $type, undef, '\the' . $within . '.\arabic{' . $type . '}') if $within;
    if (!LookupDefinition(T_CS('\\lx@name@' . $type))) {
      DefMacroI('\\lx@name@' . $type, undef, $type); }
    my $isplain = $style =~ /^plain/;
    DefMacroI('\fnum@font@' . $type, undef, ($isplain ? '\rmfamily' : '\bfseries'));
    DefMacroI('\format@title@' . $type, '{}',
      ($isplain
        ? '\lx@tag[][: ]{\lx@fnum@@{' . $type . '}} #1'
        : '\lx@tag[][ ]{\lx@fnum@@{' . $type . '}} #1'));
    DefMacroI('\ext@' . $type, undef, $auxext);
    DefEnvironmentI($type, "[]",
      "<ltx:float xml:id='#id' ?#1(placement='#1') inlist='#inlist' class='ltx_float_$type'>"
        . "#tags"
        . "#body"
        . "</ltx:float>",
      properties     => { layout => 'vertical' },
      beforeDigest   => sub { beforeFloat($type); },
      afterDigest    => sub { afterFloat($_[1]); },
      afterConstruct => sub { addFloatFrames($_[0], $style); });
    DefEnvironmentI("$type*", "[]",
      "<ltx:float xml:id='#id' ?#1(placement='#1') inlist='#inlist' class='ltx_float_$type'>"
        . "#tags"
        . "#body"
        . "</ltx:float>",
      properties     => { layout => 'vertical' },
      beforeDigest   => sub { beforeFloat($type, double => 1); },
      afterDigest    => sub { afterFloat($_[1]); },
      afterConstruct => sub { addFloatFrames($_[0], $style); });
});
## ??? DefMacro('\plain','');

sub addFloatFrames {
  my ($document, $style) = @_;
  my $float = $document->getNode->lastChild;
  if (my $outer = $style && $float_outerframe{$style}) {
    $document->setAttribute($float, framed => $outer); }
  if (my $inner = $style && $float_innerframe{$style}) {
    my ($body) = grep { $document->getNodeQName($_) !~ /^ltx:(?:toc)?caption$/ } $float->childNodes;
    if ($body) {
      $document->setAttribute($body, framed => $inner); } }
  return; }

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1;