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
|
# -*- mode: Perl -*-
# /=====================================================================\ #
# | subcaption.sty | #
# | 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;
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# TODO: Work out how caption/caption3 actually set the styling...
# pass options, and sub, to caption
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RequirePackage('caption');
NewCounter('subfigure', 'figure', idprefix => 'sf', idwithin => 'figure');
NewCounter('subtable', 'table', idprefix => 'st', idwithin => 'table');
DefMacro('\thesubfigure', '(\alph{subfigure})');
DefMacro('\thesubtable', '(\alph{subtable})');
Let('\p@subfigure', '\thefigure');
Let('\p@subtable', '\thetable');
Let('\ext@subfigure', '\ext@figure');
Let('\ext@subtable', '\ext@table');
DefMacro('\fnum@font@float', '\small');
DefMacro('\format@title@font@float', '\small');
DefMacro('\fnum@font@subfigure', '\fnum@font@figure');
DefMacro('\fnum@font@subtable', '\fnum@font@table');
DefMacro('\format@title@font@subfigure', '\format@title@font@figure');
DefMacro('\format@title@font@subtable', '\format@title@font@table');
#======================================================================
# TODO: This should appear within a minipage (suggested!) within some kind of float.
# So it should become a sub<float>, inheriting whatever style from outer float;
# But, ltx:caption will float up outside the minipage (not allowed there)!
# Probably should convert the minipage to a float, or wrap it, if we could?
DefMacro('\subcaption OptionalMatch:* []{}', sub {
my ($gullet, $star, $opt, $caption) = @_;
# TODO: this is a temporary kludge to avoid sub-sub mistakes.
if (IsDefined('\@captype')) {
my $ctype = ToString(Expand(T_CS('\@captype')));
if ($ctype && $ctype !~ /^sub/) { # avoid subsubfigure, etc.
DefMacro('\@captype', "sub$ctype", scope => 'local'); } }
return (T_CS('\caption'),
$opt ? (T_OTHER('['), $opt, T_OTHER(']')) : (), T_BEGIN, $caption, T_END);
});
#======================================================================
# Let these float, since subfigures tend to get wrapped with weird positioning.
DefEnvironment('{subfigure}[]{Dimension}',
"^<ltx:figure xml:id='#id' inlist='#inlist' ?#1(placement='#1')>"
. "#tags"
. "#body"
. "</ltx:figure>",
properties => sub { (layout => 'vertical', width => $_[2]); },
beforeDigest => sub { beforeFloat('subfigure', preincrement => 'figure'); },
afterDigest => sub { afterFloat($_[1]); });
DefEnvironment('{subfigure*}[]{Dimension}',
"^<ltx:figure xml:id='#id' inlist='#inlist' ?#1(placement='#1')>"
. "#tags"
. "#body"
. "</ltx:figure>",
properties => sub { (layout => 'vertical', width => $_[2]); },
beforeDigest => sub { beforeFloat('subfigure', double => 1, preincrement => 'figure'); },
afterDigest => sub { afterFloat($_[1]); });
DefEnvironment('{subtable}[]{Dimension}',
"^<ltx:table xml:id='#id' inlist='#inlist' ?#1(placement='#1')>"
. "#tags"
. "#body"
. "</ltx:table>",
properties => sub { (layout => 'vertical', width => $_[2]); },
beforeDigest => sub { beforeFloat('subtable', preincrement => 'table'); },
afterDigest => sub { afterFloat($_[1]); });
DefEnvironment('{subtable*}[]{Dimension}',
"^<ltx:table xml:id='#id' inlist='#inlist' ?#1(placement='#1')>"
. "#tags"
. "#body"
. "</ltx:table>",
properties => sub { (layout => 'vertical', width => $_[2]); },
beforeDigest => sub { beforeFloat('subtable', double => 1, preincrement => 'table'); },
afterDigest => sub { afterFloat($_[1]); });
#======================================================================
# Can we get by by saying \subfloat is just an alias for {subfigure} ?
# see 2111.00007 for example.
# TODO: \columnwidth is a quick placeholder width, this seems to be intended as automatic
DefMacro('\subfloat[][]{}', '\begin{subfigure}{\columnwidth}#3\caption{#2}\lx@subcaption@addinlist{#1}\end{subfigure}');
#======================================================================
# \subcaptionbox[list]{caption}[width][innerpos]{contents}
DefMacro('\subcaptionbox', '\expandafter\@@subcaptionbox\expandafter{\@captype}');
DefMacro('\@@subcaptionbox{} []{} Optional:0pt []{}',
'\begingroup\csname sub#1\endcsname{#4}'
. '#6'
. '\caption{#3}'
. '\ifx.#2.\else\lx@subcaption@addinlist{#2}\fi'
. '\csname endsub#1\endcsname\endgroup');
DefConstructor('\lx@subcaption@addinlist{}',
"^ inlist='#1'");
DefMacro('\subref OptionalMatch:* Semiverbatim', '\ref{#2}');
#======================================================================
# should be in caption? or caption3 ?
DefMacro('\DeclareCaptionSubType OptionalMatch:* [] {}', '');
#======================================================================
1;
|