File: makecell.sty.ltxml

package info (click to toggle)
latexml 0.8.8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,920 kB
  • sloc: xml: 109,048; perl: 30,224; sh: 179; javascript: 28; makefile: 13
file content (92 lines) | stat: -rw-r--r-- 4,451 bytes parent folder | download | duplicates (2)
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
# -*- 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>                        #_#     | #
# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
# \=========================================================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='&pxValue(#width)' height='&pxValue(#height)'>"
    . "<ltx:line points='#line' stroke='#color' stroke-width='0.4'/>"
    . "<ltx:g transform='translate(#Ax,#Ay)' innerwidth='#Aw' innerheight='#Ah' innerdepth='#Ad'>"
    . "<ltx:inline-block>#A</ltx:inline-block>"
    . "</ltx:g>"
    . "<ltx:g transform='translate(#Bx,#By)' innerwidth='#Bw' innerheight='#Bh' innerdepth='#Bd'>"
    . "<ltx:inline-block>#B</ltx:inline-block>"
    . "</ltx:g>"
    . "</ltx:picture>",
  reversion      => '\diaghead(#1,#2){#3}{#4}{#5}',
  afterConstruct => sub { $_[0]->addClass($_[0]->getNode, 'ltx_nopad'); },
  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) = map { $_->pxValue } $A->getSize; $Ah += $Ad;
    my ($Bw, $Bh, $Bd) = map { $_->pxValue } $B->getSize; $Bh += $Bd;
    my $w     = $space->getWidth->pxValue;    # + tabcolsep
    my $h     = $w * abs($diagV / $diagH);
    my $line  = ($flip ? "0,$h $w,0" : "0,0, $w,$h");
    my $Ax    = ($flip ? 0           : $w - $Aw);
    my $Ay    = 0;
    my $Bx    = ($flip ? $w - $Bw : 0);
    my $By    = $h - $Bh;
    my $pxppt = Dimension('1pt')->pxValue(10);
    $whatsit->setProperties(
      width => Dimension($w / $pxppt . 'pt'), height => Dimension($h / $pxppt . 'pt'),
      A     => $A,    Ax    => $Ax, Ay => $Ay, Aw => $Aw, Ah => $Ah,
      B     => $B,    Bx    => $Bx, By => $By, Bw => $Bw, Bh => $Bh,
      line  => $line, color => Black); }
);
#======================================================================
1;