Skip to content

Commit

Permalink
Use \num{} for latex values
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Mar 16, 2024
1 parent 0075a50 commit fcf0e44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/application/latex_stringifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ def result_to_latex_str_without_error(self, result: Result) -> str:
Returns the result without error as LaTeX string making use of the siunitx package.
"""
return self.create_str(result.value, [], result.unit)

def _modify_value(self, value: str) -> str:
return rf"\num{{{value}}}"
18 changes: 13 additions & 5 deletions src/application/stringifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def create_str(self, value: Value, uncertainties: List[Uncertainty], unit: str)
if should_use_parentheses:
latex_str += self.left_parenthesis
latex_str += sign
latex_str += Helpers.round_to_n_decimal_places(value_normalized, decimal_places)
value_str = Helpers.round_to_n_decimal_places(value_normalized, decimal_places)
latex_str += self._modify_value(value_str)

for u in uncertainties:
uncertainty_normalized = u.uncertainty.get_abs() * factor
Expand All @@ -78,18 +79,19 @@ def create_str(self, value: Value, uncertainties: List[Uncertainty], unit: str)
else u.uncertainty.get_decimal_place()
)
latex_str += self.plus_minus
latex_str += Helpers.round_to_n_decimal_places(uncertainty_normalized, decimal_places)
uncert_str = Helpers.round_to_n_decimal_places(uncertainty_normalized, decimal_places)
latex_str += self._modify_value(uncert_str)
if len(uncertainties) > 1:
latex_str += self.error_name_prefix + u.name + self.error_name_suffix
latex_str += f"{self.error_name_prefix}{u.name}{self.error_name_suffix}"

if should_use_parentheses:
latex_str += self.right_parenthesis
if use_scientific_notation:
latex_str += (
self.scientific_notation_prefix + str(exponent) + self.scientific_notation_suffix
f"{self.scientific_notation_prefix}{str(exponent)}{self.scientific_notation_suffix}"
)
if has_unit:
latex_str += self.unit_prefix + self._modify_unit(unit) + self.unit_suffix
latex_str += f"{self.unit_prefix}{self._modify_unit(unit)}{self.unit_suffix}"

return latex_str

Expand Down Expand Up @@ -120,3 +122,9 @@ def _modify_unit(self, unit: str) -> str:
Returns the modified unit.
"""
return unit

def _modify_value(self, value: str) -> str:
"""
Returns the modified value (as string).
"""
return value

0 comments on commit fcf0e44

Please sign in to comment.