diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright (c) 2013, Takayuki Muranushi
+
+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 Takayuki Muranushi nor the names of other
+      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
+OWNER 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/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/authoring.cabal b/authoring.cabal
new file mode 100644
--- /dev/null
+++ b/authoring.cabal
@@ -0,0 +1,47 @@
+-- Initial authoring.cabal generated by cabal init.  For further 
+-- documentation, see http://haskell.org/cabal/users-guide/
+
+name:                authoring
+version:             0.1.0.0
+synopsis:            A library for writing papers
+description:         This package is parser combinator library for writing papers.
+homepage:            http://github.com/nushio3/authoring
+bug-reports:         http://github.com/nushio3/authoring/issues
+license:             BSD3
+license-file:        LICENSE
+author:              Takayuki Muranushi
+maintainer:          muranushi@gmail.com
+copyright:           (C) Takayuki Muranushi, 2013
+category:            Text
+build-type:          Simple
+cabal-version:       >=1.8
+
+source-repository head
+  type: git
+  location: git://github.com/nushio3/authoring.git
+
+library
+  hs-source-dirs:    src/
+  exposed-modules:     
+    Text.Authoring.Bibliography
+    Text.Authoring.Combinator
+    Text.Authoring.Combinator.Cite
+    Text.Authoring.Combinator.Meta
+    Text.Authoring.Combinator.Ref
+    Text.Authoring.Combinator.Writer
+    Text.Authoring.Document
+    Text.Authoring.Label
+    Text.Authoring.State
+  -- other-modules:       
+  build-depends:
+      base ==4.*
+    , citation-resolve >= 0.4.2
+    , containers >= 0.5
+    , HaTeX >= 3.8
+    , lens
+    , mtl
+    , safe
+    , text
+    , transformers
+
+  
diff --git a/src/Text/Authoring/Bibliography.hs b/src/Text/Authoring/Bibliography.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Authoring/Bibliography.hs
@@ -0,0 +1,20 @@
+module Text.Authoring.Bibliography where
+
+import           Control.Lens (use)
+import           Control.Monad
+import           Control.Monad.State
+import           Control.Monad.IO.Class
+import qualified Data.Set as Set
+import qualified Data.Text as Text
+import           Text.CSL.Input.Identifier (toBibTeXItem, HasDatabase)
+
+import Text.Authoring.State
+
+-- | generate the content for the bibliography file.
+
+bibliographyContent :: (MonadState s m, HasAuthorState s, HasDatabase s, MonadIO m) => m Text.Text
+bibliographyContent = do
+  urls <- use citedUrlSet
+  items <- mapM toBibTeXItem $ Set.toList urls
+  return $ Text.unlines $ items
+    
diff --git a/src/Text/Authoring/Combinator.hs b/src/Text/Authoring/Combinator.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Authoring/Combinator.hs
@@ -0,0 +1,14 @@
+module Text.Authoring.Combinator (
+  
+module Text.Authoring.Combinator.Cite,
+module Text.Authoring.Combinator.Meta,
+module Text.Authoring.Combinator.Ref,
+module Text.Authoring.Combinator.Writer
+                                 
+                                 
+                                 ) where
+
+import Text.Authoring.Combinator.Cite
+import Text.Authoring.Combinator.Meta
+import Text.Authoring.Combinator.Ref
+import Text.Authoring.Combinator.Writer
diff --git a/src/Text/Authoring/Combinator/Cite.hs b/src/Text/Authoring/Combinator/Cite.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Authoring/Combinator/Cite.hs
@@ -0,0 +1,39 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Text.Authoring.Combinator.Cite where
+
+import Control.Lens
+import Control.Monad
+import Control.Monad.State
+import Control.Monad.Writer
+import qualified Data.Set as Set
+import qualified Data.Text as Text
+import Text.CSL.Input.Identifier (resolve, HasDatabase)
+
+
+import Text.Authoring.Combinator.Meta
+import Text.Authoring.Combinator.Writer
+import Text.Authoring.Document
+import Text.Authoring.State
+
+
+citet, citep :: (MonadState s m, HasAuthorState s, HasDatabase s, 
+          MonadWriter w m, HasDocument w, MonadIO m) => [String] -> m ()
+
+citet = citationGen "citet"
+citep = citationGen "citep"
+
+citet1, citep1 :: (MonadState s m, HasAuthorState s, HasDatabase s, 
+          MonadWriter w m, HasDocument w, MonadIO m) => String -> m ()
+
+citet1 = citationGen "citet" . (:[]) -- + ---<===   I am a long man lying
+citep1 = citationGen "citep" . (:[]) -- + ---<===   We are long men lying
+
+-- | make a citation to a document(s).
+citationGen :: (MonadState s m, HasAuthorState s, HasDatabase s, 
+          MonadWriter w m, HasDocument w, MonadIO m) => Text.Text -> [String] -> m ()
+citationGen cmdName  urls = do
+  forM_ urls $ \url -> do
+    _ <- resolve url
+    citedUrlSet %= Set.insert url 
+  command1 cmdName $ braces $ raw $ Text.intercalate "," $ map Text.pack urls
diff --git a/src/Text/Authoring/Combinator/Meta.hs b/src/Text/Authoring/Combinator/Meta.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Authoring/Combinator/Meta.hs
@@ -0,0 +1,43 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Text.Authoring.Combinator.Meta where
+
+import Control.Monad.Writer
+import Data.Text (Text)
+
+import Text.Authoring.Document
+import Text.Authoring.Combinator.Writer
+
+
+-- | wrap the argument @x@ using curly braces "{x}"
+
+braces :: (MonadWriter t m, HasDocument t) => m () -> m ()
+braces con = do
+  raw "{"
+  con
+  raw "}"
+
+  
+-- | command1 x con = "\x{con}"
+
+command1 :: (MonadWriter t m, HasDocument t) =>  Text -> m () -> m ()
+command1 x con = do
+  raw "\\"  
+  raw x
+  raw "{"
+  con
+  raw "}"
+       
+    
+-- | environment x con = "\begin{x}con\end{x}"    
+  
+environment :: (MonadWriter t m, HasDocument t) =>  Text -> m () -> m ()
+environment x con = do
+  raw "\\begin{"  
+  raw x
+  raw "}\n"  
+  con
+  raw "\\end{"  
+  raw x
+  raw "}\n"  
+
diff --git a/src/Text/Authoring/Combinator/Ref.hs b/src/Text/Authoring/Combinator/Ref.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Authoring/Combinator/Ref.hs
@@ -0,0 +1,56 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Text.Authoring.Combinator.Ref where
+
+import           Control.Lens
+import           Control.Monad.State
+import           Control.Monad.Writer
+import           Data.Char (isAlphaNum)
+import qualified Data.Map as Map
+import qualified Data.Set as Set
+import           Data.Text (Text, pack)
+
+import Text.Authoring.Document
+import Text.Authoring.State
+import Text.Authoring.Label
+import Text.Authoring.Combinator.Writer
+import Text.Authoring.Combinator.Meta
+
+-- | refer to a label.  
+ref :: (MonadState s m, HasAuthorState s, MonadWriter w m, HasDocument w) => Label -> m ()
+ref lab = do
+  ret <- getReference lab
+  command1 "ref" $ raw ret
+
+-- | insert a label.
+label :: (MonadState s m, HasAuthorState s, MonadWriter w m, HasDocument w) => Label -> m ()
+label lab = do
+  ret <- getReference lab
+  command1 "label" $ raw ret
+
+-- | an interface for mapping any Label to a unique, LaTeX-safe text.
+
+getReference :: (MonadState s m, HasAuthorState s) => Label -> m Text
+getReference lab = do
+  map0 <- use labelMap
+  case Map.lookup lab map0 of
+    Just str -> return str
+    Nothing  -> do
+      let cands :: [String]
+          cands = cand0 : [s ++ [c]| s <- cands, c <- ['0'..'9']]
+          cand0 = map modify $ show lab
+
+          modify :: Char -> Char
+          modify c
+            | isAlphaNum c = c
+            | otherwise    = '.'
+                             
+          takens :: Set.Set Text
+          takens = Set.fromList $ Map.elems map0
+          
+          isTaken x = Set.member (pack x) takens
+
+          freeStr :: Text
+          freeStr = pack $ head $ filter (not . isTaken) cands
+      labelMap %= (Map.insert lab freeStr)
+      return freeStr
diff --git a/src/Text/Authoring/Combinator/Writer.hs b/src/Text/Authoring/Combinator/Writer.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Authoring/Combinator/Writer.hs
@@ -0,0 +1,37 @@
+{-# LANGUAGE MultiParamTypeClasses #-}
+
+-- | Names of this module are intentitionally kept too short.
+--   Use this module with quantifier.
+
+module Text.Authoring.Combinator.Writer where
+
+import Control.Lens (scribe)
+import Control.Monad.Writer
+import Data.Text (Text, pack)
+import Prelude 
+import Safe (readMay)
+import Text.LaTeX.Base.Syntax (LaTeX)
+import qualified Text.LaTeX.Base.Commands as LTX 
+import qualified Text.LaTeX.Base.Render as LTX 
+import qualified Text.LaTeX.Base.Syntax as LTX 
+import qualified Text.LaTeX.Base.Texy as LTX 
+
+import Text.Authoring.Document
+
+-- | Scribe a LaTeX syntax into the target document.
+
+latex :: (MonadWriter t m, HasDocument t) => LaTeX -> m ()
+latex x = scribe latexSrc x
+
+-- | Scribe a raw text (unescaped) into the target.
+
+raw :: (MonadWriter t m, HasDocument t) => Text -> m ()
+raw x = latex $ LTX.raw x
+
+
+-- | Shows objects of type 'a' using Show interface
+--   Escapes LaTeX special characters.
+
+esc :: (MonadWriter t m, HasDocument t, Show a) => a -> m ()
+esc x = raw $ LTX.protectText $ pack $ Prelude.show x
+
diff --git a/src/Text/Authoring/Document.hs b/src/Text/Authoring/Document.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Authoring/Document.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+{-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+module Text.Authoring.Document where
+
+import Control.Lens.TH
+import Data.Monoid
+import Text.LaTeX.Base.Syntax (LaTeX)
+
+newtype Document = Document { _latexSrc :: LaTeX }
+  deriving (Eq, Show)
+
+deriving instance Monoid Document
+
+makeClassy ''Document
diff --git a/src/Text/Authoring/Label.hs b/src/Text/Authoring/Label.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Authoring/Label.hs
@@ -0,0 +1,38 @@
+module Text.Authoring.Label 
+       ( Label(..),(<>),(./))
+       where
+
+import           Data.Monoid
+import           Data.String (IsString(..))
+import           Data.Typeable
+import           Data.Text (pack)
+import           Text.LaTeX (raw)
+
+-- | 'Label's are used to create a unique reference label
+--   within a paper.
+data Label 
+  = FromType !TypeRep 
+  | FromString !String
+  | Ap !Label !Label
+  | Empty
+  deriving (Eq, Ord)
+
+instance Monoid Label where
+  mempty = Empty
+  mappend Empty x = x
+  mappend x Empty = x
+  mappend x y = Ap x y
+
+instance IsString Label where
+  fromString = FromString
+
+instance Show Label where
+  show (FromType r) = show r
+  show (FromString s) = s
+  show (Ap a b) = show a ++ "." ++ show b
+
+infixl 1 ./
+
+-- | Create a slightly different version of the label.
+(./) :: Show a => Label -> a -> Label
+l ./ x = Ap l (FromString $ show x)
diff --git a/src/Text/Authoring/State.hs b/src/Text/Authoring/State.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Authoring/State.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+module Text.Authoring.State where
+
+import           Control.Lens
+import           Control.Lens.TH
+import qualified Data.Map as Map
+import qualified Data.Set as Set
+import           Data.Text (Text)
+import qualified Text.CSL.Input.Identifier.Internal as Citation
+
+import           Text.Authoring.Label
+
+data AuthorState
+  = AuthorState
+  { _labelMap :: Map.Map Label Text
+  , _citationDB :: Citation.Database
+  , _citedUrlSet :: Set.Set String
+  }
+
+makeClassy ''AuthorState
+
+instance Citation.HasDatabase AuthorState where
+  database = citationDB
