Util.hs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Util
  3. ( prelude
  4. , printdoc
  5. , vw
  6. , vh
  7. , textblock
  8. , textblock'
  9. , rotatebox'
  10. , fontsize
  11. ) where
  12. import Data.Text.Encoding
  13. import qualified Data.ByteString as B
  14. import Text.LaTeX
  15. import Text.LaTeX.Base.Class
  16. import Text.LaTeX.Base.Syntax
  17. printdoc x = execLaTeXT x >>= B.putStr . encodeUtf8 . render
  18. prelude :: Monad m => LaTeXT_ m
  19. prelude = do
  20. documentclass [Paper A4] article
  21. usepackage [] "graphicx"
  22. usepackage [] "geometry"
  23. usepackage [] "lmodern"
  24. usepackage ["absolute", "overlay"] "textpos"
  25. pagenumbering "gobble"
  26. paperwidth :: LaTeXC l => l
  27. paperwidth = commS "paperwidth"
  28. paperheight :: LaTeXC l => l
  29. paperheight = commS "paperheight"
  30. vw :: LaTeXC l => Double -> l
  31. vw x = rendertex x <> commS "paperwidth"
  32. vh :: LaTeXC l => Double -> l
  33. vh y = rendertex y <> commS "paperheight"
  34. tw :: LaTeXC l => Double -> l
  35. tw x = rendertex x <> commS "textwidth"
  36. th :: LaTeXC l => Double -> l
  37. th y = rendertex y <> commS "textheight"
  38. textblock :: LaTeXC l => LaTeX -> LaTeX -> LaTeX -> l -> l
  39. textblock w x y = liftL $ TeXEnv "textblock*" [
  40. FixArg $ w,
  41. MOptArg [rendertex (0.5 :: Double) , rendertex (0.5 :: Double)],
  42. MParArg [x , y]]
  43. textblock' :: LaTeXC l => LaTeX -> LaTeX -> l -> l
  44. textblock' x y z = textblock (commS "paperwidth") x y $ center z
  45. rotatebox' :: LaTeXC l => Double -> l -> l
  46. rotatebox' a = liftL $ \l -> TeXComm "rotatebox" [OptArg "origin=c", FixArg $ rendertex a, FixArg l]
  47. fontsize :: LaTeXC l => l -> l -> l -> l
  48. fontsize x y z = braces $ comm2 "fontsize" x y <> comm0 "selectfont" <> z