Browse Source

Replace ``x``-math with $x$-math for notebooks, fixes #116.

pull/190/head
Fredrik Ekre 4 years ago
parent
commit
59689582d4
  1. 6
      CHANGELOG.md
  2. 5
      src/Literate.jl
  3. 9
      test/runtests.jl

6
CHANGELOG.md

@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- "Markdown stdlib-style" inline math (e.g. ``` ``f(x) = x^2`` ```) is now replaced with
"notebook style" math (`$f(x) = x^2$`) for notebook output. This is already the case for
display math (```` ```math ````). ([#116][github-116], [#190][github-190])
### Fixed
- Lines with trailing `#hide` are not shown in output of Markdown execution with Documenter
flavour. ([#188][github-188])
@ -163,6 +167,7 @@ https://discourse.julialang.org/t/ann-literate-jl/10651 for release announcement @@ -163,6 +167,7 @@ https://discourse.julialang.org/t/ann-literate-jl/10651 for release announcement
[dc409d0]: https://github.com/fredrikekre/Literate.jl/commit/dc409d0f43a6282bee4e28e8e12bb6309942e5d5
[ceff7a3]: https://github.com/fredrikekre/Literate.jl/commit/ceff7a36be2a9152d853257bac97be00d915ba8e
[github-116]: https://github.com/fredrikekre/Literate.jl/issues/116
[github-144]: https://github.com/fredrikekre/Literate.jl/issues/144
[github-145]: https://github.com/fredrikekre/Literate.jl/pull/145
[github-146]: https://github.com/fredrikekre/Literate.jl/pull/146
@ -186,6 +191,7 @@ https://discourse.julialang.org/t/ann-literate-jl/10651 for release announcement @@ -186,6 +191,7 @@ https://discourse.julialang.org/t/ann-literate-jl/10651 for release announcement
[github-185]: https://github.com/fredrikekre/Literate.jl/issues/185
[github-186]: https://github.com/fredrikekre/Literate.jl/pull/186
[github-187]: https://github.com/fredrikekre/Literate.jl/pull/187
[github-190]: https://github.com/fredrikekre/Literate.jl/pull/190
[Unreleased]: https://github.com/fredrikekre/Literate.jl/compare/v2.12.1...HEAD
[2.12.1]: https://github.com/fredrikekre/Literate.jl/compare/v2.12.0...v2.12.1

5
src/Literate.jl

@ -173,7 +173,7 @@ function replace_default(content, sym; @@ -173,7 +173,7 @@ function replace_default(content, sym;
if sym === :md
push!(repls, r"^#(md|!nb|!jl) "m => "") # remove leading #md, #!nb, and #!jl
push!(repls, r" #(md|!nb|!jl)$"m => "") # remove trailing #md, #!nb, and #!jl
push!(repls, r" #(md|!nb|!jl)$"m => "") # remove trailing #md, #!nb, and #!jl
push!(repls, r"^#(!md|nb|jl).*\n?"m => "") # remove leading #!md, #nb and #jl lines
push!(repls, r".*#(!md|nb|jl)$\n?"m => "") # remove trailing #!md, #nb, and #jl lines
elseif sym === :nb
@ -181,7 +181,9 @@ function replace_default(content, sym; @@ -181,7 +181,9 @@ function replace_default(content, sym;
push!(repls, r" #(!md|nb|!jl)$"m => "") # remove trailing #!md, #nb, and #!jl
push!(repls, r"^#(md|!nb|jl).*\n?"m => "") # remove leading #md, #!nb and #jl lines
push!(repls, r".*#(md|!nb|jl)$\n?"m => "") # remove trailing #md, #!nb, and #jl lines
# Replace Markdown stdlib math environments
push!(repls, r"```math(.*?)```"s => s"$$\1$$")
push!(repls, r"(?<!`)``([^`]+?)``(?!`)" => s"$\1$")
else # sym === :jl
push!(repls, r"^#(!md|!nb|jl) "m => "") # remove leading #!md, #!nb, and #jl
push!(repls, r" #(!md|!nb|jl)$"m => "") # remove trailing #!md, #!nb, and #jl
@ -193,7 +195,6 @@ function replace_default(content, sym; @@ -193,7 +195,6 @@ function replace_default(content, sym;
push!(repls, "@__NAME__" => config["name"]::String)
# fix links
if get(ENV, "DOCUMENTATIONGENERATOR", "") == "true"
## DocumentationGenerator.jl
base_url = get(ENV, "DOCUMENTATIONGENERATOR_BASE_URL", "DOCUMENTATIONGENERATOR_BASE_URL")

9
test/runtests.jl

@ -221,7 +221,8 @@ content = """ @@ -221,7 +221,8 @@ content = """
## PLACEHOLDER3
## PLACEHOLDER4
# Some math:
# Some inline math: ``\\frac{df}{dx}``, some multiline inline math: ``y =
# kx + m``, and some display math:
# ```math
# \\int f(x) dx
# ```
@ -580,7 +581,8 @@ end end @@ -580,7 +581,8 @@ end end
# PLACEHOLDER4
````
Some math:
Some inline math: ``\\frac{df}{dx}``, some multiline inline math: ``y =
kx + m``, and some display math:
```math
\\int f(x) dx
```
@ -994,7 +996,8 @@ end end @@ -994,7 +996,8 @@ end end
"""
"source": [
"Some math:\\n",
"Some inline math: \$\\\\frac{df}{dx}\$, some multiline inline math: \$y =\\n",
"kx + m\$, and some display math:\\n",
"\$\$\\n",
"\\\\int f(x) dx\\n",
"\$\$"

Loading…
Cancel
Save