{-# LANGUAGE OverloadedStrings #-}

-- | Some types shared along the library.
module Text.LaTeX.Base.Types (
   ClassName
 , PackageName
 , PageStyle
 , Label
 , createLabel , labelName
 , Pos (..) , HPos (..)
 , TableSpec (..)
 , Measure (..)
 ) where

import Text.LaTeX.Base.Syntax
import Text.LaTeX.Base.Render

-- | Class names are represented by a 'String'.
type ClassName = String

-- | Package names are represented by a 'String'.
type PackageName = String

-- | Page styles are represented by a 'String'.
type PageStyle = String

-- | Type of labels.
newtype Label = Label String deriving (Label -> Label -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Label -> Label -> Bool
$c/= :: Label -> Label -> Bool
== :: Label -> Label -> Bool
$c== :: Label -> Label -> Bool
Eq, Int -> Label -> ShowS
[Label] -> ShowS
Label -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Label] -> ShowS
$cshowList :: [Label] -> ShowS
show :: Label -> String
$cshow :: Label -> String
showsPrec :: Int -> Label -> ShowS
$cshowsPrec :: Int -> Label -> ShowS
Show)

-- | Create a label from its name.
createLabel :: String -> Label
createLabel :: String -> Label
createLabel = String -> Label
Label

-- | Get the name of a label.
labelName :: Label -> String
labelName :: Label -> String
labelName (Label String
str) = String
str

instance Render Label where
    render :: Label -> Text
render (Label String
str) = forall a. IsString a => String -> a
fromString String
str

instance IsString Label where
    fromString :: String -> Label
fromString = String -> Label
createLabel

-- | Vertical position. 'Here' and 'ForcePos' are used with @table@ environments.
data Pos = Bottom | Center | Top | Here | ForcePos deriving Int -> Pos -> ShowS
[Pos] -> ShowS
Pos -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Pos] -> ShowS
$cshowList :: [Pos] -> ShowS
show :: Pos -> String
$cshow :: Pos -> String
showsPrec :: Int -> Pos -> ShowS
$cshowsPrec :: Int -> Pos -> ShowS
Show

instance Render Pos where
 render :: Pos -> Text
render Pos
Bottom   = Text
"b"
 render Pos
Center   = Text
"c"
 render Pos
Top      = Text
"t"
 render Pos
Here     = Text
"h"
 render Pos
ForcePos = Text
"!"

-- | Horizontal position.
data HPos = HLeft | HCenter | HRight deriving Int -> HPos -> ShowS
[HPos] -> ShowS
HPos -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HPos] -> ShowS
$cshowList :: [HPos] -> ShowS
show :: HPos -> String
$cshow :: HPos -> String
showsPrec :: Int -> HPos -> ShowS
$cshowsPrec :: Int -> HPos -> ShowS
Show

instance Render HPos where
 render :: HPos -> Text
render HPos
HLeft   = Text
"l"
 render HPos
HCenter = Text
"c"
 render HPos
HRight  = Text
"r"

-- | Type of table specifications.
data TableSpec =
   LeftColumn         -- ^ Left-justified column.
 | CenterColumn       -- ^ Centered column.
 | RightColumn        -- ^ Right-justified column.
 | ParColumnTop LaTeX -- ^ Paragraph column with text vertically aligned at the top.
 | ParColumnMid LaTeX -- ^ Paragraph column with text vertically aligned at the middle. Requires 'array' package.
 | ParColumnBot LaTeX -- ^ Paragraph column with text vertically aligned at the bottom. Requires 'array' package.
 | NameColumn String  -- ^ User defined column. Requires 'array' package.
 | BeforeColumn LaTeX -- ^ Can be used before a 'LeftColumn', 'CenterColumn', 'RightColumn', 'ParColumnTop', 'ParColumnMid' or a 'ParColumnBot' specification. Inserts the code directly in front of the entry of the column. Requires 'array' package.
 | AfterColumn LaTeX  -- ^ Can be used after a 'LeftColumn', 'CenterColumn', 'RightColumn', 'ParColumnTop', 'ParColumnMid' or a 'ParColumnBot' specification. Inserts the code directly in front of the entry of the column. Requires 'array' package.
 | VerticalLine       -- ^ Vertical line between two columns.
 | DVerticalLine      -- ^ Double vertical line between two columns.
 | Separator LaTeX    -- ^ Column separator. Requires 'array' package.
   deriving Int -> TableSpec -> ShowS
[TableSpec] -> ShowS
TableSpec -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TableSpec] -> ShowS
$cshowList :: [TableSpec] -> ShowS
show :: TableSpec -> String
$cshow :: TableSpec -> String
showsPrec :: Int -> TableSpec -> ShowS
$cshowsPrec :: Int -> TableSpec -> ShowS
Show

instance Render TableSpec where
 render :: TableSpec -> Text
render TableSpec
LeftColumn       = Text
"l"
 render TableSpec
CenterColumn     = Text
"c"
 render TableSpec
RightColumn      = Text
"r"
 render (ParColumnTop LaTeX
l) = Text
"p" forall a. Semigroup a => a -> a -> a
<> forall a. Render a => a -> Text
render (LaTeX -> TeXArg
FixArg LaTeX
l)
 render (ParColumnMid LaTeX
l) = Text
"m" forall a. Semigroup a => a -> a -> a
<> forall a. Render a => a -> Text
render (LaTeX -> TeXArg
FixArg LaTeX
l)
 render (ParColumnBot LaTeX
l) = Text
"b" forall a. Semigroup a => a -> a -> a
<> forall a. Render a => a -> Text
render (LaTeX -> TeXArg
FixArg LaTeX
l)
 render (NameColumn String
n)   = forall a. IsString a => String -> a
fromString String
n
 render (BeforeColumn LaTeX
l) = Text
">{" forall a. Semigroup a => a -> a -> a
<> forall a. Render a => a -> Text
render LaTeX
l forall a. Semigroup a => a -> a -> a
<> Text
"}"
 render (AfterColumn LaTeX
l)  = Text
"<{" forall a. Semigroup a => a -> a -> a
<> forall a. Render a => a -> Text
render LaTeX
l forall a. Semigroup a => a -> a -> a
<> Text
"}"
 render TableSpec
VerticalLine     = Text
"|"
 render TableSpec
DVerticalLine    = Text
"||"
 render (Separator LaTeX
l)    = Text
"@" forall a. Semigroup a => a -> a -> a
<> forall a. Render a => a -> Text
render (LaTeX -> TeXArg
FixArg LaTeX
l)