Update: Hakyll API changed in 4.10 version, so the code below would require changes. See commit as example of the changes.

Recently I’ve checked a list of manuals for pandoc and latex, but they were quite outdated.

The problems that by default pandoc tries to use utf only to render formulas but it doesn’t work in many cases. Best solution would be mathjax as it will work in majority of brousers unlike mathml.

To set up hakyll to use latex one needs to set pandoc compiler options:

    -- ...
    compile \$ pandocCompilerWith defaultHakyllReaderOptions pandocOptions 
    -- ...

pandocOptions :: WriterOptions
pandocOptions = defaultHakyllWriterOptions{ writerHTMLMathMethod = MathJax "" }

But you will have to add mathjax url to pages where you have math, and do nothing at pages without. So you can add a special marker to page header

mathjax: on

and then add a special context that will check marker it sill populate field mathjax with either script url or nothing

mathCtx :: Context a
mathCtx = field "mathjax" $ \item -> do
    metadata <- getMetadata $ itemIdentifier item
    return $ if "mathjax" `M.member` metadata
                  then "<script type=\"text/javascript\" src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>"
                  else ""

now you need to add $mathjax$ value to your tempate and add math context to your context (I’ve used default.html)

    <script src="/js/bootstrap.min.js"></script>
  match "posts/*" $ do
      route $ setExtension ".html"
      compile $ pandocCompilerWith defaultHakyllReaderOptions pandocOptions 
         >>= saveSnapshot "content"
         >>= return . fmap demoteHeaders
         >>= loadAndApplyTemplate "templates/post.html" (postCtx tags)
         >>= loadAndApplyTemplate "templates/default.html" (mathCtx `mappend` defaultContext)
         >>= relativizeUrls

that’s all


\[M_1=\sqrt{\dfrac{(1-q_1)(1-q_2)}{2\beta_1(q_1-q_2)}}\,H_2^{1/4}\,,\qquad M_2=\sqrt{\dfrac{(1+q_1)(1+q_2)}{2\beta_2(q_2-q_1)}}\,H_2^{1/4}\,,\] and \[{\gamma}_3=\dfrac{2\varkappa H_2^{1/4}}{\sqrt{2(\beta_1-\beta_2)(q_2-q_1)}}\,.\] Such as \(C_1=0\) and \[\dot{q}_k=\{H,q_k\}=-\dfrac{4\beta_1p_2M_1(1+q_k)}{{\gamma}_3}-\dfrac{4\beta_2{\gamma}_1M_2(1-q_k)}{{\gamma}_3}\,,\]

comments powered by Disqus