<commit_before>{-# LANGUAGE QuasiQuotes #-}
module Language.LaTeX.Builder.Beamer

where

import Language.LaTeX.Builder.MonoidUtils
import Language.LaTeX.Types
import qualified Language.LaTeX.Builder as B
import Language.LaTeX.Builder.QQ
import Data.List (sort)
import Data.Maybe

{-
pkg :: PackageName
pkg = B.pkgName "beamer"
-}

documentclass :: DocumentClass
documentclass =  OtherDocumentClass "beamer"

frametitle :: LatexItem -> ParItem
frametitle = B.parCmdArg "frametitle"

data FrameOpt = Overlays Overlays
              | Fragile
  deriving (Eq,Ord) -- Overlays is first

data Overlays = RawOverlays String
  deriving (Eq,Ord)

ppFrameOpt :: FrameOpt -> [Arg LatexItem]
ppFrameOpt (Overlays overlays) = ppOverlays overlays
ppFrameOpt Fragile             = [B.optional (B.rawTex "fragile")]

ppOverlays :: Overlays -> [Arg LatexItem]
ppOverlays (RawOverlays s) = [B.optional . B.hstring $ s]

rawOverlays :: String -> Overlays
rawOverlays =  RawOverlays

-- more options to add ?
frame' :: [FrameOpt] -> ParItem  -> ParItem 
frame' opts = B.parEnvironmentPar "frame" ({-B.packageDependency pkg : -}(ppFrameOpt =<< sort opts))

frameO :: Overlays -> ParItem  -> ParItem 
frameO overlays = B.parEnvironmentPar "frame" ({-B.packageDependency pkg : -}ppOverlays overlays)

frame :: ParItem -> ParItem 
frame = B.parEnvironmentPar "frame" [{-B.packageDependency pkg-}]

example :: ParItem -> ParItem
example = B.parEnvironmentPar "example" []

box :: ParItem -> ParItem
box = B.parEnvironmentPar "box" []

box' :: LatexItem -> ParItem -> ParItem
box' title = B.parEnvironmentPar "box" [B.mandatory title]

slide :: LatexItem -> ParItem -> ParItem
slide tit body = frame (frametitle tit <> body)

alert :: LatexItem -> LatexItem
alert = B.latexCmdArg "alert"

-- AtBeginSubsection, AtBeginSection

only :: LatexItem -> LatexItem
only = B.latexCmdArg "only"

usetheme, usefonttheme :: LatexItem -> PreambleItem
usetheme = B.preambleCmdArg "usetheme"
usefonttheme = B.preambleCmdArg "usefonttheme"
-- \setbeamercolor*{titlelike}{parent=structure}
-- setbeamercolorStar = 

data Footline = Footline { author_percent :: Percentage
                         , title_percent  :: Percentage
                         , date_percent   :: Maybe Percentage }  

defaultFootline :: Footline
defaultFootline = Footline { author_percent = 34
                           , title_percent  = 36  
                           , date_percent   = Nothing } 

footline :: Footline -> PreambleItem
footline Footline{author_percent=authorp,title_percent=titlep,date_percent=maydatep} =
  let datep = fromMaybe (100 - authorp - titlep) maydatep
      f (Percentage p) = show p
  in
  B.rawPreamble $
  [$str|
        \defbeamertemplate*{footline}{infolines theme without institution}
        {
          \leavevmode%
          \hbox{%
            \begin{beamercolorbox}[wd=.|] <> f authorp <> [$str|\paperwidth,ht=2.25ex,dp=1.125ex,center]{author in head/foot}%
              \usebeamerfont{author in head/foot}
              \insertshortauthor
            \end{beamercolorbox}%
            \begin{beamercolorbox}[wd=.|] <> f titlep <> [$str|\paperwidth,ht=2.25ex,dp=1.125ex,center]{title in head/foot}%
              \usebeamerfont{title in head/foot}
              \insertshorttitle
            \end{beamercolorbox}%
            \begin{beamercolorbox}[wd=.|] <> f datep <> [$str|\paperwidth,ht=2.25ex,dp=1.125ex,right]{date  in head/foot}%
              \usebeamerfont{date in head/foot}
              \insertshortdate{}\hspace*{2em}
              \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
            \end{beamercolorbox}}%
          \vskip0pt%
        }
  |]<commit_msg>L.L.B.Beamer: renaming box to block.<commit_after>{-# LANGUAGE QuasiQuotes #-}
module Language.LaTeX.Builder.Beamer

where

import Language.LaTeX.Builder.MonoidUtils
import Language.LaTeX.Types
import qualified Language.LaTeX.Builder as B
import Language.LaTeX.Builder.QQ
import Data.List (sort)
import Data.Maybe

{-
pkg :: PackageName
pkg = B.pkgName "beamer"
-}

documentclass :: DocumentClass
documentclass =  OtherDocumentClass "beamer"

frametitle :: LatexItem -> ParItem
frametitle = B.parCmdArg "frametitle"

data FrameOpt = Overlays Overlays
              | Fragile
  deriving (Eq,Ord) -- Overlays is first

data Overlays = RawOverlays String
  deriving (Eq,Ord)

ppFrameOpt :: FrameOpt -> [Arg LatexItem]
ppFrameOpt (Overlays overlays) = ppOverlays overlays
ppFrameOpt Fragile             = [B.optional (B.rawTex "fragile")]

ppOverlays :: Overlays -> [Arg LatexItem]
ppOverlays (RawOverlays s) = [B.optional . B.hstring $ s]

rawOverlays :: String -> Overlays
rawOverlays =  RawOverlays

-- more options to add ?
frame' :: [FrameOpt] -> ParItem  -> ParItem 
frame' opts = B.parEnvironmentPar "frame" ({-B.packageDependency pkg : -}(ppFrameOpt =<< sort opts))

frameO :: Overlays -> ParItem  -> ParItem 
frameO overlays = B.parEnvironmentPar "frame" ({-B.packageDependency pkg : -}ppOverlays overlays)

frame :: ParItem -> ParItem 
frame = B.parEnvironmentPar "frame" [{-B.packageDependency pkg-}]

example :: ParItem -> ParItem
example = B.parEnvironmentPar "example" []

block :: ParItem -> ParItem
block = B.parEnvironmentPar "block" []

block' :: LatexItem -> ParItem -> ParItem
block' title = B.parEnvironmentPar "block" [B.mandatory title]

slide :: LatexItem -> ParItem -> ParItem
slide tit body = frame (frametitle tit <> body)

alert :: LatexItem -> LatexItem
alert = B.latexCmdArg "alert"

-- AtBeginSubsection, AtBeginSection

only :: LatexItem -> LatexItem
only = B.latexCmdArg "only"

usetheme, usefonttheme :: LatexItem -> PreambleItem
usetheme = B.preambleCmdArg "usetheme"
usefonttheme = B.preambleCmdArg "usefonttheme"
-- \setbeamercolor*{titlelike}{parent=structure}
-- setbeamercolorStar = 

data Footline = Footline { author_percent :: Percentage
                         , title_percent  :: Percentage
                         , date_percent   :: Maybe Percentage }  

defaultFootline :: Footline
defaultFootline = Footline { author_percent = 34
                           , title_percent  = 36  
                           , date_percent   = Nothing } 

footline :: Footline -> PreambleItem
footline Footline{author_percent=authorp,title_percent=titlep,date_percent=maydatep} =
  let datep = fromMaybe (100 - authorp - titlep) maydatep
      f (Percentage p) = show p
  in
  B.rawPreamble $
  [$str|
        \defbeamertemplate*{footline}{infolines theme without institution}
        {
          \leavevmode%
          \hbox{%
            \begin{beamercolorbox}[wd=.|] <> f authorp <> [$str|\paperwidth,ht=2.25ex,dp=1.125ex,center]{author in head/foot}%
              \usebeamerfont{author in head/foot}
              \insertshortauthor
            \end{beamercolorbox}%
            \begin{beamercolorbox}[wd=.|] <> f titlep <> [$str|\paperwidth,ht=2.25ex,dp=1.125ex,center]{title in head/foot}%
              \usebeamerfont{title in head/foot}
              \insertshorttitle
            \end{beamercolorbox}%
            \begin{beamercolorbox}[wd=.|] <> f datep <> [$str|\paperwidth,ht=2.25ex,dp=1.125ex,right]{date  in head/foot}%
              \usebeamerfont{date in head/foot}
              \insertshortdate{}\hspace*{2em}
              \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
            \end{beamercolorbox}}%
          \vskip0pt%
        }
  |]
{'fraction_non_alphanumeric': 0.120336453669787, 'fraction_numerical': 0.008411341744675078, 'mean_word_length': 3.057237204182719, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '103495', 'n_tokens_mistral': 2485, 'n_tokens_neox': 2372, 'n_words': 526}