From b8cf052e008858d189692b981528874010e77ff9 Mon Sep 17 00:00:00 2001 From: Likan Zhan Date: Fri, 14 Aug 2020 00:44:48 +0800 Subject: [PATCH 1/5] render a latex environment input as a paragraph --- src/Writers/LaTeXWriter.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Writers/LaTeXWriter.jl b/src/Writers/LaTeXWriter.jl index 12d89e3ab8..736632a469 100644 --- a/src/Writers/LaTeXWriter.jl +++ b/src/Writers/LaTeXWriter.jl @@ -498,8 +498,15 @@ function _print_code_escapes_inline(io, s::AbstractString) end function latex(io::IO, md::Markdown.Paragraph) - for md in md.content - latexinline(io, md) + if occursin(r"^\h*?\\begin{\p{Xan}*?}", md.content[begin]) + for md in md.content + md = Base.replace(md, r"\\$" => "\\\\") + Base.print(io.io, md) + end + else + for md in md.content + latexinline(io, md) + end end _println(io, "\n") end From 40ca0933ef0da5b454a84bd10a63f8600b73e028 Mon Sep 17 00:00:00 2001 From: Likan Zhan Date: Fri, 14 Aug 2020 11:28:24 +0800 Subject: [PATCH 2/5] Add test items for #1401 Add test items for #1401. --- test/examples/src.latex_simple/index.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/examples/src.latex_simple/index.md b/test/examples/src.latex_simple/index.md index 245d397cac..38ce450f55 100644 --- a/test/examples/src.latex_simple/index.md +++ b/test/examples/src.latex_simple/index.md @@ -28,3 +28,26 @@ julia> 127 % Int8 ```julia-repl sayhello2 julia> function foo end; ``` + +## Issue 1400 + +1. The output is a latex tabular environment + +```@example +using DataFrames +DataFrame(i=1:3, y='A':'C') +``` + +2. The paragraph itself is a latex tabular environment + +\begin{tabular}{r|ccc} + & i & y & z\\ + \hline + & Int64 & Char & Int64\\ + \hline + 1 & 1 & 'A' & 5 \\ + 2 & 2 & 'B' & 6 \\ + 3 & 3 & 'C' & 7 \\ + 4 & 4 & 'D' & 8 \\ +\end{tabular} + From a6eb376803c67888797a4ab41f67d2d9246da9f4 Mon Sep 17 00:00:00 2001 From: Likan Zhan Date: Fri, 14 Aug 2020 11:34:56 +0800 Subject: [PATCH 3/5] `md.content[begin]` => first(md.content) --- src/Writers/LaTeXWriter.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Writers/LaTeXWriter.jl b/src/Writers/LaTeXWriter.jl index 736632a469..248bf4ab41 100644 --- a/src/Writers/LaTeXWriter.jl +++ b/src/Writers/LaTeXWriter.jl @@ -498,7 +498,7 @@ function _print_code_escapes_inline(io, s::AbstractString) end function latex(io::IO, md::Markdown.Paragraph) - if occursin(r"^\h*?\\begin{\p{Xan}*?}", md.content[begin]) + if occursin(r"^\h*?\\begin{\p{Xan}*?}", first(md.content)) for md in md.content md = Base.replace(md, r"\\$" => "\\\\") Base.print(io.io, md) From c02d7b21fe2b32fa31e0fb2a825f5ad533131d23 Mon Sep 17 00:00:00 2001 From: Likan Zhan Date: Fri, 14 Aug 2020 11:39:46 +0800 Subject: [PATCH 4/5] Correct a typo --- test/examples/src.latex_simple/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/examples/src.latex_simple/index.md b/test/examples/src.latex_simple/index.md index 38ce450f55..70412ad5a8 100644 --- a/test/examples/src.latex_simple/index.md +++ b/test/examples/src.latex_simple/index.md @@ -29,7 +29,7 @@ julia> 127 % Int8 julia> function foo end; ``` -## Issue 1400 +## Issue 1401 1. The output is a latex tabular environment From 43f86136b88222c2a95245f6d5407318cd7a9713 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Tue, 25 Aug 2020 15:45:48 +1200 Subject: [PATCH 5/5] Update test examples --- test/examples/src.latex_simple/index.md | 38 +++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/test/examples/src.latex_simple/index.md b/test/examples/src.latex_simple/index.md index 70412ad5a8..9c3f7fd6ab 100644 --- a/test/examples/src.latex_simple/index.md +++ b/test/examples/src.latex_simple/index.md @@ -29,17 +29,30 @@ julia> 127 % Int8 julia> function foo end; ``` -## Issue 1401 +## Issue 1401: rendering custom LaTeX -1. The output is a latex tabular environment +### @example block / show with `text/latex` MIME ```@example -using DataFrames -DataFrame(i=1:3, y='A':'C') +struct Table end +Base.show(io, ::MIME"text/latex", ::Table) = write(io, raw""" +begin{tabular}{r|ccc} + & i & y & z\\ + \hline + & Int64 & Char & Int64\\ + \hline + 1 & 1 & 'A' & 5 \\ + 2 & 2 & 'B' & 6 \\ + 3 & 3 & 'C' & 7 \\ + 4 & 4 & 'D' & 8 \\ +\end{tabular} +""") +Table() ``` -2. The paragraph itself is a latex tabular environment +### @raw block +```@raw latex \begin{tabular}{r|ccc} & i & y & z\\ \hline @@ -50,4 +63,19 @@ DataFrame(i=1:3, y='A':'C') 3 & 3 & 'C' & 7 \\ 4 & 4 & 'D' & 8 \\ \end{tabular} +``` + +### Inline LaTeX +_Note: this should render as just text, not as a table._ + +\begin{tabular}{r|ccc} + & i & y & z\\ + \hline + & Int64 & Char & Int64\\ + \hline + 1 & 1 & 'A' & 5 \\ + 2 & 2 & 'B' & 6 \\ + 3 & 3 & 'C' & 7 \\ + 4 & 4 & 'D' & 8 \\ +\end{tabular}