Skip to content

Commit

Permalink
Fix latexer else branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Mar 15, 2024
1 parent da5d0ec commit d07f144
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"pylint",
"pytest",
"resultwizard",
"scriptsize",
"scriptstyle",
"sigfigs",
"siunitx",
Expand Down
10 changes: 4 additions & 6 deletions src/application/latexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def result_to_latex_cmd(self, result: _Result) -> str:
builder = LatexIfElseBuilder()

cmd_name = f"{self.config.identifier}{_Helpers.capitalize(result.name)}"
latex_str = rf"\newcommand*{{\{cmd_name}}}[1][]{{"
latex_str += "\n"
latex_str = rf"\newcommand*{{\{cmd_name}}}[1][]{{" + "\n"

# Default case (full result) & value
builder.add_branch("", self.result_to_latex_str(result))
Expand Down Expand Up @@ -70,8 +69,6 @@ def result_to_latex_cmd(self, result: _Result) -> str:
if result.unit != "":
builder.add_branch("unit", rf"\unit{{{result.unit}}}")

latex_str += builder.build()

# Error message
keywords = builder.keywords
if len(keywords) > 0:
Expand All @@ -80,10 +77,11 @@ def result_to_latex_cmd(self, result: _Result) -> str:
error_message += " or don't use any keyword at all."
else:
error_message = "This variable can only be used without keywords."
latex_str += "\n"
latex_str += rf" }}{{\scriptstyle{{\textbf{{{error_message}}}}}}}"
builder.add_else(rf"\scriptsize{{\textbf{{{error_message}}}}}")

latex_str += builder.build()
latex_str += "\n}"

return latex_str

def result_to_latex_str(self, result: _Result) -> str:
Expand Down
6 changes: 6 additions & 0 deletions src/application/latexer_ifelse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def add_branch(self, keyword: str, body: str):
self.latex += "\n"
self.latex += rf" {body}"

def add_else(self, body: str):
self.latex += "\n"
self.latex += r" }{"
self.latex += rf"{body}"
self._num_parentheses_to_close += 1

def build(self) -> str:
for _ in range(self._num_parentheses_to_close):
self.latex += "}"
Expand Down

0 comments on commit d07f144

Please sign in to comment.