diff --git a/src/Franklin.jl b/src/Franklin.jl index 1d29d60b2..023857b36 100644 --- a/src/Franklin.jl +++ b/src/Franklin.jl @@ -189,6 +189,26 @@ include("parser/latex/blocks.jl") include("parser/html/tokens.jl") include("parser/html/blocks.jl") +function enable_pmath() + a = isexactly("\\(") => :MATH_P_OPEN + b = isexactly("\\)") => :MATH_P_CLOSE + t = MD_TOKENS['\\'] + a in t || push!(t, a) + b in t || push!(t, b) + c = OCProto(:MATH_P, :MATH_P_OPEN, (:MATH_P_CLOSE,)) + c in MD_OCB_MATH || push!(MD_OCB_MATH, c) + return +end +function disable_pmath() + a = isexactly("\\(") => :MATH_P_OPEN + b = isexactly("\\)") => :MATH_P_CLOSE + t = MD_TOKENS['\\'] + c = [e for e in t if !(e in (a, b))] + empty!(t) + append!(t, c) + return +end + # EVAL include("eval/module.jl") include("eval/run.jl") diff --git a/src/converter/markdown/blocks.jl b/src/converter/markdown/blocks.jl index 21cb0eb31..b53311a9d 100644 --- a/src/converter/markdown/blocks.jl +++ b/src/converter/markdown/blocks.jl @@ -57,6 +57,7 @@ the front and the back (`\$` sign). """ const MATH_BLOCKS_PARENS = LittleDict{Symbol, Tuple{Int,Int,String,String}}( :MATH_A => ( 1, 1, "\\(", "\\)"), + :MATH_P => ( 2, 2, "\\(", "\\)"), :MATH_B => ( 2, 2, "\\[", "\\]"), :MATH_C => ( 2, 2, "\\[", "\\]"), :MATH_I => ( 4, 4, "", "") @@ -80,7 +81,7 @@ function convert_math_block(β::OCBlock, lxdefs::Vector{LxDef})::String # if the math block is a "display" one (with a number) inner = chop(β.ss, head=pm[1], tail=pm[2]) htmls = IOBuffer() - if β.name ∉ [:MATH_A, :MATH_I] + if β.name ∉ [:MATH_A, :MATH_P, :MATH_I] # NOTE: in the future if allow equation tags, then will need an `if` # here and only increment if there's no tag. For now just use numbers. diff --git a/src/parser/markdown/tokens.jl b/src/parser/markdown/tokens.jl index 00b9bf5bb..af4665e43 100644 --- a/src/parser/markdown/tokens.jl +++ b/src/parser/markdown/tokens.jl @@ -242,14 +242,18 @@ const MD_OCB_IGNORE = (:COMMENT, :MD_DEF) List of names of maths environments (display mode). """ -const MATH_DISPLAY_BLOCKS_NAMES = collect(e.name for e ∈ MD_OCB_MATH if e.name != :MATH_A) +const MATH_DISPLAY_BLOCKS_NAMES = collect( + e.name for e ∈ MD_OCB_MATH if !(e.name in (:MATH_A, :MATH_P)) +) """ MATH_BLOCKS_NAMES List of names of all maths environments. """ -const MATH_BLOCKS_NAMES = tuple(:MATH_A, MATH_DISPLAY_BLOCKS_NAMES...) +const MATH_BLOCKS_NAMES = tuple( + :MATH_A, :MATH_P, MATH_DISPLAY_BLOCKS_NAMES... +) """ CODE_BLOCKS_NAMES