Skip to content

Commit

Permalink
Enable MathJax functionality (#11)
Browse files Browse the repository at this point in the history
* Enable MathJax functionality

Allow LaTeX to appear in images produced using savefig().

* Make MathJax configurable
  • Loading branch information
jd-foster authored Sep 19, 2023
1 parent b44d6de commit 68db760
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/PlotlyKaleido.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ end

const P = Pipes()

const _mathjax_url_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax"
const _mathjax_last_version = v"2.7.9"

kill_kaleido() = is_running() && kill(P.proc)

is_running() = isdefined(P, :proc) && isopen(P.stdin) && process_running(P.proc)

restart(;kwargs...) = (kill_kaleido(); sleep(0.1); start(;kwargs...))

function start(;plotly_version = missing, kwargs...)
function start(;plotly_version = missing,
mathjax = missing, mathjax_version::VersionNumber = _mathjax_last_version,
kwargs...)
is_running() && return
cmd = joinpath(Kaleido_jll.artifact_dir, "kaleido" * (Sys.iswindows() ? ".cmd" : ""))
basic_cmds = [cmd, "plotly"]
Expand All @@ -39,6 +44,21 @@ function start(;plotly_version = missing, kwargs...)
kwargs...
)
end
if !(mathjax === missing)
if mathjax_version > v"2.7.9"
error("The given mathjax version $(mathjax_version) is greater than the last supported version of $(_mathjax_last_version).")
end
if mathjax isa Bool && mathjax
push!(chromium_flags, "--mathjax=$(_mathjax_url_path)/$(mathjax_version)/MathJax.js")
elseif mathjax isa String
# We expect the keyword argument to be a valid URL or similar, else error "Kaleido startup failed with code 1".
push!(chromium_flags, "--mathjax=$(mathjax)")
else
@warn """The value of the provided argument
mathjax=$(mathjax)
is neither a Bool nor a String and has been ignored."""
end
end
# Taken inspiration from https://github.com/plotly/Kaleido/blob/3b590b563385567f257db8ff27adae1adf77821f/repos/kaleido/py/kaleido/scopes/base.py#L116-L141
user_flags = String[]
for (k,v) in pairs(extra_flags)
Expand Down

0 comments on commit 68db760

Please sign in to comment.