LaTeX_funs.hs revision 98890889ffb2e8f6f722b00e265a211f13b5a861
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder{- |
c3d42e13d2a7c3749229498658aec34e7e4fd0a0Christian MaederModule : $Header$
c3d42e13d2a7c3749229498658aec34e7e4fd0a0Christian MaederDescription : auxiliary functions for LaTeX printing
cd7372fc7e6e43c389619f63daa6eb872d9d5b16Christian MaederCopyright : (c) Klaus Luettich, Uni Bremen 2002-2006
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder
c3d42e13d2a7c3749229498658aec34e7e4fd0a0Christian MaederMaintainer : Christian.Maeder@dfki.de
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian MaederStability : provisional
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian MaederPortability : portable
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder
99c923311eab71a85f1dcc4785d349609c828da4Christian MaederAuxiliary functions for LaTeX printing
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian MaederFunctions to calculate the length of a given word as it would be
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder printed with LaTeX according to one of four categories of words
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder useful for CASL:
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder * keywords -- all the things that were printed in boldface
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder * structid -- all the names used in the structured context of CASL
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder * annotation -- all the comments and annotations of CASL in a smaller font
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini * axiom -- identifiers in math mode for CASL Basic specs
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-}
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maedermodule Common.LaTeX_funs
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ( calc_line_length
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , axiom_width
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder , latex_macro
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , flushright
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , casl_comment_latex
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , casl_normal_latex
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , hc_sty_small_keyword
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , hc_sty_plain_keyword
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , hc_sty_casl_keyword
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , hc_sty_axiom
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , hc_sty_structid
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , hc_sty_structid_indexed
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , hc_sty_id
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , startTab, endTab, setTab
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , setTabWSp
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , startAnno
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , endAnno
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini , escapeLatex
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ) where
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torriniimport qualified Data.Map as Map
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torriniimport Data.Char
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torriniimport Data.List (isPrefixOf)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torriniimport Common.LaTeX_maps
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torriniimport Common.Lib.Pretty as Pretty
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torriniimport Common.Parsec
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torriniimport Text.ParserCombinators.Parsec as Parsec
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-- |
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-- a constant String for starting a LaTeX indentation with tab stop
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorrinistartTab :: String
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorrinistartTab = "\\@begT@"
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-- |
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-- a constant String for releasing a LaTeX indentation with tab stop
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniendTab :: String
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniendTab = "\\@endT@"
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-- |
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-- a constant String to set a tab stop and enable it
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorrinisetTab :: String
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorrinisetTab = "\\="
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-- | a constant String indicating the start of a space based indentation
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorrinisetTabWSp :: String
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorrinisetTabWSp = "\\@setTS@{"
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini{- functions for calculating an integer value according to a given
38f8320f50c5f63965ba42e4e48f38be07c823cfChristian Maeder length in LaTeX units
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Units per mm found in: Karsten Guenther, "Einfuehrung in LaTeX2e" (p.376)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-}
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicalc_line_length :: String -> Int
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicalc_line_length s =
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini let (r_unit,r_number) =
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini (\(x,y) -> (reverse x,reverse y)) $ span isAlpha $ reverse s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini unit = case r_unit of
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini "mm" -> 1
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder "cm" -> 10
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder "pt" -> 0.351
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder "in" -> 25.4
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder u -> error ( "unknown or unsupported LaTeX unit: " ++ u )
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini len :: Double
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini len = read $ map (\ c -> case c of
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ',' -> '.'
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini _ -> c) r_number
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini in truncate (len * unit * 1000)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini{- functions to calculate a word-width in integer with a given word
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini type or purpose
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-}
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinidata Word_type =
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Keyword | StructId | Normal | Comment | Annotation | AnnotationBold | Axiom
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini deriving (Show,Eq)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicalc_word_width :: Word_type -> String -> Int
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicalc_word_width wt s =
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini case Map.lookup s wFM of
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Just l -> l
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Nothing -> sum_char_width_deb ( showString "In map \""
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini . shows wt
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini . showString "\" \'") wFM k_wFM s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini - correction
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini where (wFM,k_wFM) = case wt of
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Keyword -> (keyword_map,key_keyword_map)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini StructId -> (structid_map,key_structid_map)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Comment -> (comment_map,key_comment_map)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Annotation -> (annotation_map,key_annotation_map)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini AnnotationBold -> (annotationbf_map,
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini key_annotationbf_map)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Axiom -> (axiom_map,key_axiom_map)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Normal -> (normal_map,key_normal_map)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini correction = case wt of
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Axiom -> itCorrection s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini _ -> 0
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniitCorrection :: String -> Int
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniitCorrection [] = 0
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniitCorrection s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini | length s < 2 || head s == '\\' = 0
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini | otherwise = itCorrection' 0 s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini where itCorrection' :: Int -> String -> Int
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini itCorrection' _ [] = error "itCorrection' applied to empty List"
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini itCorrection' r ys@[y1, y2]
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini | not (isAlphaNum y1) = r
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder | not (isAlphaNum y2) = r
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder | otherwise = r + lookupCorrection ys
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini itCorrection' r (y1 : ys@(y2 : _))
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini | not (isAlphaNum y1) = itCorrection' r ys
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini | otherwise =
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini itCorrection'
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini (r + lookupCorrection [y1, y2])
d4e8d3a0ddb1a63754edc3571b6a3a54a7b62d04Paolo Torrini ys
d4e8d3a0ddb1a63754edc3571b6a3a54a7b62d04Paolo Torrini itCorrection' _ _ = error ("itCorrection' doesn't work with " ++ s)
d4e8d3a0ddb1a63754edc3571b6a3a54a7b62d04Paolo Torrini lookupCorrection str = Map.findWithDefault def_cor str
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder italiccorrection_map
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder def_cor = 610
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinisum_char_width_deb :: (String -> String) -- only used for an hackie debug thing
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder -> Map.Map String Int
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini -> Map.Map Char [String] -> String -> Int
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinisum_char_width_deb _pref_fun cFM key_cFM s = sum_char_width' s 0
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini where sum_char_width' [] r = r
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini sum_char_width' [c] r = r + case c of
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini '}' -> 0
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini '{' -> 0
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder ' ' -> lookupWithDefault_cFM ['~']
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini _ -> lookupWithDefault_cFM [c]
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini sum_char_width' full@(c1:rest@(c2:cs)) r
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini | isLigature [c1, c2] = case Map.lookup [c1, c2] cFM of
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Just l -> sum_char_width' cs (r+l)
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini Nothing -> sum_char_width' rest nl
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini | [c1, c2] == "\\ " =
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini sum_char_width' cs (r + lookupWithDefault_cFM "~")
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini | c1 == ' ' =
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini sum_char_width' rest (r + lookupWithDefault_cFM "~")
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini | otherwise = case prefixIsKey full key_cFM of
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini Just key -> sum_char_width'
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini (drop (length key) full)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini $ r + (cFM Map.! key)
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini Nothing -> if c1 == '\\' then
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini sum_char_width'
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini (dropWhile isAlpha rest)
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini $ r + lookupWithDefault_cFM "~"
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini else sum_char_width' rest nl
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini where nl = r + lookupWithDefault_cFM [c1]
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini lookupWithDefault_cFM s' = case Map.lookup s' cFM of
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini Nothing -> 2200 -- do something here?
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini Just w -> w
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniprefixIsKey :: String -> Map.Map Char [String] -> Maybe String
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniprefixIsKey [] _ = Nothing
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniprefixIsKey ls@(c:_) key_cFM = case filter (flip isPrefixOf ls)
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini $ Map.findWithDefault [] c key_cFM of
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini [] -> Nothing
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini s : _ -> Just s
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini
38f8320f50c5f63965ba42e4e48f38be07c823cfChristian MaederisLigature :: String -> Bool
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniisLigature s = case s of
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini [_, _] -> Map.findWithDefault False s ligatures
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini _ -> False
c730c28919b53f940ed319ebb42780244c528e29Paolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinikeyword_width, structid_width, axiom_width, annotationbf_width,
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini comment_width, normal_width :: String -> Int
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maederannotationbf_width = calc_word_width AnnotationBold
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinikeyword_width = calc_word_width Keyword
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinistructid_width = calc_word_width StructId
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicomment_width = calc_word_width Comment
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrininormal_width = calc_word_width Normal
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torriniaxiom_width = sum . map (calc_word_width Axiom) . parseAxiomString
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini-- |
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini-- latex_macro creates a document ('Doc') containing String
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini-- that has a zero width.
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini-- So it can be used for LaTeX-macros not needing any space, i.e.
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini-- @\textit{@ or @}@
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrinilatex_macro :: String -> Doc
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrinilatex_macro = sp_text 0
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicasl_keyword_latex, casl_annotationbf_latex,
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini casl_axiom_latex,
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini casl_comment_latex, casl_structid_latex,
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini casl_normal_latex :: String -> Doc
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicasl_annotationbf_latex s = sp_text (annotationbf_width s) s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicasl_structid_latex s = sp_text (structid_width s) s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicasl_comment_latex s = sp_text (comment_width s) s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicasl_keyword_latex s = sp_text (keyword_width s) s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicasl_normal_latex s = sp_text (normal_width s) s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinicasl_axiom_latex s = sp_text (axiom_width s) s
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder-- | sort, op, pred, type and its plurals
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinihc_sty_casl_keyword :: String -> Doc
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinihc_sty_casl_keyword str =
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder sp_text (keyword_width "preds") $ '\\' : map toUpper str
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinihc_sty_plain_keyword :: String -> Doc
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maederhc_sty_plain_keyword kw =
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini latex_macro "\\KW{" <> casl_keyword_latex (escapeUnderline kw)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini <> latex_macro "}"
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maederhc_sty_small_keyword :: String -> Doc
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maederhc_sty_small_keyword kw =
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini latex_macro "\\KW{" <> casl_annotationbf_latex (escapeUnderline kw)
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder <> latex_macro "}"
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrinihc_sty_axiom, hc_sty_structid, hc_sty_id,hc_sty_structid_indexed
603e326e7b189de8c1e4ea8c89470b3a61154019Christian Maeder :: String -> Doc
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maederhc_sty_structid sid = latex_macro "\\SId{"<>sid_doc<>latex_macro "}"
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder where sid_doc = casl_structid_latex (escapeUnderline sid)
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maederhc_sty_structid_indexed sid =
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder latex_macro "\\SIdIndex{"<>sid_doc<>latex_macro "}"
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder where sid_doc = casl_structid_latex (escapeUnderline sid)
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maederhc_sty_id i = latex_macro "\\Id{"<>id_doc<>latex_macro "}"
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder where id_doc = casl_axiom_latex i
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maederhc_sty_axiom ax = latex_macro "\\Ax{"<>ax_doc<>latex_macro "}"
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder where ax_doc = casl_axiom_latex ax
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo Torrini
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder-- | flush argument doc to the right
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maederflushright :: Doc -> Doc
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maederflushright = (latex_macro "\\`" <>)
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-- |
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder-- a constant String for the start of annotations
120c9bff9059626735fc12b0399dcc9e5a62c345Christian MaederstartAnno :: String
120c9bff9059626735fc12b0399dcc9e5a62c345Christian MaederstartAnno = "{\\small{}"
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder-- |
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder-- a constant string ending an annotation
120c9bff9059626735fc12b0399dcc9e5a62c345Christian MaederendAnno :: String
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniendAnno = "%@%small@}"
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniescapeUnderline :: String -> String
120c9bff9059626735fc12b0399dcc9e5a62c345Christian MaederescapeUnderline = concatMap ( \ c -> if c == '_' then "\\_" else [c])
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniescapeLatex :: Bool -> String -> String
120c9bff9059626735fc12b0399dcc9e5a62c345Christian MaederescapeLatex addAx = concatMap ( \ c ->
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder if elem c "_%$&{}#" then
62dd3cd58cda003c32ac69ff12dc82b0a6f5d9d3Christian Maeder if addAx then "\\Ax{\\" ++ c : "}"
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder else '\\' : [c]
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder else if addAx && elem c "<|>=-!()[]?:;,./*+@" then "\\Ax{" ++ c : "}"
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini else Map.findWithDefault [c] c escapeMap)
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder
aa436590b8c7f5035f5cf657d6de163046bc23eaPaolo TorriniparseAxiomString :: String -> [String]
120c9bff9059626735fc12b0399dcc9e5a62c345Christian MaederparseAxiomString s = case parse axiomString "" s of
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder Left _ -> [s]
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder Right l -> l
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniaxiomString :: CharParser st [String]
120c9bff9059626735fc12b0399dcc9e5a62c345Christian MaederaxiomString = do
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder l <- many parseAtom
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini eof
120c9bff9059626735fc12b0399dcc9e5a62c345Christian Maeder return $ concat l
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder
74e146c7cfad97817d7e065dcd937cada89b257dChristian MaederparseAtom :: CharParser st [String]
74e146c7cfad97817d7e065dcd937cada89b257dChristian MaederparseAtom = do
74e146c7cfad97817d7e065dcd937cada89b257dChristian Maeder tryString "\\Ax{" <|> tryString "\\Id{" <|> string "{"
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder l <- many parseAtom
74e146c7cfad97817d7e065dcd937cada89b257dChristian Maeder Parsec.char '}'
a2e8cca8a8217b158b0b7a760e8234c03186456dChristian Maeder return (concat l)
74e146c7cfad97817d7e065dcd937cada89b257dChristian Maeder <|> do
99c923311eab71a85f1dcc4785d349609c828da4Christian Maeder b <- Parsec.char '\\'
74e146c7cfad97817d7e065dcd937cada89b257dChristian Maeder s <- fmap (: []) (satisfy (\ c -> isSpace c
74e146c7cfad97817d7e065dcd937cada89b257dChristian Maeder || elem c "_~^|\'\",;:.`\\{}[]%$&#()"))
74e146c7cfad97817d7e065dcd937cada89b257dChristian Maeder <|> many1 letter
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini return [b : s]
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini <|> do
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini s <- many1 letter
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini return [s]
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini <|> do
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini c <- satisfy (/= '}')
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini return [[c]]
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-- | a character map for special latex characters
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniescapeMap :: Map.Map Char String
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo TorriniescapeMap = Map.fromList
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini [('\\',"\\Ax{\\setminus}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('^',"\\Ax{\\hat{\\ }}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('"',"''"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('~',"\\Ax{\\sim}"),
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder ('\160',"\\ "),
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder ('\162',"\\Id{\\textcent}"),
13ed13e06a5dd4aad12044ed7e7503cbe7f62990Christian Maeder ('\164',"\\Id{\\textcurrency}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\165',"\\Id{\\textyen}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\166',"\\Id{\\textbrokenbar}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\170',"\\Id{\\textordfeminine}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\171',"\\Id{\\guillemotleft}"),
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder ('\172',"\\Ax{\\neg}"),
13ed13e06a5dd4aad12044ed7e7503cbe7f62990Christian Maeder ('\173',"-"),
13ed13e06a5dd4aad12044ed7e7503cbe7f62990Christian Maeder ('\174',"\\Id{\\textregistered}"),
cd7372fc7e6e43c389619f63daa6eb872d9d5b16Christian Maeder ('\175',"\\Ax{\\bar{\\ }}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\176',"\\Id{\\textdegree}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\177',"\\Ax{\\pm}"),
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder ('\178',"\\Ax{^2}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\179',"\\Ax{^3}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\180',"\\Ax{\\acute{\\ }}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\181',"\\Ax{\\mu}"),
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder ('\185',"\\Ax{^1}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\186',"\\Id{\\textordmasculine}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\187',"\\Id{\\guillemotright}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\192',"\\Ax{\\grave{A}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\193',"\\Ax{\\acute{A}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\200',"\\Ax{\\grave{E}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\201',"\\Ax{\\acute{E}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\204',"\\Ax{\\grave{I}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\205',"\\Ax{\\acute{I}}"),
d5ef5a29a89fa5548f81fcd49fcf0ffda69d45b0Christian Maeder ('\208',"\\Id{\\DH}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\210',"\\Ax{\\grave{O}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\211',"\\Ax{\\acute{O}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\215',"\\Ax{\\times}"),
5e4812721f9026ae4ae54381a5fdeb163489087dChristian Maeder ('\217',"\\Ax{\\grave{U}}"),
5e4812721f9026ae4ae54381a5fdeb163489087dChristian Maeder ('\218',"\\Ax{\\acute{U}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\221',"\\Ax{\\acute{Y}}"),
5e4812721f9026ae4ae54381a5fdeb163489087dChristian Maeder ('\222',"\\Id{\\TH}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\224',"\\Ax{\\grave{a}}"),
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder ('\225',"\\Ax{\\acute{a}}"),
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder ('\232',"\\Ax{\\grave{e}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\233',"\\Ax{\\acute{e}}"),
5e4812721f9026ae4ae54381a5fdeb163489087dChristian Maeder ('\236',"\\Ax{\\grave{\\Id{\\i}}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\237',"\\Ax{\\acute{\\Id{\\i}}}"),
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder ('\240',"\\Id{\\dh}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\242',"\\Ax{\\grave{o}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\243',"\\Ax{\\acute{o}}"),
5e4812721f9026ae4ae54381a5fdeb163489087dChristian Maeder ('\247',"\\Ax{\\div}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\249',"\\Ax{\\grave{u}}"),
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder ('\250',"\\Ax{\\acute{u}}"),
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder ('\253',"\\Ax{\\acute{y}}"),
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini ('\254',"\\Id{\\th}")]
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini{- acute and grave characters don't work in a tabbing environment
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder \textcent upto textbrokenbar requires \usepackage{textcomp}
ce31795240d8fb340bc984b8b35147c955e29afaChristian Maeder whereas \guillemot, eth, and thorn \usepackage[T1]{fontenc}
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini-}
1b0778e21d9b3e71a684ad6e901e8a0e7d57ee1cPaolo Torrini