Skip to content

Commit

Permalink
Merge pull request #11124 from malmaud/fix_latex
Browse files Browse the repository at this point in the history
Fix printing of LaTeX markdown to IPython and plain text.
  • Loading branch information
MikeInnes committed May 26, 2015
2 parents b05a330 + 5cf6938 commit 42243c4
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://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 42243c4

Please sign in to comment.