diff --git a/pandoc.cabal b/pandoc.cabal
index 600bb0de4..6c9189774 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -192,7 +192,6 @@ Library
                    Text.Pandoc.Writers.S5,
                    Text.Pandoc.Templates
   Other-Modules:   Text.Pandoc.XML,
-                   Text.Pandoc.TH,
                    Paths_pandoc
   Extensions:      CPP, TemplateHaskell, FlexibleInstances
   Ghc-Options:     -O2 -Wall
diff --git a/src/Text/Pandoc/LaTeXMathML.hs b/src/Text/Pandoc/LaTeXMathML.hs
index 1eb3c23cc..8cdd3cd21 100644
--- a/src/Text/Pandoc/LaTeXMathML.hs
+++ b/src/Text/Pandoc/LaTeXMathML.hs
@@ -1,14 +1,16 @@
-{-# LANGUAGE CPP, TemplateHaskell #-}
 -- | Definitions for use of LaTeXMathML in HTML.  
 -- (See <http://math.etsu.edu/LaTeXMathML/>)
 module Text.Pandoc.LaTeXMathML ( latexMathMLScript ) where
-import Text.Pandoc.TH ( contentsOf )
 import System.FilePath ( (</>) )
+import Text.Pandoc.Shared (readDataFile)
 
 -- | String containing LaTeXMathML javascript.
-latexMathMLScript :: String
-#ifndef __HADDOCK__
-latexMathMLScript = "<script type=\"text/javascript\">\n" ++
-                    $(contentsOf $ "data" </> "LaTeXMathML.js.comment") ++
-                    $(contentsOf $ "data" </> "LaTeXMathML.js.packed") ++ "</script>\n"
-#endif
+latexMathMLScript :: IO String
+latexMathMLScript = undefined
+{-
+latexMathMLScript = do
+ jsCom <- readDataFile $ "data" </> "LaTeXMathML.js.comment"
+ jsPacked <- readDataFile $ "data" </> "LaTeXMathML.js.packed"
+ return $ "<script type=\"text/javascript\">\n" ++ jsCom ++ jsPacked ++
+          "</script>\n"
+-}
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 868edc2c7..e913d5d0b 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -104,7 +104,8 @@ module Text.Pandoc.Shared (
                      WriterOptions (..),
                      defaultWriterOptions,
                      -- * File handling
-                     inDirectory
+                     inDirectory,
+                     readDataFile
                     ) where
 
 import Text.Pandoc.Definition
@@ -122,6 +123,7 @@ import System.IO.UTF8
 import Data.Generics
 import qualified Control.Monad.State as S
 import Control.Monad (join)
+import Paths_pandoc (getDataFileName)
 
 --
 -- List processing
@@ -1030,3 +1032,7 @@ inDirectory path action = do
   result <- action
   setCurrentDirectory oldDir
   return result
+
+-- | Read file from the Cabal data directory.
+readDataFile :: FilePath -> IO String
+readDataFile fname = getDataFileName fname >>= readFile
diff --git a/src/Text/Pandoc/TH.hs b/src/Text/Pandoc/TH.hs
deleted file mode 100644
index dfd6be28b..000000000
--- a/src/Text/Pandoc/TH.hs
+++ /dev/null
@@ -1,53 +0,0 @@
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-{-
-Copyright (C) 2008 John MacFarlane <jgm@berkeley.edu>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
--}
-
-{- |
-   Module      : Text.Pandoc.TH
-   Copyright   : Copyright (C) 2006-8 John MacFarlane
-   License     : GNU GPL, version 2 or above 
-
-   Maintainer  : John MacFarlane <jgm@berkeley.edu>
-   Stability   : alpha
-   Portability : portable
-
-Template haskell functions used by Pandoc modules.
--}
-module Text.Pandoc.TH (
-                        contentsOf,
-                        binaryContentsOf
-                      ) where
-
-import Language.Haskell.TH
-import Language.Haskell.TH.Syntax (Lift (..))
-import qualified Data.ByteString as B
-import Data.ByteString.Internal ( w2c )
-import Prelude hiding ( readFile )
-import System.IO.UTF8
-
--- | Insert contents of text file into a template.
-contentsOf :: FilePath -> ExpQ
-contentsOf p = lift =<< (runIO $ readFile p)
-
--- | Insert contents of binary file into a template.
--- Note that @Data.ByteString.readFile@ uses binary mode on windows.
-binaryContentsOf :: FilePath -> ExpQ
-binaryContentsOf p = lift =<< (runIO $ B.readFile p)
-
-instance Lift B.ByteString where
-  lift x = return (LitE (StringL $ map w2c $ B.unpack x))
diff --git a/src/Text/Pandoc/Templates.hs b/src/Text/Pandoc/Templates.hs
index 98eed7292..75989fbcd 100644
--- a/src/Text/Pandoc/Templates.hs
+++ b/src/Text/Pandoc/Templates.hs
@@ -52,6 +52,7 @@ import System.FilePath
 import System.Directory
 import Prelude hiding (readFile)
 import System.IO.UTF8 (readFile)
+import Text.Pandoc.Shared (readDataFile)
 import Paths_pandoc
 
 -- | Get the default template, either from the application's user data
@@ -73,9 +74,8 @@ getTemplateFromUserDataDirectory format = E.try $ do
   readFile templatePath
 
 getTemplateFromCabalDataDirectory :: String -> IO (Either E.IOException String)
-getTemplateFromCabalDataDirectory format = E.try $ do 
-  templatePath <- getDataFileName $ "templates" </> format <.> "template"
-  readFile templatePath
+getTemplateFromCabalDataDirectory format = E.try $
+  readDataFile $ "templates" </> format <.> "template"
 
 -- | Renders a template 
 renderTemplate :: [(String,String)]  -- ^ Assoc. list of values for variables
diff --git a/src/Text/Pandoc/Writers/S5.hs b/src/Text/Pandoc/Writers/S5.hs
index 6187bc9a8..67ff673c2 100644
--- a/src/Text/Pandoc/Writers/S5.hs
+++ b/src/Text/Pandoc/Writers/S5.hs
@@ -37,7 +37,7 @@ module Text.Pandoc.Writers.S5 (
                 writeS5String,
                 insertS5Structure
                 ) where
-import Text.Pandoc.Shared ( WriterOptions )
+import Text.Pandoc.Shared ( WriterOptions, readDataFile )
 import Text.Pandoc.Writers.HTML ( writeHtml, writeHtmlString )
 import Text.Pandoc.Definition
 import Text.XHtml.Strict
@@ -45,10 +45,6 @@ import System.FilePath ( (</>) )
 import Data.List ( intercalate )
 import Prelude hiding (readFile)
 import System.IO.UTF8 (readFile)
-import Paths_pandoc (getDataFileName)
-
-readDataFile :: FilePath -> IO String
-readDataFile fname = getDataFileName fname >>= readFile
 
 s5HeaderIncludes :: IO String
 s5HeaderIncludes = do