Skip to content

Commit

Permalink
Merge pull request #354 from Blueprints-org/353-feature-request-add-u…
Browse files Browse the repository at this point in the history
…nits-to-complete-latex-formula

#353 Add unit to Latex formula
  • Loading branch information
egarciamendez authored Oct 16, 2024
2 parents 12e26b6 + d93eeb4 commit f6c97e7
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions blueprints/codes/latex_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@dataclass(frozen=True)
class LatexFormula:
"""Latex formula representation.
Depending on the context this could include the unit, the formula, the result, etc.
Attributes
Expand All @@ -28,6 +29,7 @@ class LatexFormula:
equation: str = ""
numeric_equation: str = ""
comparison_operator_label: str = "="
unit: str = ""

@property
def complete(self) -> str:
Expand All @@ -39,13 +41,9 @@ def complete(self) -> str:
Return symbol = equation = numeric_equation = result
"""
all_sub_equations = [
self.return_symbol,
self.equation,
self.numeric_equation,
self.result,
]
return f" {self.comparison_operator_label} ".join([eq for eq in all_sub_equations if eq != ""])
all_sub_equations = [self.return_symbol, self.equation, self.numeric_equation, f"{self.result}"]
long_formula = f" {self.comparison_operator_label} ".join([eq for eq in all_sub_equations if eq != ""])
return long_formula + f" {self.unit}" if self.unit else long_formula

@property
def short(self) -> str:
Expand All @@ -57,7 +55,8 @@ def short(self) -> str:
Return symbol = result
"""
return f"{self.return_symbol} {self.comparison_operator_label} {self.result}"
short_formula = f"{self.return_symbol} {self.comparison_operator_label} {self.result}"
return short_formula + f" {self.unit}" if self.unit else short_formula

def __str__(self) -> str:
"""String representation of the formula."""
Expand Down Expand Up @@ -89,7 +88,9 @@ def latex_fraction(numerator: str | float, denominator: str | float) -> str:


def latex_min_curly_brackets(*args: str | float) -> str:
r"""Return a string which will output: min{arg_1; arg_2; ...; arg_N} in latex and it will also automatically ensure floats are converted to latex
r"""Return a string which will output: min{arg_1; arg_2; ...; arg_N} in latex.
It will also automatically ensure floats are converted to latex
text.
Examples
Expand All @@ -112,7 +113,9 @@ def latex_min_curly_brackets(*args: str | float) -> str:


def latex_max_curly_brackets(*args: str | float) -> str:
r"""Return a string which will output: max{arg_1; arg_2; ...; arg_N} in latex and it will also automatically ensure floats are converted to latex
r"""Return a string which will output: max{arg_1; arg_2; ...; arg_N} in latex.
It will also automatically ensure floats are converted to latex
text.
Examples
Expand Down

0 comments on commit f6c97e7

Please sign in to comment.