| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Text.LaTeX.Base.Syntax
Description
Synopsis
- data Measure
- data MathType
- data LaTeX
- data TeXArg
- (<>) :: Semigroup a => a -> a -> a
- between :: Monoid m => m -> m -> m -> m
- protectString :: String -> String
- protectText :: Text -> Text
- matchCommand :: (String -> Bool) -> LaTeX -> [(String, [TeXArg])]
- lookForCommand :: String -> LaTeX -> [[TeXArg]]
- matchEnv :: (String -> Bool) -> LaTeX -> [(String, [TeXArg], LaTeX)]
- lookForEnv :: String -> LaTeX -> [([TeXArg], LaTeX)]
- texmap :: (LaTeX -> Bool) -> (LaTeX -> LaTeX) -> LaTeX -> LaTeX
- texmapM :: (Applicative m, Monad m) => (LaTeX -> Bool) -> (LaTeX -> m LaTeX) -> LaTeX -> m LaTeX
- getBody :: LaTeX -> Maybe LaTeX
- getPreamble :: LaTeX -> LaTeX
LaTeX datatype
Measure units defined in LaTeX. Use CustomMeasure to use commands like textwidth.
For instance:
rule Nothing (CustomMeasure linewidth) (Pt 2)
This will create a black box (see rule) as wide as the text and two points tall.
Constructors
| Pt Double | A point is 1/72.27 inch, that means about 0.0138 inch or 0.3515 mm. |
| Mm Double | Millimeter. |
| Cm Double | Centimeter. |
| In Double | Inch. |
| Ex Double | The height of an "x" in the current font. |
| Em Double | The width of an "M" in the current font. |
| CustomMeasure LaTeX | You can introduce a |
Instances
Different types of syntax for mathematical expressions.
Constructors
| Parentheses | |
| Square | |
| Dollar | |
| DoubleDollar |
Instances
| Data MathType Source # | |||||
Defined in Text.LaTeX.Base.Syntax Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MathType -> c MathType # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c MathType # toConstr :: MathType -> Constr # dataTypeOf :: MathType -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c MathType) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MathType) # gmapT :: (forall b. Data b => b -> b) -> MathType -> MathType # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MathType -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MathType -> r # gmapQ :: (forall d. Data d => d -> u) -> MathType -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> MathType -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> MathType -> m MathType # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MathType -> m MathType # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MathType -> m MathType # | |||||
| Generic MathType Source # | |||||
Defined in Text.LaTeX.Base.Syntax Associated Types
| |||||
| Show MathType Source # | |||||
| Eq MathType Source # | |||||
| Hashable MathType Source # | |||||
Defined in Text.LaTeX.Base.Syntax | |||||
| type Rep MathType Source # | |||||
Defined in Text.LaTeX.Base.Syntax type Rep MathType = D1 ('MetaData "MathType" "Text.LaTeX.Base.Syntax" "HaTeX-3.23.0.2-Ciqt3qGzvcAKiuU7PYpSYh" 'False) ((C1 ('MetaCons "Parentheses" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Square" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Dollar" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DoubleDollar" 'PrefixI 'False) (U1 :: Type -> Type))) | |||||
Type of LaTeX blocks.
Constructors
| TeXRaw Text | Raw text. |
| TeXComm String [TeXArg] | Constructor for commands. First argument is the name of the command. Second, its arguments. |
| TeXCommS String | Constructor for commands with no arguments.
When rendering, no space or |
| TeXEnv String [TeXArg] LaTeX | Constructor for environments. First argument is the name of the environment. Second, its arguments. Third, its content. |
| TeXMath MathType LaTeX | Mathematical expressions. |
| TeXLineBreak (Maybe Measure) Bool | Line break command. |
| TeXBraces LaTeX | A expression between braces. |
| TeXComment Text | Comments. |
| TeXSeq LaTeX LaTeX | |
| TeXEmpty | An empty block.
Neutral element of |
Instances
| LaTeXC LaTeX Source # | This instance just sets | ||||
| Render LaTeX Source # | |||||
| Texy LaTeX Source # | |||||
| Arbitrary LaTeX Source # | |||||
| Data LaTeX Source # | |||||
Defined in Text.LaTeX.Base.Syntax Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LaTeX -> c LaTeX # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LaTeX # dataTypeOf :: LaTeX -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LaTeX) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LaTeX) # gmapT :: (forall b. Data b => b -> b) -> LaTeX -> LaTeX # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LaTeX -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LaTeX -> r # gmapQ :: (forall d. Data d => d -> u) -> LaTeX -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LaTeX -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LaTeX -> m LaTeX # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LaTeX -> m LaTeX # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LaTeX -> m LaTeX # | |||||
| IsString LaTeX Source # | Method | ||||
Defined in Text.LaTeX.Base.Syntax Methods fromString :: String -> LaTeX # | |||||
| Monoid LaTeX Source # | |||||
| Semigroup LaTeX Source # | Appending is strict in both arguments (except when the first argument is | ||||
| Floating LaTeX Source # | The | ||||
| Generic LaTeX Source # | |||||
Defined in Text.LaTeX.Base.Syntax Associated Types
| |||||
| Num LaTeX Source # | The | ||||
| Fractional LaTeX Source # | Division uses the LaTeX | ||||
| Show LaTeX Source # | |||||
| Eq LaTeX Source # | |||||
| Hashable LaTeX Source # | |||||
Defined in Text.LaTeX.Base.Syntax | |||||
| type Rep LaTeX Source # | |||||
Defined in Text.LaTeX.Base.Syntax type Rep LaTeX = D1 ('MetaData "LaTeX" "Text.LaTeX.Base.Syntax" "HaTeX-3.23.0.2-Ciqt3qGzvcAKiuU7PYpSYh" 'False) (((C1 ('MetaCons "TeXRaw" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :+: C1 ('MetaCons "TeXComm" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TeXArg]))) :+: (C1 ('MetaCons "TeXCommS" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :+: (C1 ('MetaCons "TeXEnv" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TeXArg]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LaTeX))) :+: C1 ('MetaCons "TeXMath" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MathType) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LaTeX))))) :+: ((C1 ('MetaCons "TeXLineBreak" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Measure)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :+: C1 ('MetaCons "TeXBraces" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LaTeX))) :+: (C1 ('MetaCons "TeXComment" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :+: (C1 ('MetaCons "TeXSeq" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LaTeX) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LaTeX)) :+: C1 ('MetaCons "TeXEmpty" 'PrefixI 'False) (U1 :: Type -> Type))))) | |||||
An argument for a LaTeX command or environment.
Constructors
| FixArg LaTeX | Fixed argument. |
| OptArg LaTeX | Optional argument. |
| MOptArg [LaTeX] | Multiple optional argument. |
| SymArg LaTeX | An argument enclosed between |
| MSymArg [LaTeX] | Version of |
| ParArg LaTeX | An argument enclosed between |
| MParArg [LaTeX] | Version of |
Instances
| Render TeXArg Source # | |||||
| Arbitrary TeXArg Source # | |||||
| Data TeXArg Source # | |||||
Defined in Text.LaTeX.Base.Syntax Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TeXArg -> c TeXArg # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TeXArg # toConstr :: TeXArg -> Constr # dataTypeOf :: TeXArg -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c TeXArg) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TeXArg) # gmapT :: (forall b. Data b => b -> b) -> TeXArg -> TeXArg # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TeXArg -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TeXArg -> r # gmapQ :: (forall d. Data d => d -> u) -> TeXArg -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> TeXArg -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> TeXArg -> m TeXArg # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TeXArg -> m TeXArg # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TeXArg -> m TeXArg # | |||||
| Generic TeXArg Source # | |||||
Defined in Text.LaTeX.Base.Syntax Associated Types
| |||||
| Show TeXArg Source # | |||||
| Eq TeXArg Source # | |||||
| Hashable TeXArg Source # | |||||
Defined in Text.LaTeX.Base.Syntax | |||||
| type Rep TeXArg Source # | |||||
Defined in Text.LaTeX.Base.Syntax type Rep TeXArg = D1 ('MetaData "TeXArg" "Text.LaTeX.Base.Syntax" "HaTeX-3.23.0.2-Ciqt3qGzvcAKiuU7PYpSYh" 'False) ((C1 ('MetaCons "FixArg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LaTeX)) :+: (C1 ('MetaCons "OptArg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LaTeX)) :+: C1 ('MetaCons "MOptArg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [LaTeX])))) :+: ((C1 ('MetaCons "SymArg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LaTeX)) :+: C1 ('MetaCons "MSymArg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [LaTeX]))) :+: (C1 ('MetaCons "ParArg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LaTeX)) :+: C1 ('MetaCons "MParArg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [LaTeX]))))) | |||||
(<>) :: Semigroup a => a -> a -> a infixr 6 #
An associative operation.
Examples
>>>[1,2,3] <> [4,5,6][1,2,3,4,5,6]
>>>Just [1, 2, 3] <> Just [4, 5, 6]Just [1,2,3,4,5,6]
>>>putStr "Hello, " <> putStrLn "World!"Hello, World!
between :: Monoid m => m -> m -> m -> m Source #
Calling between c l1 l2 puts c between l1 and l2 and
appends them.
between c l1 l2 = l1 <> c <> l2
Escaping reserved characters
Syntax analysis
Arguments
| :: String | Name of the command. |
| -> LaTeX | LaTeX syntax tree. |
| -> [[TeXArg]] | List of arguments passed to the command. |
Look into a LaTeX syntax tree to find any call to the command with
the given name. It returns a list of arguments with which this command
is called.
lookForCommand = (fmap snd .) . matchCommand . (==)
If the returned list is empty, the command was not found. However, if the list contains empty lists, those are callings to the command with no arguments.
For example
lookForCommand "author" l
would look for the argument passed to the \author command in l.
lookForEnv :: String -> LaTeX -> [([TeXArg], LaTeX)] Source #
Similar to lookForCommand, but applied to environments.
It returns a list with arguments passed and content of the
environment in each call.
lookForEnv = (fmap (\(_,as,l) -> (as,l)) .) . matchEnv . (==)
Arguments
| :: (LaTeX -> Bool) | Condition. |
| -> (LaTeX -> LaTeX) | Function to apply when the condition matches. |
| -> LaTeX | |
| -> LaTeX |
The function texmap looks for subexpressions that match a given
condition and applies a function to them.
texmap c f = runIdentity . texmapM c (pure . f)