summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Site.hs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/Site.hs b/src/Site.hs
index bf501d8..9b08316 100644
--- a/src/Site.hs
+++ b/src/Site.hs
@@ -5,7 +5,7 @@ import Hakyll
5import Data.Monoid (Monoid(..), mconcat, (<>)) 5import Data.Monoid (Monoid(..), mconcat, (<>))
6import Control.Monad (liftM, forM_, (<=<)) 6import Control.Monad (liftM, forM_, (<=<))
7import Data.Char (toLower, isSpace, isAlphaNum) 7import Data.Char (toLower, isSpace, isAlphaNum)
8import Data.Maybe (mapMaybe, fromMaybe) 8import Data.Maybe (mapMaybe, fromMaybe, listToMaybe)
9import Data.Map (Map) 9import Data.Map (Map)
10import qualified Data.Map as Map 10import qualified Data.Map as Map
11import qualified Data.Set as Set 11import qualified Data.Set as Set
@@ -19,6 +19,7 @@ import Control.Applicative (Alternative(..), Applicative(..))
19import Text.Blaze.Html (toHtml, toValue, (!)) 19import Text.Blaze.Html (toHtml, toValue, (!))
20import qualified Text.Blaze.Html5 as H 20import qualified Text.Blaze.Html5 as H
21import qualified Text.Blaze.Html5.Attributes as A 21import qualified Text.Blaze.Html5.Attributes as A
22import Text.Read (readMaybe)
22 23
23import System.FilePath (takeBaseName, (</>), (<.>)) 24import System.FilePath (takeBaseName, (</>), (<.>))
24 25
@@ -30,6 +31,8 @@ import Data.Char (toLower)
30import Tex (compileTex) 31import Tex (compileTex)
31import Text.Printf (printf) 32import Text.Printf (printf)
32 33
34import Text.Regex.TDFA ((=~))
35
33main :: IO () 36main :: IO ()
34main = hakyllWith config $ do 37main = hakyllWith config $ do
35 match "templates/*" $ compile templateCompiler 38 match "templates/*" $ compile templateCompiler
@@ -225,8 +228,17 @@ texTransform = walkM texTransformInline <=< walkM texTransformBlock
225 let 228 let
226 texId = texTranslation' $ texT tex 229 texId = texTranslation' $ texT tex
227 alignment <- loadSnapshotBody texId "alignment" 230 alignment <- loadSnapshotBody texId "alignment"
228 return $ printf "<object data=\"/%s\" type=\"image/svg+xml\" style=\"vertical-align:-%s\">%s</object>" 231 content <- loadBody texId
229 (toFilePath texId) (alignment :: String) tex 232 let
233 latexFontSize :: Double
234 latexFontSize = 12 / 1.25
235 match = (=~) :: String -> String -> (String, String, String, [String])
236 size = case match content "height='([-0-9\\.]+)pt' .* width='([-0-9\\.]+)pt'" of
237 (_, _, _, xs@[_, _]) -> (\[y, x] -> (x / latexFontSize, y / latexFontSize)) <$> mapM (readMaybe :: String -> Maybe Double) xs
238 _ -> Nothing
239 size' = maybe "" (\(a, b) -> printf " width:%.2fem; height:%.2fem;" a b) size
240 return $ printf "<object data=\"/%s\" type=\"image/svg+xml\" style=\"vertical-align:-%s;%s\">%s</object>"
241 (toFilePath texId) (alignment :: String) (size' :: String) tex
230 classOf DisplayMath = "display-math" 242 classOf DisplayMath = "display-math"
231 classOf InlineMath = "inline-math" 243 classOf InlineMath = "inline-math"
232 244