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

Strip out $$ as well #1426

Merged
merged 15 commits into from
Oct 28, 2020
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Documenter.jl changelog

## Version `v0.26.0`

* ![Enhancement][badge-enhancement] Objects that render as equations and whose `text/latex` representations are wrapped in display equation delimiters `\[ ... \]` or `$$ ... $$` are now handled correctly in the HTML output. ([#1278][github-1278], [#1283][github-1283], [#1426][github-1426])

## Version `v0.25.3`

* ![Feature][badge-feature] Documenter can now deploy from GitLab CI to GitHub Pages with `Documenter.GitLab`. ([#1448][github-1448])
Expand Down Expand Up @@ -627,8 +631,10 @@
[github-1258]: https://github.com/JuliaDocs/Documenter.jl/pull/1258
[github-1264]: https://github.com/JuliaDocs/Documenter.jl/pull/1264
[github-1269]: https://github.com/JuliaDocs/Documenter.jl/pull/1269
[github-1278]: https://github.com/JuliaDocs/Documenter.jl/issues/1278
[github-1279]: https://github.com/JuliaDocs/Documenter.jl/issues/1279
[github-1280]: https://github.com/JuliaDocs/Documenter.jl/pull/1280
[github-1283]: https://github.com/JuliaDocs/Documenter.jl/pull/1283
[github-1285]: https://github.com/JuliaDocs/Documenter.jl/pull/1285
[github-1292]: https://github.com/JuliaDocs/Documenter.jl/pull/1292
[github-1293]: https://github.com/JuliaDocs/Documenter.jl/pull/1293
Expand All @@ -651,6 +657,7 @@
[github-1357]: https://github.com/JuliaDocs/Documenter.jl/pull/1357
[github-1360]: https://github.com/JuliaDocs/Documenter.jl/pull/1360
[github-1362]: https://github.com/JuliaDocs/Documenter.jl/issues/1362
[github-1364]: https://github.com/JuliaDocs/Documenter.jl/issues/1364
[github-1365]: https://github.com/JuliaDocs/Documenter.jl/pull/1365
[github-1367]: https://github.com/JuliaDocs/Documenter.jl/pull/1367
[github-1368]: https://github.com/JuliaDocs/Documenter.jl/pull/1368
Expand All @@ -660,11 +667,11 @@
[github-1389]: https://github.com/JuliaDocs/Documenter.jl/pull/1389
[github-1392]: https://github.com/JuliaDocs/Documenter.jl/pull/1392
[github-1400]: https://github.com/JuliaDocs/Documenter.jl/pull/1400
[github-1426]: https://github.com/JuliaDocs/Documenter.jl/pull/1426
[github-1428]: https://github.com/JuliaDocs/Documenter.jl/issues/1428
[github-1430]: https://github.com/JuliaDocs/Documenter.jl/pull/1430
[github-1438]: https://github.com/JuliaDocs/Documenter.jl/issues/1438
[github-1364]: https://github.com/JuliaDocs/Documenter.jl/issues/1364
[github-1435]: https://github.com/JuliaDocs/Documenter.jl/pull/1435
[github-1438]: https://github.com/JuliaDocs/Documenter.jl/issues/1438
[github-1448]: https://github.com/JuliaDocs/Documenter.jl/pull/1448
[github-1440]: https://github.com/JuliaDocs/Documenter.jl/pull/1440
[github-1452]: https://github.com/JuliaDocs/Documenter.jl/pull/1452
Expand Down
13 changes: 12 additions & 1 deletion src/Writers/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,18 @@ function mdconvert(d::Dict{MIME,Any}, parent; kwargs...)
elseif haskey(d, MIME"image/jpeg"())
out = Documents.RawHTML(string("<img src=\"data:image/jpeg;base64,", d[MIME"image/jpeg"()], "\" />"))
elseif haskey(d, MIME"text/latex"())
out = Utilities.mdparse(d[MIME"text/latex"()]; mode = :single)
# If the show(io, ::MIME"text/latex", x) output is already wrapped in \[ ... \] or $$ ... $$, we
# unwrap it first, since when we output Markdown.LaTeX objects we put the correct
# delimiters around it anyway.
latex = d[MIME"text/latex"()]
equation = false
m_bracket = match(r"\s*\\\[(.*)\\\]\s*", latex)
m_dollars = match(r"\s*\$\$(.*)\$\$\s*", latex)
if m_bracket === nothing && m_dollars === nothing
out = Utilities.mdparse(latex; mode = :single)
else
out = Markdown.LaTeX(m_bracket !== nothing ? m_bracket[1] : m_dollars[1])
end
elseif haskey(d, MIME"text/markdown"())
out = Markdown.parse(d[MIME"text/markdown"()])
elseif haskey(d, MIME"text/plain"())
Expand Down
30 changes: 30 additions & 0 deletions test/examples/src/man/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,33 @@ Hello World!
Written in <a href="https://fonts.google.com/specimen/Nanum+Brush+Script">Nanum Brush Script.</a>
</div>
```

## Handling of `text/latex`

You can define a type that has a `Base.show` method for the `text/latex` MIME:

```@example showablelatex
struct LaTeXEquation
code :: String
end
Base.show(io, ::MIME"text/latex", latex::LaTeXEquation) = write(io, latex.code)
nothing # hide
```

In an `@example` or `@eval` block, it renders as an equation:

```@example showablelatex
LaTeXEquation(raw"Foo $x^2$ bar.")
```

Documenter also supports having the LaTeX text being already wrapped in `\[ ... \]`:

```@example showablelatex
LaTeXEquation(raw"\[\left[ \begin{array}{rr}x&2 x\end{array}\right]\]")
```

or wrapped in `$$ ... $$`:

```@example showablelatex
LaTeXEquation(raw"$$\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}$$")
```