Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render a latex environment input as a paragraph #1401

Closed
wants to merge 8 commits into from
Closed

render a latex environment input as a paragraph #1401

wants to merge 8 commits into from

Conversation

likanzhan
Copy link
Contributor

Sometimes, the output of a @example block is itself a latex environment, such as a DataFrame.

```@example
using DataFrames
df = DataFrame(i=1:4, y='A':'D', z=5:8);
df
```

In this case, some special characters, such as & and \, are not need escaped, except for the linebreak symbol \\.
This pr intends to do this.
This is related to issue #1346.

@mortenpi mortenpi added the Format: LaTeX Related to the LaTeX / PDF output label Aug 13, 2020
Copy link
Member

@mortenpi mortenpi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediately clear to me what exact issue this fixes. Could you add a small test case to e.g. the latex_simple tests for this? tests_latex.jl builds and tests the LaTeX tests, but you do have to instantiate the test environment.

@@ -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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [begin] syntax was added in 1.4, so this would have to be rewritten as e.g. first(md.content) to be compatible with 1.0.

Add test items for #1401.
@@ -499,8 +499,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}*?}", first(md.content))
Copy link
Member

@mortenpi mortenpi Aug 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elements of md.content are not guaranteed to be strings, so this implementation may throw an error: https://travis-ci.org/github/JuliaDocs/Documenter.jl/jobs/717872752#L320-L329

test/examples/src.latex_simple/index.md Outdated Show resolved Hide resolved
test/examples/src.latex_simple/index.md Show resolved Hide resolved
@mortenpi
Copy link
Member

I took the liberty of updating the tests a bit, so the last inline comment is now attached to the wrong place. However, in the examples:

  1. The Table() does work, but does not render correctly. I think it should be handled here, but isn't for some reason. So this would be nice to have a fix for.
  2. The at-raw block here should render as a table (and does render correctly).
  3. The text example below should not render as a table, because it is semantically just text. To include raw LaTeX, you should use an at-raw block. I am pretty sure that the changes to the Markdown.Paragraph method are unnecessary.

This is how the examples render with master (since this branch currently errors): DocumenterLaTeXSimple.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Format: LaTeX Related to the LaTeX / PDF output
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants