Fix issues discussed in #11

This commit is contained in:
Martin Pépin 2016-04-13 21:26:11 +02:00
parent 5d0cd2d54e
commit 1d60b9bb3a
5 changed files with 10 additions and 64 deletions

View File

@ -4,7 +4,7 @@ ASCIIMATH=filters/asciimath/pandoc-asciimath
HS_FILTERS_NAMES =
PY_FILTERS_NAMES = pandoc-svg.py
EXT_FILTERS = $(ASCIIMATH)
EXT_FILTERS = pandoc-crossref $(ASCIIMATH)
HS_FILTERS = $(addprefix filters/, $(HS_FILTERS_NAMES))
PY_FILTERS = $(addprefix filters/, $(PY_FILTERS_NAMES))
@ -21,7 +21,7 @@ $(HS_FILTERS):
ghc --make $@.hs -o $@
$(ASCIIMATH):
(cd filters/asciimath; make)
(cd filters/asciimath; make filter-only)
clean:
rm -f $(OUT)

@ -1 +1 @@
Subproject commit d68cf88317451fc4ae04244802a0992afe91b6b7
Subproject commit 18483581cecdbffe97810eb0e7292c030fcbf4d9

View File

@ -1,26 +0,0 @@
-- nice-frac.hs
import Text.Pandoc.JSON
import Text.Regex
-- Usefull regex elements
space :: String
space = "[ \\t\\n\\r]*"
num :: String
num = "([0-9]+)"
-- Replace fractions like "(42 / 1)" by "\frac{42}{1}"
fracReg :: Regex
fracReg = mkRegex $
"\\(" ++ space ++ num ++ space ++ "/" ++ space ++ num ++ space ++ "\\)"
frac :: String -> String
frac s = subRegex fracReg s "\\\\frac{\\1}{\\2}"
-- Apply the substitution to all Latex parts on the AST
niceFrac :: Inline -> Inline
niceFrac (Math t s) = Math t (frac s)
niceFrac x = x
main :: IO ()
main = toJSONFilter niceFrac

View File

@ -1,33 +0,0 @@
-- usual-fun.hs
import Text.Pandoc.JSON
import Text.Regex
import Data.List (intercalate)
-- Association list for usual functions
usual :: String
usual = intercalate "|" [
"cos", "sin", "tan", "cotan",
"arccos", "arcsin", "arctan",
"exp", "log"]
-- Remove the '\' before usual functions' names if present
rmBSReg :: Regex
rmBSReg = mkRegex $ "(\\\\)(" ++ usual ++ ")\\>"
rmBS :: String -> String
rmBS s = subRegex rmBSReg s "\\2"
-- Add a '\' before usual functions' names
addBSReg :: Regex
addBSReg = mkRegex $ "\\<(" ++ usual ++ ")\\>"
addBS :: String -> String
addBS s = subRegex addBSReg s "\\\\\\0"
-- Apply the substitution to all Latex parts on the AST
niceFrac :: Inline -> Inline
niceFrac (Math t s) = Math t (addBS . rmBS $ s)
niceFrac x = x
main :: IO ()
main = toJSONFilter niceFrac

View File

@ -1,7 +1,7 @@
---
# Metadata
title: Example
author: Martin Pépin
author: Kerl13 & Phyks
date: \today
# Pandoc-crossref options
cref: True
@ -12,5 +12,10 @@ chapters: True
# AsciiMath example
Soit $n in NN$, alors on a
The following asciimath code
sum_(k=1)^n k^3 = ((n(n+1))/2)^2
will be rendered the following way
$$ sum_(k=1)^n k^3 = ((n(n+1))/2)^2 $$