Skip to content

Commit

Permalink
Fix #141 and fix #145, LaTeX rendering improvements (#147)
Browse files Browse the repository at this point in the history
* Fix #141 and fix #145, LaTeX rendering improvements

* Attempt to resolve PyCall in CI issue
  • Loading branch information
MichaelHatherly authored Jun 7, 2024
1 parent f161fd9 commit 84761e2
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/QuartoNotebookWorker/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
RCall = "6f49c342-dc21-5d91-9882-a32aef131414"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SymPyCore = "458b697b-88f0-4a86-b56b-78b75cfb3531"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[extensions]
QuartoNotebookWorkerCairoMakieExt = "CairoMakie"
QuartoNotebookWorkerDataFramesTablesExt = ["DataFrames", "Tables"]
QuartoNotebookWorkerJSONExt = "JSON"
QuartoNotebookWorkerLaTeXStringsExt = "LaTeXStrings"
QuartoNotebookWorkerMakieExt = "Makie"
QuartoNotebookWorkerPlotlyBaseExt = "PlotlyBase"
QuartoNotebookWorkerPlotlyJSExt = "PlotlyJS"
QuartoNotebookWorkerPlotsExt = "Plots"
QuartoNotebookWorkerRCallExt = "RCall"
QuartoNotebookWorkerReviseExt = "Revise"
QuartoNotebookWorkerSymPyCoreExt = "SymPyCore"

[preferences.QuartoNotebookWorker]
packages = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module QuartoNotebookWorkerLaTeXStringsExt

import QuartoNotebookWorker as QNW
import LaTeXStrings as LS

QNW._mimetype_wrapper(s::LS.LaTeXString) = LaTeXStringWrapper(s)

struct LaTeXStringWrapper <: QNW.WrapperType
value::LS.LaTeXString
end

Base.show(io::IO, ::MIME"text/markdown", s::LaTeXStringWrapper) = print(io, s.value)
Base.showable(::MIME"text/markdown", ::LaTeXStringWrapper) = true

end
17 changes: 17 additions & 0 deletions src/QuartoNotebookWorker/ext/QuartoNotebookWorkerSymPyCoreExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module QuartoNotebookWorkerSymPyCoreExt

import QuartoNotebookWorker as QNW
import SymPyCore as SPC

QNW._mimetype_wrapper(s::SPC.SymbolicObject) = SymWrapper(s)
QNW._mimetype_wrapper(s::AbstractArray{<:SPC.Sym}) = SymWrapper(s)
QNW._mimetype_wrapper(s::Dict{T,S}) where {T<:SPC.SymbolicObject,S<:Any} = SymWrapper(s)

struct SymWrapper <: QNW.WrapperType
value::Any
end

Base.show(io::IO, ::MIME"text/markdown", s::SymWrapper) = show(io, "text/latex", s.value)
Base.showable(::MIME"text/markdown", ::SymWrapper) = true

end
16 changes: 16 additions & 0 deletions test/examples/integrations/SymPy.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: SymPy integration
julia:
exeflags: ["--project=SymPy"]
---

```{julia}
ENV["PYTHON"] = ""
Pkg.build("PyCall")
using SymPy
```

```{julia}
@syms x
integrate(sin(x)*cos(x), x)
```
3 changes: 3 additions & 0 deletions test/examples/integrations/SymPy/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
10 changes: 10 additions & 0 deletions test/testsets/integrations/SymPy.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include("../../utilities/prelude.jl")

test_example(joinpath(@__DIR__, "../../examples/integrations/SymPy.qmd")) do json
cells = json["cells"]
cell = cells[4]
output = cell["outputs"][1]

@test output["data"]["text/markdown"] == raw"$\frac{\sin^{2}{\left(x \right)}}{2}$"
@test output["data"]["text/latex"] == raw"$\frac{\sin^{2}{\left(x \right)}}{2}$"
end
1 change: 1 addition & 0 deletions test/testsets/mimetypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ test_example(joinpath(@__DIR__, "../examples/mimetypes.qmd")) do json
cell = cells[14]
@test !isempty(cell["outputs"][1]["data"]["text/plain"])
@test !isempty(cell["outputs"][1]["data"]["text/latex"])
@test !isempty(cell["outputs"][1]["data"]["text/markdown"])
end

0 comments on commit 84761e2

Please sign in to comment.