Skip to content

Commit

Permalink
Add support for subfigures in LaTeX with Figure(::Matrix).
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHatherly committed Feb 9, 2021
1 parent 72893dc commit c7b7d9c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[publish_theme_default]
git-tree-sha1 = "66ee25018081b7378b9ed4c8d50a251788f33219"
git-tree-sha1 = "cd7bfb8871504ba2a6cf24f507f68dc697b57331"

[[publish_theme_default.download]]
sha256 = "233b90dd4f4427bd1d165c3e77f49f9b9e0037b427fe8ca3a11b0f129118c97c"
url = "https://github.com/MichaelHatherly/PublishThemes/releases/download/default-0.2.1/default-0.2.1.tar.gz"
sha256 = "587b898ce982508a6a8acf132bae63c656d7bedc75fad8fcc7c739ac803ed34f"
url = "https://github.com/MichaelHatherly/PublishThemes/releases/download/default-0.2.2/default-0.2.2.tar.gz"
34 changes: 34 additions & 0 deletions src/cells.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,40 @@ function Base.show(io::IO, ::MIME"text/latex", f::Objects.Figure)
throw(ErrorException("cannot display type $(typeof(f.object)) as a figure."))
end

function Base.show(io::IO, ::MIME"text/latex", f::Objects.Figure{Matrix{T}}) where T
objects = f.object
for mime in SUPPORTED_MIMES[:latex]
if all(object -> showable(mime, object), objects)
f.landscape && println(io, "\\begin{landscape}")
println(io, "\\begin{figure}[$(f.placement)]")
# Write out the objects left to right.
println(io, "\\begin{tabular}{$(repeat('c', size(objects, 2)))}")
M, N = size(objects)
max_height = round(1 / M; digits = 2)
max_width = round(1 / N; digits = 2)
for row in eachrow(objects)
for (ith, object) in enumerate(row)
filename = string(hash(object), _ext(mime))
open(filename, "w") do handle
Base.invokelatest(show, handle, mime, object)
end
print(io, "\\includegraphics[max width=$(max_width)\\textwidth,max height=$(max_height)\\textheight,valign=m]{./$filename}")
ith < N ? print(io, " & ") : println(io, "\\\\")
end
end
println(io, "\\end{tabular}")
if !isempty(f.caption)
desc = isempty(f.desc) ? "" : "[$(f.desc)]"
println(io, "\\caption$(desc){$(f.caption)}")
end
println(io, "\\end{figure}")
f.landscape && println(io, "\\end{landscape}")
return nothing
end
end
throw(ErrorException("cannot display type $(typeof(f.object)) as a figure."))
end

function Base.show(io::IO, ::MIME"text/html", f::Objects.Figure)
for mime in SUPPORTED_MIMES[:html]
if showable(mime, f.object)
Expand Down

0 comments on commit c7b7d9c

Please sign in to comment.