# -*- mode: Perl -*-
# /=====================================================================\ #
# | makecell | #
# | 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> #_# | #
# \=========================================================ooo==U==ooo=/ #
package LaTeXML::Package::Pool;
use strict;
use warnings;
use LaTeXML::Package;
InputDefinitions('makecell', type => 'sty', noltxml => 1);
# * The diagonally divided heading uses the {picture} environment,
# but currently the sizing is messed up (delayed too late) so that doesn't lay out correctly.
# Mark \thead et.al as headers (row, column?)
DefMacroI('\lx@makecell@head', undef, sub {
if (my $alignment = LookupValue('Alignment')) {
my $col = $alignment->currentColumn;
$$col{thead}{column} = 1; # Which???
$$col{thead}{row} = 1; }
return; });
# Hopefully, \theadfont is used in the right places to effect this?
# And hopefully, redefining \theadfont at begin document keeps from being redefined by user?
AtBeginDocument('\let\lx@orig@theadfont\theadfont'
. '\def\theadfont{\lx@orig@theadfont\lx@makecell@head}');
# And since folks SHOULD use \thead, we'll not bother guessing.
AssignValue(GUESS_TABULAR_HEADERS => 0);
# \diaghead (slopex,slopey) {width}{item A}{item B}
# Note that A is generally the lower item
# This macro arranges to wrap the args in a table,
# with appropriate alignment based on slope.
DefMacro('\diaghead OptionalPair {}{}{}', sub {
my ($gullet, $diag, $space, $A, $B) = @_;
my ($diagH, $diagV) = ($diag ? ($diag->getX->valueOf, $diag->getY->valueOf) : (5.0, -2.0));
my $flip = ($diagH < 0) ^ ($diagV < 0);
my ($Ap, $Bp) = ($flip ? ('l', 'r') : ('r', 'l'));
return Invocation(T_CS('\lx@diagheads'),
$diagH, $diagV, $space,
Invocation(T_CS('\lx@diag@head'), T_LETTER($Ap), $A),
Invocation(T_CS('\lx@diag@head'), T_LETTER($Bp), $B)); });
# Ideally, we'd arrange a constructor whose reversion is simply #2
DefMacro('\lx@diag@head{}{}',
# '{\theadfont\begin{tabular}{#1}#2\end{tabular}}');
'{\theadfont\shortstack[#1]{#2}}');
DefConstructor('\lx@diagheads {}{} {}{}{}',
"<ltx:picture width='#width' height='#height' unitlength='1.0pt'>"
. "<ltx:line points='#line' stroke='black' stroke-width='0.4'/>"
. "<ltx:g transform='translate(#Ax,#Ay)' innerwidth='#Aw' innerheight='#Ah'>"
. "<ltx:inline-block>#A</ltx:inline-block>"
. "</ltx:g>"
. "<ltx:g transform='translate(#Bx,#By)' innerwidth='#Bw' innerheight='#Bh'>"
. "<ltx:inline-block>#B</ltx:inline-block>"
. "</ltx:g>"
. "</ltx:picture>",
reversion => '\diaghead(#1,#2){#3}{#4}{#5}',
afterDigest => sub {
my ($stomach, $whatsit) = @_;
my ($diagH, $diagV, $space, $A, $B) = $whatsit->getArgs;
$diagH = ToString($diagH) || 1;
$diagV = ToString($diagV) || 1;
my $flip = ($diagH < 0) ^ ($diagV < 0);
my ($Aw, $Ah, $Ad) = $A->getSize; $Ah = $Ah->add($Ad);
my ($Bw, $Bh, $Bd) = $B->getSize; $Bh = $Bh->add($Bd);
my $w = $space->getWidth; # + tabcolsep
my $h = $w->multiply(Float(abs($diagV / $diagH)));
my ($ww, $hh) = ($w->ptValue, $h->ptValue);
my $line = ($flip ? "0,$hh $ww,0" : "0,0, $ww,$hh");
my $Ax = ($flip ? 0 : $w->subtract($Aw)->ptValue);
my $Ay = $Ah->ptValue;
my $Bx = ($flip ? $w->subtract($Bw)->ptValue : 0);
my $By = $h->ptValue;
$whatsit->setProperties(width => $w, height => $h,
A => $A, Ax => $Ax, Ay => $Ay, Aw => $Aw, Ah => $Ah,
B => $B, Bx => $Bx, By => $By, Bw => $Bw, Bh => $Bh,
line => $line); }
);
#======================================================================
1;