Skip to content

Commit

Permalink
Add markdown show() method for Tableau.
Browse files Browse the repository at this point in the history
  • Loading branch information
michakraus committed Nov 27, 2020
1 parent 0b29f3b commit 7b4e101
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/tableau.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,25 @@ function Base.show(io::IO, tab::Tableau)
equal_columns_width = true,
noheader = true)
end

"Markdown-print Runge-Kutta tableau."
function Base.show(io::IO, ::MIME"text/markdown", tab::Tableau)
print(io, "text/markdown", "\nRunge-Kutta Tableau $(tab.name) with $(tab.s) stages and order $(tab.o):\n")

tab_arr = convert(Array{Any}, to_array(tab))
tab_arr[tab.s+1,1] = ""

strio = IOBuffer()
pretty_table(strio, tab_arr,
backend = :latex,
vlines = [1],
hlines = [tab.s],
noheader = true)
tab_latex = String(take!(strio))

tab_markdown = replace(tab_latex, "tabular" => "array")
tab_markdown = replace(tab_markdown, "\\begin{table}" => "```math")
tab_markdown = replace(tab_markdown, "\\end{table}" => "```")

print(io, "text/markdown", "\n" * tab_markdown)
end
1 change: 1 addition & 0 deletions test/test_tableau.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ using RungeKutta: name, order, eachstage, nstages, coefficients, weights, nodes,
@test tab1 == convert(Tableau, convert(Matrix{T}, tab1); name=tab1.name, o=tab1.o)

@test startswith(repr(tab1), "\nRunge-Kutta Tableau")
@test startswith(repr(MIME("text/markdown"), tab1), "text/markdown\nRunge-Kutta Tableau")

end
end
Expand Down

0 comments on commit 7b4e101

Please sign in to comment.