1# -*- mode: Perl -*-
2# /=====================================================================\ #
3# |  floatflt                                                           | #
4# | Implementation for LaTeXML                                          | #
5# |=====================================================================| #
6# | Part of LaTeXML:                                                    | #
7# |  Public domain software, produced as part of work done by the       | #
8# |  United States Government & not subject to copyright in the US.     | #
9# |---------------------------------------------------------------------| #
10# | Thanks to the arXMLiv group for initial implementation              | #
11# |    http://arxmliv.kwarc.info/                                       | #
12# | Released to the Public Domain                                       | #
13# |---------------------------------------------------------------------| #
14# | Bruce Miller <bruce.miller@nist.gov>                        #_#     | #
15# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
16# \=========================================================ooo==U==ooo=/ #
17package LaTeXML::Package::Pool;
18use strict;
19use warnings;
20use LaTeXML::Package;
21
22#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23# \begin{floatingfigure}[pos]{width} ... \end{figure}
24# pos = rflt to the right, lflt to the left, v to the outer edge, p to the inner
25# Since we know nothing about pages, we'll treat v=r, p=l...
26
27AssignValue(floatfltpos => 'v');
28DeclareOption('rflt', sub { AssignValue(floatfltpos => 'r'); });
29DeclareOption('lflt', sub { AssignValue(floatfltpos => 'l'); });
30DeclareOption('pflt', sub { AssignValue(floatfltpos => 'p'); });
31DeclareOption('vflt', sub { AssignValue(floatfltpos => 'v'); });
32
33DefEnvironment('{floatingfigure}[]{Dimension}',
34  "<ltx:figure xml:id='#id' inlist='#inlist' float='#float' width='#pctwidth'>"
35    . "#tags"
36    . "#body"
37    . "</ltx:figure>",
38  beforeDigest => sub { DefMacroI('\@captype', undef, 'figure'); },
39  afterDigest => sub { RescueCaptionCounters('figure', $_[1]); },
40  properties => sub {
41    (float => (ToString($_[1] || LookupValue('floatfltpos')) =~ /^(v|r)/ ? 'right' : 'left'),
42      pctwidth => toPercent($_[2])); });
43
44DefEnvironment('{floatingtable}[]{Dimension}',
45  "<ltx:table xml:id='#id' inlist='#inlist' float='#float' width='#pctwidth'>"
46    . "#tags"
47    . "#body"
48    . "</ltx:table>",
49  beforeDigest => sub { DefMacroI('\@captype', undef, 'table'); },
50  afterDigest => sub { RescueCaptionCounters('table', $_[1]); },
51  properties => sub {
52    (float => (ToString($_[1] || LookupValue('floatfltpos')) =~ /^(v|r)/ ? 'right' : 'left'),
53      pctwidth => toPercent($_[2])); });
54
55sub toPercent {
56  my ($dimen) = @_;
57  return int(100 * $dimen->valueOf / LookupValue('\textwidth')->valueOf) . '%'; }
58
59DefMacro('\fltitem[]{}',    '\item {#2}');
60DefMacro('\fltditem[]{}{}', '\item[#2] {#3}');
61
62DefMacro('\initfloatingfigs', '');    # ?????
63#======================================================================
64DefMacro('\dofigtest', '');
65DefMacro('\dotabtest', '');
66DefMacro('\tryfig',    '');
67DefMacro('\trytab',    '');
68DefMacro('\figinsert', '');
69DefMacro('\tabinsert', '');
70DefMacro('\dohang',    '');
71DefMacro('\dohangt',   '');
72
73DefRegister('\figbox'  => Box());
74DefRegister('\tabbox'  => Box());
75DefRegister('\pagebox' => Box());
76
77DefRegister('\ffigcount' => Number(0));
78DefRegister('\ftabcount' => Number(0));
79DefRegister('\fftest'    => Number(0));
80DefRegister('\hangcount' => Number(0));
81
82DefRegister('\nosuccesstryfig' => Number(0));
83DefRegister('\nosuccesstrytab' => Number(0));
84
85DefRegister('\figgutter' => Dimension('1pc'));
86DefRegister('\tabgutter' => Dimension('1pc'));
87
88DefRegister('\htdone'      => Number(0));
89DefRegister('\pageht'      => Dimension('0pt'));
90DefRegister('\startpageht' => Dimension('0pt'));
91
92DefRegister('\tabbredd'      => Dimension('0pt'));
93DefRegister('\floatfltwidth' => Dimension('0pt'));
94DefRegister('\fltitemwidth'  => Dimension('0pt'));
95DefRegister('\outputpretest' => Tokens());
96
97RawTeX(<<'EoTeX');
98\newif\iftryingfig     \tryingfigfalse
99\newif\iftryingtab     \tryingtabfalse
100\newif\ifdoingfig      \doingfigfalse
101\newif\ifdoingtab      \doingtabfalse
102\newif\iffigprocessing \figprocessingfalse
103\newif\iftabprocessing \tabprocessingfalse
104\newif\ifpageafterfig  \pageafterfigfalse
105\newif\ifpageaftertab  \pageaftertabfalse
106\newif\ifoddpages
107\newif\ifoutput
108EoTeX
109#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1101;
111