Skip to content

Commit

Permalink
Fix printing of LaTeX markdown to IPython and plain text.
Browse files Browse the repository at this point in the history
  • Loading branch information
malmaud committed May 26, 2015
1 parent 96cc970 commit 5cf6938
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions base/markdown/IPython/IPython.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ end
writemime(io::IO, ::MIME"text/plain", tex::LaTeX) =
print(io, '$', tex.formula, '$')

latex(io::IO, tex::LaTeX) =
print(io, "\$\$", tex.formula, "\$\$")

latexinline(io::IO, tex::LaTeX) =
print(io, '$', tex.formula, '$')

term(io::IO, tex::LaTeX, cols) = println_with_format(:magenta, io, tex.formula)
terminline(io::IO, tex::LaTeX) = print_with_format(:magenta, io, tex.formula)
2 changes: 2 additions & 0 deletions base/markdown/render/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function plain(io::IO, md::HorizontalRule)
println(io, "" ^ 3)
end

plain(io::IO, md) = writemime(io, "text/plain", md)

# Inline elements

plaininline(x) = sprint(plaininline, x)
Expand Down
17 changes: 16 additions & 1 deletion test/markdown.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of Julia. License is MIT: http:https://julialang.org/license

using Base.Markdown
import Base.Markdown: MD, Paragraph, Header, Italic, Bold, plain, term, html, Table, Code
import Base.Markdown: MD, Paragraph, Header, Italic, Bold, plain, term, html, Table, Code, LaTeX
import Base: writemime

# Basics
Expand Down Expand Up @@ -176,3 +176,18 @@ t = """a | b
1 | 2
"""
@test plain(Markdown.parse(t)) == t


# LaTeX extension
latex_doc = md"""
We have $x^2 < x$ whenever:
$|x| < 1$"""

@test latex_doc == MD(Any[Paragraph(Any["We have ",
LaTeX("x^2 < x"),
" whenever:"]),
LaTeX("|x| < 1")])


@test latex(latex_doc) == "We have \$x^2 < x\$ whenever:\n\$\$|x| < 1\$\$"

0 comments on commit 5cf6938

Please sign in to comment.