| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# /=====================================================================\ # |
|
2
|
|
|
|
|
|
|
# | LaTeXML::Util::Radix | # |
|
3
|
|
|
|
|
|
|
# | PostProcessing driver | # |
|
4
|
|
|
|
|
|
|
# |=====================================================================| # |
|
5
|
|
|
|
|
|
|
# | Part of LaTeXML: | # |
|
6
|
|
|
|
|
|
|
# | Public domain software, produced as part of work done by the | # |
|
7
|
|
|
|
|
|
|
# | United States Government & not subject to copyright in the US. | # |
|
8
|
|
|
|
|
|
|
# |---------------------------------------------------------------------| # |
|
9
|
|
|
|
|
|
|
# | Bruce Miller #_# | # |
|
10
|
|
|
|
|
|
|
# | http://dlmf.nist.gov/LaTeXML/ (o o) | # |
|
11
|
|
|
|
|
|
|
# \=========================================================ooo==U==ooo=/ # |
|
12
|
|
|
|
|
|
|
package LaTeXML::Util::Radix; |
|
13
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
20
|
|
|
14
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
19
|
|
|
15
|
1
|
|
|
1
|
|
9
|
use base qw(Exporter); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
484
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT = (qw( &radix_format |
|
17
|
|
|
|
|
|
|
&radix_alpha &radix_Alpha &radix_greek &radix_Greek |
|
18
|
|
|
|
|
|
|
&radix_roman &radix_Roman)); |
|
19
|
|
|
|
|
|
|
#====================================================================== |
|
20
|
|
|
|
|
|
|
# This isn't really any sort of general purpose Radix module, |
|
21
|
|
|
|
|
|
|
# probably the term "radix" is a misnomer here! |
|
22
|
|
|
|
|
|
|
# It is used to primarily generate labels, or uniquifying suffixes to make ID's, |
|
23
|
|
|
|
|
|
|
# Bibtex year tags like 2013a, etc using alphabetic letters, or |
|
24
|
|
|
|
|
|
|
# perhaps greek, or even from a set of symbols. |
|
25
|
|
|
|
|
|
|
# |
|
26
|
|
|
|
|
|
|
# The general idea is simply to generate labels in the sequence: |
|
27
|
|
|
|
|
|
|
# a,b,c,...y,z,aa,ab,ac,...az,ba,...zy,zz,aaa,aab,.... and so on. |
|
28
|
|
|
|
|
|
|
# I would assume that the usual advise is that it is bad style to pass, |
|
29
|
|
|
|
|
|
|
# or even approach "z"; However, this is an automaton, and things happen. |
|
30
|
|
|
|
|
|
|
#====================================================================== |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub radix_format { |
|
33
|
0
|
|
|
0
|
0
|
|
my ($number, @symbols) = @_; |
|
34
|
0
|
|
|
|
|
|
my $string = ''; |
|
35
|
0
|
|
|
|
|
|
my $max = scalar(@symbols); |
|
36
|
0
|
|
|
|
|
|
while ($number > 0) { |
|
37
|
0
|
|
|
|
|
|
$string = $symbols[($number - 1) % $max] . $string; |
|
38
|
0
|
|
|
|
|
|
$number = int(($number - 1) / $max); } |
|
39
|
0
|
|
|
|
|
|
return $string; } |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my @letters = (qw(a b c d e f g h i j k l m n o p q r s t u v w x y z)); |
|
42
|
|
|
|
|
|
|
my @Letters = (qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)); |
|
43
|
|
|
|
|
|
|
my @greek = ("\x{03B1}", "\x{03B2}", "\x{03B3}", |
|
44
|
|
|
|
|
|
|
"\x{03B4}", "\x{03B5}", "\x{03B6}", "\x{03B7}", |
|
45
|
|
|
|
|
|
|
"\x{03B8}", "\x{03B9}", "\x{03BA}", "\x{03BB}", |
|
46
|
|
|
|
|
|
|
"\x{03BC}", "\x{03BD}", "\x{03BE}", "\x{03BF}", |
|
47
|
|
|
|
|
|
|
"\x{03C0}", "\x{03C1}", "\x{03C3}", |
|
48
|
|
|
|
|
|
|
"\x{03C4}", "\x{03C5}", "\x{03C6}", "\x{03C7}", |
|
49
|
|
|
|
|
|
|
"\x{03C8}", "\x{03C9}"); |
|
50
|
|
|
|
|
|
|
my @Greek = ("\x{0391}", "\x{0392}", "\x{0393}", |
|
51
|
|
|
|
|
|
|
"\x{0394}", "\x{0395}", "\x{0396}", "\x{0397}", |
|
52
|
|
|
|
|
|
|
"\x{0398}", "\x{0399}", "\x{039A}", "\x{039B}", |
|
53
|
|
|
|
|
|
|
"\x{039C}", "\x{039D}", "\x{039E}", "\x{039F}", |
|
54
|
|
|
|
|
|
|
"\x{03A0}", "\x{03A1}", "\x{03A3}", |
|
55
|
|
|
|
|
|
|
"\x{03A4}", "\x{03A5}", "\x{03A6}", "\x{03A7}", |
|
56
|
|
|
|
|
|
|
"\x{03A8}", "\x{03A9}"); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub radix_alpha { |
|
59
|
0
|
|
|
0
|
0
|
|
my ($n) = @_; |
|
60
|
0
|
|
|
|
|
|
return radix_format($n, @letters); } |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub radix_Alpha { |
|
63
|
0
|
|
|
0
|
0
|
|
my ($n) = @_; |
|
64
|
0
|
|
|
|
|
|
return radix_format($n, @Letters); } |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub radix_greek { |
|
67
|
0
|
|
|
0
|
0
|
|
my ($n) = @_; |
|
68
|
0
|
|
|
|
|
|
return radix_format($n, @greek); } |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub radix_Greek { |
|
71
|
0
|
|
|
0
|
0
|
|
my ($n) = @_; |
|
72
|
0
|
|
|
|
|
|
return radix_format($n, @Greek); } |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Dumb place for this, but where else... |
|
75
|
|
|
|
|
|
|
# Note: This is one "The TeX Way"! (bah!! hint: try a large number) |
|
76
|
|
|
|
|
|
|
# namely, it's very limited.... what happened to my much-improved version? |
|
77
|
|
|
|
|
|
|
my @rmletters = ('i', 'v', 'x', 'l', 'c', 'd', 'm'); # [CONSTANT] |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub radix_roman { |
|
80
|
0
|
|
|
0
|
0
|
|
my ($n) = @_; |
|
81
|
0
|
|
|
|
|
|
my $div = 1000; |
|
82
|
0
|
0
|
|
|
|
|
my $s = ($n > $div ? ('m' x int($n / $div)) : ''); |
|
83
|
0
|
|
|
|
|
|
my $p = 4; |
|
84
|
0
|
|
|
|
|
|
while ($n %= $div) { |
|
85
|
0
|
|
|
|
|
|
$div /= 10; |
|
86
|
0
|
|
|
|
|
|
my $d = int($n / $div); |
|
87
|
0
|
0
|
|
|
|
|
if ($d % 5 == 4) { $s .= $rmletters[$p]; $d++; } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if ($d > 4) { $s .= $rmletters[$p + int($d / 5)]; $d %= 5; } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if ($d) { $s .= $rmletters[$p] x $d; } |
|
|
0
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$p -= 2; } |
|
91
|
0
|
|
|
|
|
|
return $s; } |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Convert the number to lower case roman numerals, returning a list of LaTeXML::Core::Token |
|
94
|
|
|
|
|
|
|
sub radix_Roman { |
|
95
|
0
|
|
|
0
|
0
|
|
my ($n) = @_; |
|
96
|
0
|
|
|
|
|
|
return uc(radix_roman($n)); } |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#====================================================================== |
|
99
|
|
|
|
|
|
|
1; |