Skip to content

Commit

Permalink
add usecdot kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsas committed Mar 22, 2019
1 parent e63022a commit ff2167c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/latexoperation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This uses the information about the previous operations to decide if
a parenthesis is needed.
"""
function latexoperation(ex::Expr, prevOp::AbstractArray)
function latexoperation(ex::Expr, prevOp::AbstractArray; usecdot=true, kwargs...)
op = ex.args[1]
convertSubscript!(ex)
args = ex.args
Expand All @@ -20,7 +20,7 @@ function latexoperation(ex::Expr, prevOp::AbstractArray)
arg = args[i]
prevOp[i] in [:+, :-] && (arg = "\\left( $arg \\right)")
str = string(str, arg)
i != length(args) && (str *= " \\cdot ")
i != length(args) && (str *= usecdot ? " \\cdot " : " ")
end
return str

Expand Down Expand Up @@ -160,7 +160,7 @@ function latexoperation(ex::Expr, prevOp::AbstractArray)
return ""
end

latexoperation(sym::Symbol, prevOp::AbstractArray) = "$sym"
latexoperation(sym::Symbol, prevOp::AbstractArray; kwargs...) = "$sym"


function convertSubscript!(ex::Expr)
Expand Down
2 changes: 1 addition & 1 deletion src/latexraw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function latexraw(inputex::Expr; convert_unicode=true, kwargs...)
ex.args[i] = recurseexp!(ex.args[i])
end
end
return latexoperation(ex, prevOp)
return latexoperation(ex, prevOp; kwargs...)
end
ex = deepcopy(inputex)
str = recurseexp!(ex)
Expand Down
13 changes: 6 additions & 7 deletions src/plugins/DiffEqBiological.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ end


function chemical_arrows(rn::DiffEqBase.AbstractReactionNetwork;
expand = true, double_linebreak=false, mathjax=true, starred=false)

expand = true, double_linebreak=false, mathjax=true, starred=false, kwargs...)
str = starred ? "\\begin{align*}\n" : "\\begin{align}\n"
eol = double_linebreak ? "\\\\\\\\\n" : "\\\\\n"

Expand All @@ -71,7 +70,7 @@ function chemical_arrows(rn::DiffEqBase.AbstractReactionNetwork;
expand && (rate = DiffEqBiological.recursive_clean!(rate))

### Generate formatted string of substrates
substrates = [latexraw("$(substrate.stoichiometry== 1 ? "" : "$(substrate.stoichiometry) * ") $(substrate.reactant)") for substrate in r.substrates ]
substrates = [latexraw("$(substrate.stoichiometry== 1 ? "" : "$(substrate.stoichiometry) * ") $(substrate.reactant)"; kwargs...) for substrate in r.substrates ]
isempty(substrates) && (substrates = ["\\varnothing"])

str *= join(substrates, " + ")
Expand All @@ -83,17 +82,17 @@ function chemical_arrows(rn::DiffEqBase.AbstractReactionNetwork;
expand && (rate_backwards = DiffEqBiological.recursive_clean!(rate_backwards))
expand && (rate_backwards = DiffEqBiological.recursive_clean!(rate_backwards))
str *= " &<=>"
str *= "[" * latexraw(rate) * "]"
str *= "[" * latexraw(rate_backwards) * "] "
str *= "[" * latexraw(rate; kwargs...) * "]"
str *= "[" * latexraw(rate_backwards; kwargs...) * "] "
backwards_reaction = true
else
### Uni-directional arrows
str *= " &->"
str *= "[" * latexraw(rate) * "] "
str *= "[" * latexraw(rate; kwargs...) * "] "
end

### Generate formatted string of products
products = [latexraw("$(product.stoichiometry== 1 ? "" : "$(product.stoichiometry) * ") $(product.reactant)") for product in r.products ]
products = [latexraw("$(product.stoichiometry== 1 ? "" : "$(product.stoichiometry) * ") $(product.reactant)"; kwargs...) for product in r.products ]
isempty(products) && (products = ["\\varnothing"])
str *= join(products, " + ")
str *= "}$eol"
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/ParameterizedFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ end
# Overload environment functions #
###############################################

function latexraw(ode::DiffEqBase.AbstractParameterizedFunction)
function latexraw(ode::DiffEqBase.AbstractParameterizedFunction; kwargs...)
lhs = ["\\frac{d$x}{dt} = " for x in ode.syms]
rhs = latexraw(ode.funcs)
rhs = latexraw(ode.funcs; kwargs...)
return lhs .* rhs
end


function latexinline(ode::DiffEqBase.AbstractParameterizedFunction)
function latexinline(ode::DiffEqBase.AbstractParameterizedFunction; kwargs...)
lhs = ["\\frac{d$x}{dt} = " for x in ode.syms]
rhs = latexraw(ode.funcs)
rhs = latexraw(ode.funcs; kwargs...)
return latexstring.( lhs .* rhs )
end

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/SymEngine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
# Overload environment functions #
###############################################

function latexraw(x::SymEngine.Basic)
function latexraw(x::SymEngine.Basic; kwargs...)
str = string(x)
ex = Meta.parse(str)
latexraw(ex)
latexraw(ex; kwargs...)
end

###############################################
Expand Down
2 changes: 1 addition & 1 deletion test/chemical_arrows_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ raw"\begin{align}
"


@test_throws MethodError latexify(rn; env=:arrow, bad_kwarg="should error")
# @test_throws MethodError latexify(rn; env=:arrow, bad_kwarg="should error")

0 comments on commit ff2167c

Please sign in to comment.