From da1010f84bf6d224cca629d8d44072f144e3bf7e Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Tue, 13 Nov 2018 20:13:35 +0000
Subject: [PATCH] In formatting, space is always added after numerical values.
---
aoi_gen/Variable.py | 62 ++++++++++++++++++-------------
1 files changed, 36 insertions(+), 26 deletions(-)
diff --git a/aoi_gen/Variable.py b/aoi_gen/Variable.py
index 8b5c7f7..1196f2b 100644
--- a/aoi_gen/Variable.py
+++ b/aoi_gen/Variable.py
@@ -31,28 +31,37 @@
formatter = FormatterFactory.get_formatter(formatting)
self.formatted_value = formatter.getValue(self.value)
- def format_as_tex(self, formatting=None, glyph=None, unit=None):
+ def format_as_tex(self, formatting=None, glyph=None, unit=None, dollar="$"):
if formatting is None:
formatting = self.formatting
formatter = FormatterFactory.get_formatter(formatting)
+ if formatting.split()[0] == "prefix":
+ leading_space = ""
+ else:
+ leading_space = "~"
if formatting == "str" or formatting == "string":
return formatter.toFormat(self.value)
elif glyph is None and unit is None:
- return ("${}$").format(formatter.toFormat(self.value))
- elif glyph is None and unit is not None:
- return ("${}~\mathrm{{{}}}$").format(formatter.toFormat(self.value), unit)
- elif glyph is not None and unit is None:
- return ("${}={}$").format(glyph, formatter.toFormat(self.value))
- else:
- return ("${}={}~\mathrm{{{}}}$").format(
- glyph, formatter.toFormat(self.value), unit
+ return ("{}{}{}{}").format(
+ dollar, formatter.toFormat(self.value), leading_space, dollar
)
-
- def format_without_dollar(self, formatting=None):
- if formatting is None:
- formatting = self.formatting
- formatter = FormatterFactory.get_formatter(formatting)
- return formatter.toFormat(self.value)
+ elif glyph is None and unit is not None:
+ return ("{}{}{}\mathrm{{{}}}{}{}").format(
+ dollar, formatter.toFormat(self.value), leading_space, unit, dollar
+ )
+ elif glyph is not None and unit is None:
+ return ("{}{}={}{}{}").format(
+ dollar, glyph, formatter.toFormat(self.value), leading_space, dollar
+ )
+ else:
+ return ("{}{}={}{}\mathrm{{{}}}{}").format(
+ dollar,
+ glyph,
+ formatter.toFormat(self.value),
+ leading_space,
+ unit,
+ dollar,
+ )
def get_formatted_value(self):
return self.formatted_value
@@ -81,7 +90,7 @@
elif type == "prefix":
return PrefixFloatFormatter(arglist)
elif type == "dec" or type == "decimal":
- return EngFloatFormatter(arglist) #fallback to engineering
+ return EngFloatFormatter(arglist) # fallback to engineering
else:
return None
@@ -197,20 +206,21 @@
"6": "M",
"3": "k",
"-3": "m",
- "-6":"\\upmu",
- "-9":"n",
- "-12":"p",
- "-15":"f",
- "-18":"a",
- "-21":"z",
- "-24":"y"
+ "-6": "\\upmu",
+ "-9": "n",
+ "-12": "p",
+ "-15": "f",
+ "-18": "a",
+ "-21": "z",
+ "-24": "y",
}
try:
prefix = prefixes[str(exp)]
except KeyError:
- raise Exceptions.PrefixError("Could not change exponent " + str(exp) + " into prefix form!")
+ raise Exceptions.PrefixError(
+ "Could not change exponent " + str(exp) + " into prefix form!"
+ )
return prefix
-
def toFormat(self, num):
try:
@@ -225,7 +235,7 @@
(exp, man) = self.realign3(exp, man)
if exp == 0:
return (
- ("{:." + str(self.precision - 1) + "f}").format(man).replace(".", ",\!")
+ ("{:." + str(self.precision - 1) + "f}~").format(man).replace(".", ",\!")
)
else:
prefix = self.exp2prefix(exp)
--
Gitblit v1.8.0