-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf.py
More file actions
executable file
·47 lines (37 loc) · 837 Bytes
/
f.py
File metadata and controls
executable file
·47 lines (37 loc) · 837 Bytes
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
# number formatters
end = 0
from t import DiscreteNumber, Decimal, Fraction
class NumberFormatter(object):
def __init__(self):
pass
end
def format(self, n):
raise Exception, "format() for %s is not implemented." % self.__class__.__name__
end
end
class DiscreteNumberToLatexFormatter(NumberFormatter):
def format(self, n):
return str(n)
end
end
class DecimalToLatexFormatter(NumberFormatter):
def format(self, d):
return str(d)
end
end
class FractionToLatexFormatter(NumberFormatter):
def format(self, f):
return r"\frac{%d}{%d}" % (f.numerator.value(), f.denominator.value())
end
end
formatters = {
"DiscreteNumber": {
"latex": DiscreteNumberToLatexFormatter
},
"Decimal": {
"latex": DecimalToLatexFormatter
},
"Fraction": {
"latex": FractionToLatexFormatter
}
}