diff --git a/Project.toml b/Project.toml index 29f2f47807..417a505c5e 100644 --- a/Project.toml +++ b/Project.toml @@ -20,6 +20,7 @@ Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Requires = "ae029012-a4dd-5104-9daa-d747884805df" RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47" +SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" @@ -28,15 +29,15 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [weakdeps] BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665" CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" -HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327" GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2" +HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327" StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544" [extensions] CatalystBifurcationKitExtension = "BifurcationKit" CatalystCairoMakieExtension = "CairoMakie" -CatalystHomotopyContinuationExtension = "HomotopyContinuation" CatalystGraphMakieExtension = "GraphMakie" +CatalystHomotopyContinuationExtension = "HomotopyContinuation" CatalystStructuralIdentifiabilityExtension = "StructuralIdentifiability" [compat] @@ -48,9 +49,9 @@ DiffEqBase = "6.83.0" DocStringExtensions = "0.8, 0.9" DynamicPolynomials = "0.5" DynamicQuantities = "0.13.2" +GraphMakie = "0.5" Graphs = "1.4" HomotopyContinuation = "2.9" -GraphMakie = "0.5" JumpProcesses = "9.3.2" LaTeXStrings = "1.3.0" Latexify = "0.14, 0.15, 0.16" @@ -60,6 +61,7 @@ Parameters = "0.12" Reexport = "0.2, 1.0" Requires = "1.0" RuntimeGeneratedFunctions = "0.5.12" +SciMLBase = "2.44, >=2.45.1" Setfield = "1" StructuralIdentifiability = "0.5.8" Symbolics = "5.30.1" @@ -71,11 +73,11 @@ BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665" CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def" DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf" +GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2" Graphviz_jll = "3c863552-8265-54e4-a6dc-903eb78fde85" HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" -GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2" NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" diff --git a/src/latexify_recipes.jl b/src/latexify_recipes.jl index 0d54079ec0..736657023c 100644 --- a/src/latexify_recipes.jl +++ b/src/latexify_recipes.jl @@ -48,7 +48,7 @@ function processsym(s) var end -function chemical_arrows(rn::ReactionSystem; expand = true, +function chemical_arrows(rn::ReactionSystem; double_linebreak = LATEX_DEFS.double_linebreak, starred = LATEX_DEFS.starred, mathrm = true, mathjax = LATEX_DEFS.mathjax, kwargs...) @@ -87,8 +87,6 @@ function chemical_arrows(rn::ReactionSystem; expand = true, ### Expand functions to maths expressions rate = r.rate isa Symbolic ? subber(r.rate) : r.rate - rate = ModelingToolkit.prettify_expr(Symbolics._toexpr(rate)) - expand && (rate = recursive_clean!(rate)) ### Generate formatted string of substrates substrates = [make_stoich_str(substrate[1], substrate[2], subber; mathrm, @@ -102,10 +100,7 @@ function chemical_arrows(rn::ReactionSystem; expand = true, if i + 1 <= length(rxs) && issetequal(r.products, rxs[i + 1].substrates) && issetequal(r.substrates, rxs[i + 1].products) ### Bi-directional arrows - rate_backwards = MT.prettify_expr(Symbolics._toexpr(rxs[i + 1].rate)) - #rate_backwards = rxs[i+1].rate isa Symbolic ? Expr(subber(rxs[i+1].rate)) : rxs[i+1].rate - expand && (rate_backwards = recursive_clean!(rate_backwards)) - expand && (rate_backwards = recursive_clean!(rate_backwards)) + rate_backwards = rxs[i + 1].rate isa Symbolic ? subber(rxs[i + 1].rate) : rxs[i + 1].rate str *= " &" * rev_arrow str *= "[" * latexraw(rate_backwards; kwargs...) * "]" str *= "{" * latexraw(rate; kwargs...) * "} " @@ -121,8 +116,8 @@ function chemical_arrows(rn::ReactionSystem; expand = true, for product in zip(r.products, r.prodstoich)] isempty(products) && (products = ["\\varnothing"]) str *= join(products, " + ") - if (i == lastidx) || - (((i + 1) == lastidx) && (backwards_reaction == true)) && + if ((i == lastidx) || + (((i + 1) == lastidx) && (backwards_reaction == true))) && isempty(nonrxs) str *= " \n " else @@ -155,43 +150,6 @@ function any_nonrx_subsys(rn::MT.AbstractSystem) false end -# Recursively traverses an expression and removes things like X^1, 1*X. Will not actually have any effect on the expression when used as a function, but will make it much easier to look at it for debugging, as well as if it is transformed to LaTeX code. -function recursive_clean!(expr) - (expr isa Symbol) && (expr == :no___noise___scaling) && (return 1) - (typeof(expr) != Expr) && (return expr) - for i in 1:length(expr.args) - expr.args[i] = recursive_clean!(expr.args[i]) - end - (expr.args[1] == :^) && (expr.args[3] == 1) && (return expr.args[2]) - if expr.args[1] == :* - in(0, expr.args) && (return 0) - i = 1 - while (i = i + 1) <= length(expr.args) - if (typeof(expr.args[i]) == Expr) && (expr.args[i].head == :call) && - (expr.args[i].args[1] == :*) - for arg in expr.args[i].args - (arg != :*) && push!(expr.args, arg) - end - end - end - for i in length(expr.args):-1:2 - (typeof(expr.args[i]) == Expr) && (expr.args[i].head == :call) && - (expr.args[i].args[1] == :*) && deleteat!(expr.args, i) - (expr.args[i] == 1) && deleteat!(expr.args, i) - end - (length(expr.args) == 2) && (return expr.args[2]) # We have a multiplication of only one thing, return only that thing. - (length(expr.args) == 1) && (return 1) # We have only * and no real arguments. - (length(expr.args) == 3) && (expr.args[2] == -1) && return :(-$(expr.args[3])) - (length(expr.args) == 3) && (expr.args[3] == -1) && return :(-$(expr.args[2])) - end - if expr.head == :call - (expr.args[1] == :/) && (expr.args[3] == 1) && (return expr.args[2]) - (expr.args[1] == :binomial) && (expr.args[3] == 1) && return expr.args[2] - #@isdefined($(expr.args[1])) || error("Function $(expr.args[1]) not defined.") - end - return expr -end - function make_stoich_str(spec, stoich, subber; mathrm = true, kwargs...) if mathrm prestr = "\\mathrm{"