File: dcolumn.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 (65 lines) | stat: -rw-r--r-- 2,758 bytes parent folder | download | duplicates (4)
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
# -*- mode: Perl -*-
# /=====================================================================\ #
# |  dcolumn                                                            | #
# | 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;

RequirePackage('array');

sub absorbedString {
  my ($tokens) = @_;
  my $capdocument = LaTeXML::Core::Document->new($STATE->getModel);
  my $capture = $capdocument->openElement('ltx:_Capture_', font => LaTeXML::Common::Font->new());
  $capdocument->absorb(Digest($tokens));
  if (my @nodes = $capdocument->findnodes("//ltx:XMath/*", $capture)) {
    return $nodes[0]->textContent; }
  else {
    return $capture->textContent; } }    # ???

DefMacro('\lx@unactivate DefToken', sub {
    my ($gullet, $delim) = @_;
    $STATE->assignMathcode(ToString($delim) => undef); });

DefMacro('\DC@{}{}{}', sub {
    my ($gullet, $delim, $todelim, $ndec) = @_;
    $delim = ToString($delim);
    if ($delim ne ToString($todelim)) {
      $STATE->assignMathcode($delim => 0x8000);
      DefMacroI(T_CS($delim), undef, '\@hidden@bgroup\lx@unactivate{' . $delim . '}\lx@wrap[role=PERIOD]{' . UnTeX($todelim) . '}\@hidden@egroup');
    }
    # We need to temporarily deactivate '$'
    Let(T_CS('\DC@saved@dollar'), T_MATH);
    Let(T_MATH,                   T_CS('\relax'));
    return Tokens(LookupValue('IN_MATH') ? () : T_CS('\@@BEGININLINEMATH'));
});
# NOTE: We should be making arrangements for this funny thing to still
# be considered a number!

DefMacro('\DC@end', sub {
    Let(T_MATH, T_CS('\DC@saved@dollar'));
    return (T_CS('\@@ENDINLINEMATH'));
});

DefColumnType('D{}{}{}', sub {
    my ($gullet, $delim, $todelim, $ndec) = @_;
    my $alignment = absorbedString(Tokens(T_CS('\ensuremath'), T_BEGIN, $todelim, T_END));
    $LaTeXML::BUILD_TEMPLATE->addColumn(before => Tokens(T_CS('\DC@'),
        T_BEGIN, $delim->unlist,   T_END,
        T_BEGIN, $todelim->unlist, T_END,
        T_BEGIN, $ndec->unlist,    T_END),
      align => 'char:' . $alignment,
      after => Tokens(T_CS('\DC@end')));
    return; });

1;