ChrisPenner / slick

Static site generator built on Shake configured in Haskell
BSD 3-Clause "New" or "Revised" License
204 stars 24 forks source link

How to enable latex? #11

Closed locallycompact closed 4 years ago

locallycompact commented 4 years ago

Hi, I've been experimenting with a fork of this for gitlab here. I thought that this commit might work to enable MathJax, but it doesn't (output here). What's the right idea?

ChrisPenner commented 4 years ago

Not positive, but I suspect the issue is with the Reader, not the writer. You'll probably need to enable one or more of the tex extensions.

You can edit ReaderOptions to include extra extensions then pass them into the markdown reader.

Hopefully that'll sort you out :+1:, the default markdown reader is basically just for Github Markdown, so if you want more extensions you just need to pass them as options 😄

dhess commented 4 years ago

@locallycompact You need something like this:

readerOptions :: ReaderOptions
readerOptions = def { readerExtensions = exts }
 where
  exts = mconcat
    [extensionsFromList [Ext_tex_math_single_backslash], pandocExtensions]

writerOptions :: WriterOptions
writerOptions = def { writerExtensions     = exts
                    , writerHTMLMathMethod = KaTeX defaultKaTeXURL
                    , writerSectionDivs    = True
                    , writerTemplate       = Just $ T.unpack tmpl
                    }
 where
  exts = mconcat [extensionsFromList [Ext_smart], getDefaultExtensions "html5"]

Here I've used KaTeX rather than MathJax, but the idea is the same. (You'll want to use defaultMathJaxURL rather than defaultKaTeXURL, as well.)

You can ignore the writerTemplate and writerSectionDivs; I needed those to get the Tufte CSS Pandoc stuff to render properly.