marxup 1.0.0.1 → 1.0.1
raw patch · 5 files changed
+42/−29 lines, 5 filessetup-changed
Files
- MarXup/Latex.hs +1/−0
- MarXup/Tex.hs +21/−3
- Setup.hs +2/−0
- examples/LaTeX.hs +14/−24
- marxup.cabal +4/−2
MarXup/Latex.hs view
@@ -15,6 +15,7 @@ mkcols = sequence_ . intersperse newcol vspace = cmd "vspace"+hspace = cmd "hspace" title = cmd "title" newline = backslash <> backslash
MarXup/Tex.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+ module MarXup.Tex where import Control.Monad.Fix@@ -75,8 +77,13 @@ select True x = Left x select False x = Right x ++type TexAndMPost = [Either String String]++newtype Displayer a = Displayer {fromDisplayer :: RWS () TexAndMPost References a }+ deriving (Monad, MonadWriter TexAndMPost, MonadState References, MonadFix) -- | Produces a list of strings (either for LaTeX or MetaPOST).-display :: String -> Bool -> Tex a -> RWS () [Either String String] References a+display :: String -> Bool -> Tex a -> Displayer a display fname mp t = case t of (Tex s) -> tell' s (Return a) -> return a@@ -86,7 +93,9 @@ (MFix f) -> mfix (rec . f) (Metapost x) -> display fname True x (MPFigure l) -> tell' $ fname ++ "-" ++ show l ++ ".mps"- where tell' s = tell [select mp s] + where tell' :: String -> Displayer ()+ tell' s = tell [select mp s] + rec :: Tex a -> Displayer a rec = display fname mp sho :: Show a => a -> Tex ()@@ -95,7 +104,7 @@ render :: Tex a -> IO () render t = do fname <- getProgName- let (_,xs) = evalRWS (display fname False t) () emptyRefs + let (_,xs) = evalRWS (fromDisplayer $ display fname False t) () emptyRefs (mp,tex) = partitionEithers xs writeFile (fname <.> "tex") (concat tex) writeFile (fname <.> "mp") (concat mp)@@ -131,6 +140,15 @@ res <- sequence $ map braces args when (null args) $ Tex "{}" -- so that this does not get glued with the next thing. return res++cmdm :: String -> [Tex a] -> [Tex a] -> Tex [a]+cmdm cmd options args = do + backslash >> Tex cmd+ when (not $ null options) $ sequence_ $ map brackets $ options+ res <- sequence $ map braces args+ when (null args) $ Tex "{}" -- so that this does not get glued with the next thing.+ return res+ cmdn'_ :: String -> [String] -> [Tex a] -> Tex () cmdn'_ cmd options args = cmdn' cmd options args >> return ()
Setup.hs view
@@ -1,2 +1,4 @@+#!/usr/bin/env runhaskell import Distribution.Simple+main :: IO () main = defaultMain
examples/LaTeX.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS_GHC -XTypeSynonymInstances -XOverloadedStrings -XDoRec -pgmF marxup -F #-}+{-# OPTIONS_GHC -XTypeSynonymInstances -XOverloadedStrings -XDoRec -pgmF marchup -F #-} import MarXup.Latex import MarXup.Tex@@ -11,7 +11,7 @@ usepackage ["utf8x"] "inputenc" -someTree = derivationTree $ Node (rule (mbox "who knows?") "A → B") []+someTree = derivationTree $ Node (rule (mbox "modus ponens") "A → B") [] (∶) = binop ":" γ = cmd "Gamma" nil@@ -25,48 +25,38 @@ (≜) = binop "=" main = render $ latexDocument "article" ["11pt"] preamble $ @"-@section{Markup}--At-syntax is used to call a Haskell function. --Here comes @sf{some sans-serif text with @em{emphasis}!}--Note that arguments put in braces are markup.-Arguments in parenthesis contain regular Haskell code.-So, we could also write it-@em(text "like this").---@someSection<-section{References}+@intro<-section{Intro} -The result of a call can be bound.+At-syntax is used to call a Haskell function. The result can be bound. For example, the @sf{section} command returns a label that can be used for references. -This is section @xref(someSection). Note that cross-references are checked+This is section @xref(intro). Note that cross-references are checked at ``compile-time''. Forward references also work (see sec. @xref(concl)). +@section{Markup} +Here comes @sf{some sans-serif text with @em{emphasis}!} +Note that arguments put in braces are markup.++ @section{Math} -Haskell syntax is somewhat more convenient than markup to -write math. Combined with unicode,+Arguments in parenthesis are Haskell. Combined with unicode syntax, this can make writing all sorts of mathy stuff rather pleasant. For example: @math(γ ⊢ x ∶ a). The operators are overloaded to work on text as well:-@displayMath(b ≜ sqrt (a + x/y))-However you must insert parentheses yourself-(until the math sub-DSL is implemented):-@displayMath((x+x)*x)+@displayMath(b ≜ sqrt (a + (x/y))) @concl<-section{Conclusion} -Marχup is awesome. :)++Marχup is awesome. @"
marxup.cabal view
@@ -1,5 +1,5 @@ name: marxup-version: 1.0.0.1+version: 1.0.1 category: Text synopsis: Markup language preprocessor for Haskell description:@@ -12,8 +12,10 @@ Cabal-Version: >= 1.8 tested-with: GHC==6.12.1 build-type: Simple+ data-files:- examples/LaTeX.hs+ examples/LaTeX.hs+ executable marxup extensions: FlexibleInstances, TupleSections