Skip to content

Commit

Permalink
addresses issue #986
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Nov 25, 2022
1 parent bbc867b commit 0911597
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/Franklin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion src/converter/markdown/blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, "", "")
Expand All @@ -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.

Expand Down
8 changes: 6 additions & 2 deletions src/parser/markdown/tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0911597

Please sign in to comment.