diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2014, Timo von Holtz
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+* Neither the name of the {organization} nor the names of its
+  contributors may be used to endorse or promote products derived from
+  this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+lhslatex
+========
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/lhslatex.cabal b/lhslatex.cabal
new file mode 100644
--- /dev/null
+++ b/lhslatex.cabal
@@ -0,0 +1,29 @@
+-- Initial lhslatex.cabal generated by cabal init.  For further 
+-- documentation, see http://haskell.org/cabal/users-guide/
+
+name:                lhslatex
+version:             0.1.0.0
+synopsis:            Tool for using pdflatex with .lhs files
+description:         Tool for using pdflatex with .lhs files
+homepage:            https://github.com/tvh/lhslatex
+license:             BSD3
+license-file:        LICENSE
+author:              Timo von Holtz
+maintainer:          tvh@tvholtz.de
+-- copyright:           
+-- category:            
+build-type:          Simple
+extra-source-files:  README.md
+cabal-version:       >=1.10
+
+executable lhslatex
+  main-is: lhslatex.hs            
+  -- other-modules:       
+  -- other-extensions:    
+  build-depends:       base >=4.6 && <4.8,
+                       process >= 1.2,
+                       filepath >= 1.3,
+                       regex-posix >= 0.95,
+                       directory >= 1.2
+  -- hs-source-dirs:      
+  default-language:    Haskell2010
diff --git a/lhslatex.hs b/lhslatex.hs
new file mode 100644
--- /dev/null
+++ b/lhslatex.hs
@@ -0,0 +1,55 @@
+import System.Directory
+import System.Environment
+import Text.Regex.Posix
+import System.FilePath.Posix
+import Data.List
+import System.Process
+import Control.Monad
+
+createTmpDir :: FilePath -> IO FilePath
+createTmpDir base = do
+  let dir = addExtension base ".XXXXXXXXXX"
+  exists <- doesDirectoryExist dir
+  when exists $ removeDirectoryRecursive dir
+  createDirectory dir
+  return dir
+
+splitArgs :: [String] -> (String,[String])
+splitArgs args =
+  let (file, args') = partition (=~ "\\.lhs$") args
+      file' = case file of
+                [f] -> f
+                _   -> error "could not identify .lhs file"
+      (stem,_) = splitExtension file'
+  in (stem, args')
+
+moveFile :: FilePath -> FilePath -> IO ()
+moveFile fp1 fp2 = do
+--  error $ show (fp1,fp2)
+  exists <- doesFileExist fp2
+  when exists (removeFile fp2)
+  renameFile fp1 fp2
+
+main :: IO ()
+main = do
+  args <- getArgs
+  let (stem,args') = splitArgs args
+      file = addExtension stem ".lhs"
+      texFile = addExtension stem ".tex"
+      pdfFile = addExtension stem ".pdf"
+      auxFile = addExtension stem ".aux"
+  old_dir <- getCurrentDirectory
+  tmp_dir <- createTmpDir (old_dir </> "lhslatex")
+  tInputs' <- lookupEnv "TEXINPUTS"
+  let tInputs = case tInputs' of
+                  Just e  -> e
+                  Nothing -> ""
+  setEnv "TEXINPUTS" $ old_dir ++ ":" ++ tInputs
+  lhsFile <- readFile file
+  setCurrentDirectory tmp_dir
+  tex <- readProcess "lhs2TeX" ["-"] lhsFile
+  writeFile texFile tex
+  callProcess "pdflatex" (args' ++ [texFile])
+  moveFile (tmp_dir </> pdfFile) (old_dir </> pdfFile)
+  moveFile (tmp_dir </> auxFile) (old_dir </> auxFile)
+  removeDirectoryRecursive tmp_dir
