From 59689582d4da50eb764be83879748bb6a923de35 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 18 Feb 2022 12:48:29 +0100 Subject: [PATCH] Replace ``x``-math with $x$-math for notebooks, fixes #116. --- CHANGELOG.md | 6 ++++++ src/Literate.jl | 5 +++-- test/runtests.jl | 9 ++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e488fb0..da7a45f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 [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 [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 diff --git a/src/Literate.jl b/src/Literate.jl index 91bfa44..3301ae9 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -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; 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; 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") diff --git a/test/runtests.jl b/test/runtests.jl index 7784c13..b5eebae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 # 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 """ "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", "\$\$"