File: algorithmic.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 (73 lines) | stat: -rw-r--r-- 3,508 bytes parent folder | download | duplicates (3)
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
# -*- mode: Perl -*-
# /=====================================================================\ #
# |  algorithmic                                                        | #
# | 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;

# Was algorithmicx.sty loaded? If so: BAIL immediately.
# (deeply incompatible)
if (IsDefined(T_CS('\algorithmic'))) {
  Warn("unexpected", "\\algorithmic",
    "Another package has already defined \\algorithmic, will not load algorithmic.sty");
  return 1; }

# Read in the LaTeX definitions and redefine a few things strategically.
InputDefinitions('algorithmic', type => 'sty', noltxml => 1);

Let('\lx@orig@algorithmic', '\algorithmic');
DefMacro('\algorithmic', '\lx@setup@algorithmic\lx@orig@algorithmic');
DefPrimitive('\lx@setup@algorithmic', sub {
    ResetCounter('ALC@line');
    # If we are not within an algorithm environment, step the counter for its id's
    if (!grep { $_ eq 'algorithm'; } $STATE->lookupStackedValues('current_environment')) {
      RefStepID('algorithm'); }
    Let('\list',    '\lx@algorithmic@beginlist');
    Let('\endlist', '\lx@algorithmic@endlist');
    Let('\item',    '\lx@algorithmic@item');
    Let('\hfill',   '\lx@algorithmic@hfill');
});

DefConstructor('\lx@algorithmic@beginlist{}{}', "<ltx:listing>",
  beforeConstruct => sub { $_[0]->maybeCloseElement('ltx:p'); },
  afterDigest     => sub { Let('\list', '\lx@algorithmic@beginlist@inner'); });    # NOT nested list!

DefConstructor('\lx@algorithmic@endlist', "</ltx:listing>",
  beforeConstruct => sub { $_[0]->maybeCloseElement('ltx:listingline'); });

DefConstructor('\lx@algorithmic@beginlist@inner{}{}', "",
  afterDigest => sub { Let('\endlist', '\relax'); });                              # NOT nested list!

DefMacro('\lx@algorithmic@item OptionalUndigested',
  '\lx@algorithmic@item@@ [#1]\hskip\ALC@tlm\relax');

# This imitates \item; just opens the ltx:listingline, but somebody's got to close it.
DefConstructor('\lx@algorithmic@item@@ OptionalUndigested',
  "<ltx:listingline xml:id='#id' itemsep='#itemsep'>"
    . "#tags",
  properties => sub {
    my $id   = Digest(T_CS('\theALC@line@ID'));
    my $tags = Digest(Invocation(T_CS('\lx@make@tags'), T_OTHER('ALC@line')));
    (id => $id, tags => $tags); },
  beforeConstruct => sub { $_[0]->maybeCloseElement('ltx:listingline'); });

NewCounter('algorithm', undef,       idprefix => 'alg');
NewCounter('ALC@line',  'algorithm', idprefix => 'l');     # Assuming we're inside an {algorithm}!
DefMacro('\fnum@ALC@line', '\ALC@lno');

# Hopefully this will only get used for right justifying a comment;
# the ltx:text should autoclose at end of line?
DefConstructor('\lx@algorithmic@hfill',
  "<ltx:text cssstyle='float:right'>");
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1;