Skip to content

Commit

Permalink
added logic for if statement (not done)
Browse files Browse the repository at this point in the history
  • Loading branch information
co1emi11er2 committed Dec 1, 2024
1 parent 01d615d commit 419f260
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/handcalcs_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ end
function clean_expr(expr, len, spa)
expr = expr[2:end-1] # remove the $ from end and beginning of string
expr = expr[end] == " " ? expr : expr * " " # add trailing space if there isn't one
pattern = r"\\begin\{cases\}(.*?)\\end\{cases\}"s # if format pattern
m = match(pattern, expr)
if !isnothing(m) # expr is an if statement, do something different
expr = split(expr, "=") |> unique |> x -> join(x, "=")[1:end-1] # removes any redundant parts, and removes space at the end
expr = replace(expr, "="=>"&=", count=1) # add alignment
expr = len == :long ? replace(expr, " ="=>"\n\\\\[$spa" *"pt]\n&=", count=2) : expr
return expr
end
# TODO the line below breaks if statements in edge cases
expr = split(expr, "=") |> unique |> x -> join(x, "=")[1:end-1] # removes any redundant parts, and removes space at the end
expr = replace(expr, "="=>"&=", count=1) # add alignment
expr = len == :long ? replace(expr, " ="=>"\n\\\\[$spa" *"pt]\n&=", count=2) : expr
Expand Down

0 comments on commit 419f260

Please sign in to comment.