build pluto only for now

This commit is contained in:
jverzani 2022-05-28 07:14:56 -04:00
parent fa77930bf5
commit 6a6f24d51c
5 changed files with 459 additions and 297 deletions

View File

@ -3,4 +3,5 @@ ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
CalculusWithJulia = "a2e0e22d-7d4c-5312-9169-8b992201a882"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
Weave = "44d3d7a6-8a23-5bf8-98c5-b353f8df5ec9"

71
docs/build_cache.toml Normal file
View File

@ -0,0 +1,71 @@
derivatives_optimization = "5975e12024d1cbb622b2879aacb70352f6632461ebb55b4631bdf82eca90a05b"
alternatives_plotly_plotting = "38de16a0a8f975a4a69a7dca7e747ce3dbb42c9291fc9591852fee9668e85c61"
integral_vector_calculus_stokes_theorem = "072c2d4cead381d760b8617f75a4f3a2f9c3c7080ca2fe0d1b09937b09ba678c"
derivatives_derivatives = "1f463e9535956f67a1d1f67c0bb96561793c188e4dee516956e15524db0092ad"
integrals_arc_length = "2544b9be3fdfdc553788e655313ddc7bf0d06478d1d3122e32e09d39f2e18d9d"
integrals_area = "f615c00f21b19de93016e879bc19a36e77bbdff86b15176700fc81608c4f8505"
derivatives_more_zeros = "8c399cc058540b8180356eed20333209c8e0227e1b158bf6036acaef7b50be45"
derivatives_curve_sketching = "e5f32b3f77e289593c95b2201c0b24c9da0389fbf763f4f378ec09858e1c6ac7"
derivatives_lhospitals_rule = "c2e4958e8d5e65e2ef5a9bc7f0d9f9868acd27547fba7d61dfe9340e85772b82"
ODEs_odes = "57c6d05ba7a2b412237573202bb787d8478e47d6c49899665ea3dbdf631f2fac"
precalc_polynomials_package = "9837d1e005a6a2fc25f3847532ea1a861f493e681c4d094ddc39892fc28ac19c"
integral_vector_calculus_line_integrals = "1f3a8a8a22d0be207761f96a06d128f4661bc67b5c03fbda5d35a846bfb9beb4"
ODEs_euler = "7326d476767ecd1e68b3e33aff5683699e22257a3e4f252300c05c344aa2cb2f"
integrals_partial_fractions = "72cc5b7e96273fdc2d30d9c5532e399e86aa9e37ada3a7a173518d279be2a8c8"
differentiable_vector_calculus_scalar_functions = "660582e02440193a6b55721bc3690a4c61bdd76d3f0425fb7c9eabc7977ea982"
integrals_center_of_mass = "6a58f248e43cbcb664532a1edd3e418ca9b4aeb226eb7987daf69ba902f9752f"
misc_getting_started_with_julia = "2365a25db4c90c6681a020763269e57bcfe4e292aa9cecefbe59e80e56b546cc"
precalc_logical_expressions = "354f07b97bad092a198cef91a6403ef6bb6287e06b0b910de4bb9ce65477c1a9"
limits_continuity = "7ec41b103affe38d9a5a20d52971e7278bffa38e4daf11efd7dd10fa1f6df300"
differentiable_vector_calculus_scalar_functions_applications = "aaebf1333b4153e0678af7ba45c168dd15cca5a3fd5de43b27032c64f490735e"
limits_intermediate_value_theorem = "d695cee3a813edd12b33f8502542a813bf78a7295c5d4c7f01d14d2751bf5928"
integral_vector_calculus_review = "7d9bc1ea81ecb731eaf781f3dd90fe93bcaed198bddbeae14095edb1665bab6d"
precalc_inversefunctions = "fe53a8d52a189d1969e9ccc178c3531b314a8039d036be934a7ca7d9b20c850f"
precalc_variables = "eac80638a636d707187269654ecc6b69bb5593dd87431de669b47f4ec48fb9b0"
derivatives_related_rates = "ad9978143e47775297a7611f3237c703c2e5062707893a299f5232cd83475651"
precalc_numbers_types = "37c0ba15749a95eb2bb854af30d7c53351a14689d8cfefc6c514070c9ba49491"
integrals_volumes_slice = "2c8bbdea196ab12447b1b9f3f4c90cc308c712dbebb3298fff47475ce39e6ad6"
integrals_surface_area = "5fc55f8068911a67723710a7faf87947d951428289d253142419e329291a7263"
limits_limits_extensions = "52316ab96de356e2d8c6c0b03ea96663b4c39f254840c4588f017648bdb3a221"
derivatives_symbolic_derivatives = "f2a3cc66b0d805f6275dca26f2f53cc387f509c16fe29d2ead0aaaf2dffeaae3"
derivatives_taylor_series_polynomials = "401adcc7a53093dc863d026dbf6f315d908ab72e737765ddf6a3b78de66ee289"
integrals_ftc = "d098b6a62fd0400c14ac67f3ba90676d3da76155b7fbd8072f125d3b8274e5db"
limits_limits = "4bf057fb77cc09ed000a038fc52e65c60df73e6092dd6d9e2c7f518ff4e82112"
derivatives_mean_value_theorem = "69897def87afa42f79bb190708e0ace410d44c58f57ddf93ea0580fefe6051b9"
precalc_julia_overview = "5eb94db07206c44a644a4e9abc4c402bf938bc442e2cefb8c97bc911e976d52b"
differentiable_vector_calculus_vector_valued_functions = "c1ee91bf783f141ff71bd3e6fdd35c46579dc9d307942ecc636095363893d8e4"
integral_vector_calculus_div_grad_curl = "0c79bf69639c6a17b83ba0b49df0911c46c07e48f9bbd5dc29a3294c7389ca19"
derivatives_first_second_derivatives = "0abe3b17514d385f932795e0b4ba6190f96bc60c7783ff5af126c8819b34d0a2"
precalc_functions.jmd = "a6d4928a59cf9eb4a8e3f36469819289c21911e756d73c9fa294eb421c9c686b"
derivatives_numeric_derivatives = "199441dc8c74f6854a907bcb7d380bab0e72bc3b6bb92cc587b375808680e20b"
derivatives_linearization = "246e5fa6e9871f59c220f1891cd6a7b6c806670af5dae83779396e128f703d81"
misc_julia_interfaces = "2ecff77788c6c706450ab11ee45e21e0714cb545353d8879e2c2e6349dcf9608"
derivatives_newtons_method = "bd4185c9db9b8b7e3cb0ab582ae1f8d3908322fe81e208c25f62a68b2944859e"
integral_vector_calculus_double_triple_integrals = "8a1fe10844df05c69ff6fc5bdb53483462e3ef162ed2dcc873d647a0f2f3b15d"
precalc_polynomial_roots = "fa23b7f0dfdfb7fe85aae97cc94ebbc3de0ecf82ddccbf78ebf0c5c2d711578b"
precalc_ranges = "b262dbb5b0d7a87a21db72bb64d3fa37fe06cd5af2e38f48cc38b4ce820a0c33"
precalc_polynomial = "2c0ba02bd275e1fd51d7f0a239c691ed9ca57b7706a4cff7df462ffb364acc8c"
precalc_rational_functions = "626575c82c4b248c943ff01c1da5bb3a815e3cc6918a3531343fc58538042f2e"
precalc_transformations = "0432fb01b8ec71c305444d43f0704b6af677d962cbd18c666535bccd644c22fb"
precalc_vectors = "8398d7e06947b3fa27c49bddb64cc7096b0ab29435b663b3e5579512dada80ee"
integrals_integration_by_parts = "1a1b0ce236af59896c1c59c9481fcdf51f5a1b22146903aa1023f1c3c33c0f73"
ODEs_differential_equations = "c3ef746402f9b9a3d4146dc67566578c537a1d179e60da3ceac9fa7d39367f31"
integrals_area_between_curves = "b91a0c1631ec04cf065eefddf18db1ea24c28f06d745909e7f1b6a97bd7ece3b"
precalc_trig_functions = "a638b2d482c45d58da6bcff0d25c27a7cc44d326e9532890e3b023df8a502097"
differentiable_vector_calculus_polar_coordinates = "a5eed23614ec0815e9c6f88768619fce9fc0ada31535147468c44a6c9c586376"
integrals_improper_integrals = "cc96fa238225a198b1717a50f72cb0869fff21d35d275c4c2e4b9f5b005b4cc7"
misc_calculus_with_julia = "79d3617d1b0a7735bbae8a6eda83fe40b755bde9bf101bb592e3b903adfeb34f"
differentiable_vector_calculus_vectors = "cde2675466c01a697a7bfc73a94d58e9a58b7ed1b30cc1f03b9f573b6cb5a48d"
misc_unicode = "ef41cdddea251570f3757186ccb6a0d1f9a313a04b6ac0f074e266f71dfcb461"
integrals_mean_value_theorem = "7d7dbc1e2f8461f1b59f0df5143189cce576a3fdcef39365190859fb827ecf46"
ODEs_solve = "967c509f4b998a5f7a2f993fbb649dd52c99ed2ed4120c6d7726e04fc088f1c1"
misc_toc = "0663a465e34b5a8e1b7b375dac2b9872e94ac5a276877061fc19bc300740c5b9"
misc_quick_notes = "26d355d223cd562804037e96412ac766d5dcd997c42263819cf2c89504524e24"
precalc_functions = "a6d4928a59cf9eb4a8e3f36469819289c21911e756d73c9fa294eb421c9c686b"
precalc_plotting = "1b85c91fb0488407a91b79c2613716b2788e50ca62520888e15676a63a7a966d"
integrals_substitution = "b96fe31960c9c8b0a46e3f8f6011abd9a8deb2fcbe8cc5402692415bcb8c04f6"
precalc_calculator = "a400b6003b6093fe7efade92bb1adff4fe014a7e020529825be1692f36ae2653"
precalc_exp_log_functions = "bd5d1b555dd2c975f327ebf17d076ff390d6b480d35c52b3f88cdff441e6f2f3"
differentiable_vector_calculus_plots_plotting = "1fbca9144d419b406206671a04c6e5b954e1993192d53c1dfa3e132d8100b769"
differentiable_vector_calculus_vector_fields = "bd852d03a2a3397337649b23898252a7db0a298b6427d3e78262d4457e87a90b"
derivatives_implicit_differentiation = "e3bd825f55ed70502ea787361e0a3d4bbe3463dc56980e31feb2b2a6101ecc1c"

View File

@ -2,11 +2,7 @@ using Documenter
using ArgParse
using CalculusWithJuliaNotes
using CalculusWithJulia
using Weave
using Pkg
import Markdown
import Pluto
include("weave-support.jl")
include("markdown-to-pluto.jl")
@ -34,21 +30,6 @@ function parse_commandline()
return parse_args(s)
end
# what to build
function build_pages(folder=nothing, file=nothing, target=:html, force=false)
build_list = (target, )
if folder != nothing && file !=nothing
weave_file(folder, file * ".jmd", build_list=build_list, force=force)
elseif folder != nothing
if folder == "all"
weave_all(; build_list=build_list, force=all)
else
weave_folder(folder, build_list = build_list, force=force)
end
elseif force
weave_all(; build_list=build_list, force=true)
end
end
# build pages
d = parse_commandline()
@ -58,22 +39,14 @@ force = parse(Bool, d["force"])
if isnothing(folder) && isnothing(file)
# build full thing
# for folder ∈ ("precalc", "limits", "derivatives", "integrals", "ODEs",
# "differentiable_vector_calculus", "integral_vector_calculus",
# "misc")
# build_pages(folder, nothing, target, force)
# end
# # alternatives needs work
# build_pages("alternatives", "plotly_plotting", :html, force)
# keep it simple for now; uncomment above once build goes through
#build_all(force)
build_pages("precalc", nothing, :html, force)
build_toc()
#build_toc()
else
build_pages(folder, file, target, force)
build_pages(folder, file, :html, force)
end

View File

@ -1,4 +1,4 @@
import Markdown
# causes issues
function Markdown.plain(io::IO, l::Markdown.LaTeX)

View File

@ -1,11 +1,58 @@
## Modified from
## https://github.com/SciML/SciMLTutorials.jl/blob/master/src/SciMLTutorials.jl
using CalculusWithJulia
import Pluto
using Weave
using Pkg
using SHA
using TOML
const repo_directory = joinpath(@__DIR__,"..")
const cssfile = joinpath(@__DIR__, "..", "templates", "skeleton_css.css")
const htmlfile = joinpath(@__DIR__, "..", "templates", "bootstrap.tpl")
const latexfile = joinpath(@__DIR__, "..", "templates", "julia_tex.tpl")
const cache_file = joinpath(@__DIR__, "build_cache.toml")
const build_dir = joinpath(@__DIR__, "build")
sha(s::IO) = bytes2hex(sha256(s))
sha(path::AbstractString) = open(path, "r") do io
sha(io)
end
read_cache() = TOML.parsefile(cache_file)
write_cache(D) =
open(cache_file, "w") do io
for (k,v) D
println(io, k, " = ", "\"$v\"")
end
end
function write_sha(folder, file)
key = join((folder, file), "_")
jmd_sha = sha(jmd_file(folder, file))
# may need to block!
D = read_cache()
D[key] = jmd_sha
write_cache(D)
end
# build file check sha in cache
jmd_file(folder, file) = joinpath(repo_directory, "CwJ", folder, file)
# should we build this file?
function build_fileq(folder, file; force=true)
force && return force
key = join((folder, file), "_")
D = read_cache()
jmd_sha = sha(jmd_file(folder, file))
cache_sha = get(D, key, nothing)
Δ = jmd_sha != cache_sha
return Δ
end
## ----
function build_toc(force=true)
@info "building table of contents"
@ -20,8 +67,7 @@ function build_toc(force=true)
cd(jmd_dir)
build_file(file, outfile, force=force) || return nothing
build_fileq(file, outfile, force=force) || return nothing
header = CalculusWithJulia.WeaveSupport.header_cmd
#footer = CalculusWithJulia.WeaveSupport.footer_cmd(bnm, folder)
html_content = md2html(file,
@ -43,275 +89,346 @@ function build_toc(force=true)
end
# do we build the file check mtime
# function build_file(jmdfile, outfile; force=false)
# do we build the file?
function build_file(jmdfile, outfile; force=false)
force && return true
!isfile(outfile) && return true
mtime(outfile) < mtime(jmdfile) && return true
return false
# force && return true
# !isfile(outfile) && return true
# mtime(outfile) < mtime(jmdfile) && return true
# return false
# end
# build pluto html
# file **has** ".jmd" extension
function build_file(folder, file, force)
## use jmd -> pluto notebook -> generate_html
@info "Building HTML: $file"
o = build_fileq(folder, file, force=force)
o || return false
bnm = replace(file, r"\.jmd$"=>"")
jmd_dir = joinpath(repo_directory, "CwJ", folder)
cd(jmd_dir)
dir = joinpath(build_dir, folder)
isdir(dir) || mkpath(dir)
ext = ".html"
outfile = joinpath(build_dir, folder, bnm*ext)
header = CalculusWithJulia.WeaveSupport.header_cmd
footer = CalculusWithJulia.WeaveSupport.footer_cmd(bnm, folder)
html_content = md2html(jmd_file(folder, file),
header_cmds=(header,),
footer_cmds=(footer,)
)
open(outfile, "w") do io
write(io, html_content)
end
write_sha(folder, file)
end
# build list ⊂ (:script,:html,:weave_html, :pdf,:github,:notebook,:pluto)
function weave_file(folder, file; build_list=(:html,), force=false, kwargs...)
jmd_dir = isdir(folder) ? folder : joinpath(repo_directory, "CwJ", folder)
jmd_file = joinpath(jmd_dir, file)
bnm = replace(basename(jmd_file), r".jmd$" => "")
build_dir = joinpath(@__DIR__, "build")
isdir(build_dir) || mkpath(build_dir)
if !force
#testfile = joinpath(repo_directory, "html", folder, bnm*".html")
testfile = joinpath(build_dir, folder, bnm*".html")
if isfile(testfile) && (mtime(testfile) >= mtime(tmp))
return
end
force=true
end
Pkg.activate(dirname(jmd_dir))
Pkg.instantiate()
args = Dict{Symbol,String}(:folder=>folder,:file=>file)
if :script build_list
println("Building Script")
dir = joinpath(repo_directory,"script",folder)
isdir(dir) || mkpath(dir)
ext = ".jl"
outfile = joinpath(dir, bnm*ext)
build_file(file, outfile, force=force) || return nothing
args[:doctype] = "script"
tangle(tmp;out_path=dir)
end
# use Pluto to build html pages
if :html build_list
## use jmd -> pluto notebook -> generate_html
println("Building HTML: $file")
cd(jmd_dir)
dir = joinpath(build_dir, folder)
isdir(dir) || mkpath(dir)
ext = ".html"
outfile = joinpath(dir, bnm*ext)
o = build_file(file, outfile, force=force)
o || return nothing
header = CalculusWithJulia.WeaveSupport.header_cmd
footer = CalculusWithJulia.WeaveSupport.footer_cmd(bnm, folder)
html_content = md2html(file,
header_cmds=(header,),
footer_cmds=(footer,)
)
open(outfile, "w") do io
write(io, html_content)
end
end
## old html generation
if :weave_html build_list
println("Building HTML for $file")
dir = joinpath(build_dir, folder)
isdir(dir) || mkpath(dir)
figdir = joinpath(jmd_dir,"figures")
htmlfigdir = joinpath(dir, "figures")
if isdir(figdir)
isdir(htmlfigdir) && rm(htmlfigdir, recursive=true)
cp(figdir, htmlfigdir)
end
ext = ".html"
outfile = joinpath(dir, bnm*ext)
build_file(file, outfile, force=force) || return nothing
Weave.set_chunk_defaults!(:wrap=>false)
args[:doctype] = "html"
# override printing for Polynomials, SymPy with weave
𝐦 = Core.eval(@__MODULE__, :(module $(gensym(:WeaveHTMLTestModule)) end))
Core.eval(𝐦, quote
using SymPy, Polynomials
function Base.show(io::IO, ::MIME"text/html", x::T) where {T <: SymPy.SymbolicObject}
#write(io, "<div class=\"well well-sm\">")
write(io, "<div class=\"output\">")
show(io, "text/latex", x)
write(io, "</div>")
end
function Base.show(io::IO, ::MIME"text/html", x::Array{T}) where {T <: SymPy.SymbolicObject}
#write(io, "<div class=\"well well-sm\">")
write(io, "<div class=\"output\">")
show(io, "text/latex", x)
write(io, "</div>")
end
function Base.show(io::IO, ::MIME"text/html", x::T) where {T <: Polynomials.AbstractPolynomial}
# #write(io, "<div class=\"well well-sm\">")
write(io, "<div class=\"output\">")
show(io, "text/latex", x)
write(io, "</div>")
end
end)
#weave(tmp,doctype = "md2html",out_path=dir,args=args; fig_ext=".svg", css=cssfile, kwargs...)
weave(tmp;
doctype = "md2html",
out_path=dir,
mod = 𝐦,
args=args,
fig_ext=".svg",
template=htmlfile,
fig_path=tempdir(),
kwargs...)
# clean up
isdir(htmlfigdir) && rm(htmlfigdir, recursive=true)
end
if :pdf build_list
eval(quote using Tectonic end) # load Tectonic; wierd testing error
println("Building PDF")
dir = joinpath(repo_directory,"pdf",folder)
isdir(dir) || mkpath(dir)
ext = ".pdf"
outfile = joinpath(dir, bnm*ext)
build_file(file, outfile, force=force) || return nothing
fig_path = "_figures_" * bnm
figdir = joinpath(jmd_dir,"figures")
texfigdir = joinpath(dir, "figures")
if isdir(figdir)
isdir(texfigdir) && rm(texfigdir, recursive=true)
cp(figdir, texfigdir)
end
args[:doctype] = "pdf"
try
weave(tmp,doctype="md2tex",out_path=dir,args=args;
template=latexfile,
fig_path=fig_path,
kwargs...)
texfile = joinpath(dir, bnm * ".tex")
Base.invokelatest(Tectonic.tectonic, bin -> run(`$bin $texfile`))
# clean up
for ext in (".tex",)
f = joinpath(dir, bnm * ext)
isfile(f) && rm(f)
end
catch ex
@warn "PDF generation failed" exception=(ex, catch_backtrace())
end
isdir(texfigdir) && rm(texfigdir, recursive=true)
isdir(joinpath(dir,fig_path)) && rm(joinpath(dir,fig_path), recursive=true)
for ext in (".aux", ".log", ".out")
f = joinpath(dir, bnm * ext)
isfile(f) && rm(f)
end
end
if :github build_list
println("Building Github Markdown")
dir = joinpath(repo_directory,"markdown",folder)
isdir(dir) || mkpath(dir)
ext = ".md"
outfile = joinpath(dir, bnm*ext)
build_file(file, outfile, force=force) || return nothing
args[:doctype] = "github"
weave(tmp,doctype = "github",out_path=dir, args=args;
fig_path=tempdir(),
kwargs...)
end
if :notebook build_list
println("Building Notebook")
dir = joinpath(repo_directory,"notebook",folder)
isdir(dir) || mkpath(dir)
ext = ".ipynb"
outfile = joinpath(dir, bnm*ext)
build_file(file, outfile, force=force) || return nothing
args[:doctype] = "notebook"
Weave.convert_doc(tmp,outfile)
end
if :pluto build_list
println("Building Pluto notebook")
dir = joinpath(repo_directory,"pluto",folder)
isdir(dir) || mkpath(dir)
ext = ".jl"
outfile = joinpath(dir, bnm*ext)
build_file(file, outfile, force=force) || return nothing
md2jl(file, outfile)
end
end
"""
weave_all(; force=false, build_list=(:script,:html,:pdf,:github,:notebook))
Run `weave` on all source files.
* `force`: by default, only run `weave` on files with `html` file older than the source file in `CwJ`
* `build_list`: list of output types to be built. The default is all types
The files will be built as subdirectories in the package directory. This is returned by `pathof(CalculusWithJulia)`.
"""
function weave_all(;force=false, build_list=(:script,:html,:pdf,:github,:notebook))
# what to build
function build_all(force)
folders = readdir(joinpath(repo_directory,"CwJ"))
folders = filter(F -> isdir(joinpath(repo_directory, "CwJ", F)), folders)
asyncmap(F -> weave_folder(F; force=force, build_list=build_list), folders)
# for folder in readdir(joinpath(repo_directory,"CwJ"))
# folder == "test.jmd" && continue
# weave_folder(folder; force=force, build_list=build_list)
# end
asyncmap(F -> build_folder(F, force), folders)
end
function weave_folder(folder; force=false, build_list=(:html,))
function build_folder(folder, force)
!isnothing(match(r"\.ico$", folder)) && return nothing
files = readdir(joinpath(repo_directory,"CwJ",folder))
files = filter(f -> occursin(r".jmd$", basename(f)), files)
asyncmap(file -> weave_file(folder, file; force=force, build_list=build_list), files)
# for file in readdir(joinpath(repo_directory,"CwJ",folder))
# !occursin(r".jmd$", basename(file)) && continue
# println("Building $(joinpath(folder,file))")
# try
# weave_file(folder,file; force=force, build_list=build_list)
# catch
# end
# end
asyncmap(file -> build_file(folder, file, force), files)
end
function build_pages(folder=nothing, file=nothing, target=:html, force=false)
if folder == nothing
build_all(force)
elseif file == nothing
build_folder(folder, force)
else
# build file in folder
build_file(folder, file, force)
end
end
# ## --------------------------------------------------
# ## Build more generally, but not use right now
# const cssfile = joinpath(@__DIR__, "..", "templates", "skeleton_css.css")
# const htmlfile = joinpath(@__DIR__, "..", "templates", "bootstrap.tpl")
# const latexfile = joinpath(@__DIR__, "..", "templates", "julia_tex.tpl")
# # build list ⊂ (:script,:html,:weave_html, :pdf,:github,:notebook,:pluto)
# function weave_file(folder, file; build_list=(:html,), force=false, kwargs...)
# jmd_dir = isdir(folder) ? folder : joinpath(repo_directory, "CwJ", folder)
# jmd_file = joinpath(jmd_dir, file)
# bnm = replace(basename(jmd_file), r".jmd$" => "")
# build_dir = joinpath(@__DIR__, "build")
# isdir(build_dir) || mkpath(build_dir)
# if !force
# #testfile = joinpath(repo_directory, "html", folder, bnm*".html")
# testfile = joinpath(build_dir, folder, bnm*".html")
# if isfile(testfile) && (mtime(testfile) >= mtime(tmp))
# return
# end
# force=true
# end
# Pkg.activate(dirname(jmd_dir))
# Pkg.instantiate()
# args = Dict{Symbol,String}(:folder=>folder,:file=>file)
# if :script ∈ build_list
# println("Building Script")
# dir = joinpath(repo_directory,"script",folder)
# isdir(dir) || mkpath(dir)
# ext = ".jl"
# outfile = joinpath(dir, bnm*ext)
# build_file(file, outfile, force=force) || return nothing
# args[:doctype] = "script"
# tangle(tmp;out_path=dir)
# end
# # use Pluto to build html pages
# if :html ∈ build_list
# ## use jmd -> pluto notebook -> generate_html
# println("Building HTML: $file")
# cd(jmd_dir)
# dir = joinpath(build_dir, folder)
# isdir(dir) || mkpath(dir)
# ext = ".html"
# outfile = joinpath(dir, bnm*ext)
# o = build_file(file, outfile, force=force)
# o || return nothing
# header = CalculusWithJulia.WeaveSupport.header_cmd
# footer = CalculusWithJulia.WeaveSupport.footer_cmd(bnm, folder)
# html_content = md2html(file,
# header_cmds=(header,),
# footer_cmds=(footer,)
# )
# open(outfile, "w") do io
# write(io, html_content)
# end
# end
# ## old html generation
# if :weave_html ∈ build_list
# println("Building HTML for $file")
# dir = joinpath(build_dir, folder)
# isdir(dir) || mkpath(dir)
# figdir = joinpath(jmd_dir,"figures")
# htmlfigdir = joinpath(dir, "figures")
# if isdir(figdir)
# isdir(htmlfigdir) && rm(htmlfigdir, recursive=true)
# cp(figdir, htmlfigdir)
# end
# ext = ".html"
# outfile = joinpath(dir, bnm*ext)
# build_file(file, outfile, force=force) || return nothing
# Weave.set_chunk_defaults!(:wrap=>false)
# args[:doctype] = "html"
# # override printing for Polynomials, SymPy with weave
# 𝐦 = Core.eval(@__MODULE__, :(module $(gensym(:WeaveHTMLTestModule)) end))
# Core.eval(𝐦, quote
# using SymPy, Polynomials
# function Base.show(io::IO, ::MIME"text/html", x::T) where {T <: SymPy.SymbolicObject}
# #write(io, "<div class=\"well well-sm\">")
# write(io, "<div class=\"output\">")
# show(io, "text/latex", x)
# write(io, "</div>")
# end
# function Base.show(io::IO, ::MIME"text/html", x::Array{T}) where {T <: SymPy.SymbolicObject}
# #write(io, "<div class=\"well well-sm\">")
# write(io, "<div class=\"output\">")
# show(io, "text/latex", x)
# write(io, "</div>")
# end
# function Base.show(io::IO, ::MIME"text/html", x::T) where {T <: Polynomials.AbstractPolynomial}
# # #write(io, "<div class=\"well well-sm\">")
# write(io, "<div class=\"output\">")
# show(io, "text/latex", x)
# write(io, "</div>")
# end
# end)
# #weave(tmp,doctype = "md2html",out_path=dir,args=args; fig_ext=".svg", css=cssfile, kwargs...)
# weave(tmp;
# doctype = "md2html",
# out_path=dir,
# mod = 𝐦,
# args=args,
# fig_ext=".svg",
# template=htmlfile,
# fig_path=tempdir(),
# kwargs...)
# # clean up
# isdir(htmlfigdir) && rm(htmlfigdir, recursive=true)
# end
# if :pdf ∈ build_list
# eval(quote using Tectonic end) # load Tectonic; wierd testing error
# println("Building PDF")
# dir = joinpath(repo_directory,"pdf",folder)
# isdir(dir) || mkpath(dir)
# ext = ".pdf"
# outfile = joinpath(dir, bnm*ext)
# build_file(file, outfile, force=force) || return nothing
# fig_path = "_figures_" * bnm
# figdir = joinpath(jmd_dir,"figures")
# texfigdir = joinpath(dir, "figures")
# if isdir(figdir)
# isdir(texfigdir) && rm(texfigdir, recursive=true)
# cp(figdir, texfigdir)
# end
# args[:doctype] = "pdf"
# try
# weave(tmp,doctype="md2tex",out_path=dir,args=args;
# template=latexfile,
# fig_path=fig_path,
# kwargs...)
# texfile = joinpath(dir, bnm * ".tex")
# Base.invokelatest(Tectonic.tectonic, bin -> run(`$bin $texfile`))
# # clean up
# for ext in (".tex",)
# f = joinpath(dir, bnm * ext)
# isfile(f) && rm(f)
# end
# catch ex
# @warn "PDF generation failed" exception=(ex, catch_backtrace())
# end
# isdir(texfigdir) && rm(texfigdir, recursive=true)
# isdir(joinpath(dir,fig_path)) && rm(joinpath(dir,fig_path), recursive=true)
# for ext in (".aux", ".log", ".out")
# f = joinpath(dir, bnm * ext)
# isfile(f) && rm(f)
# end
# end
# if :github ∈ build_list
# println("Building Github Markdown")
# dir = joinpath(repo_directory,"markdown",folder)
# isdir(dir) || mkpath(dir)
# ext = ".md"
# outfile = joinpath(dir, bnm*ext)
# build_file(file, outfile, force=force) || return nothing
# args[:doctype] = "github"
# weave(tmp,doctype = "github",out_path=dir, args=args;
# fig_path=tempdir(),
# kwargs...)
# end
# if :notebook ∈ build_list
# println("Building Notebook")
# dir = joinpath(repo_directory,"notebook",folder)
# isdir(dir) || mkpath(dir)
# ext = ".ipynb"
# outfile = joinpath(dir, bnm*ext)
# build_file(file, outfile, force=force) || return nothing
# args[:doctype] = "notebook"
# Weave.convert_doc(tmp,outfile)
# end
# if :pluto ∈ build_list
# println("Building Pluto notebook")
# dir = joinpath(repo_directory,"pluto",folder)
# isdir(dir) || mkpath(dir)
# ext = ".jl"
# outfile = joinpath(dir, bnm*ext)
# build_file(file, outfile, force=force) || return nothing
# md2jl(file, outfile)
# end
# end
# """
# weave_all(; force=false, build_list=(:script,:html,:pdf,:github,:notebook))
# Run `weave` on all source files.
# * `force`: by default, only run `weave` on files with `html` file older than the source file in `CwJ`
# * `build_list`: list of output types to be built. The default is all types
# The files will be built as subdirectories in the package directory. This is returned by `pathof(CalculusWithJulia)`.
# """
# function weave_all(;force=false, build_list=(:script,:html,:pdf,:github,:notebook))
# folders = readdir(joinpath(repo_directory,"CwJ"))
# folders = filter(F -> isdir(joinpath(repo_directory, "CwJ", F)), folders)
# asyncmap(F -> weave_folder(F; force=force, build_list=build_list), folders)
# # for folder in readdir(joinpath(repo_directory,"CwJ"))
# # folder == "test.jmd" && continue
# # weave_folder(folder; force=force, build_list=build_list)
# # end
# end
# function weave_folder(folder; force=false, build_list=(:html,))
# !isnothing(match(r"\.ico$", folder)) && return nothing
# files = readdir(joinpath(repo_directory,"CwJ",folder))
# files = filter(f -> occursin(r".jmd$", basename(f)), files)
# asyncmap(file -> weave_file(folder, file; force=force, build_list=build_list), files)
# # for file in readdir(joinpath(repo_directory,"CwJ",folder))
# # !occursin(r".jmd$", basename(file)) && continue
# # println("Building $(joinpath(folder,file))")
# # try
# # weave_file(folder,file; force=force, build_list=build_list)
# # catch
# # end
# # end
# end