Skip to content

Commit

Permalink
feat(eo-phi-normalizer): extend latex output
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Nov 28, 2024
1 parent 4c2dd58 commit e57de7f
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Control.Monad (forM, unless, when)
import Data.Aeson (ToJSON)
import Data.Aeson.Encode.Pretty (Config (..), Indent (..), defConfig, encodePrettyToTextBuilder')
import Data.FileEmbed (embedFileRelative)
import Data.Foldable (forM_)
import Data.Foldable (Foldable (..), forM_)
import Data.List (intercalate, isPrefixOf)
import Data.Maybe (fromMaybe)
import Data.Text.Internal.Builder (toLazyText)
Expand Down Expand Up @@ -593,7 +593,7 @@ main = withUtf8 do
Nothing -> do
ruleSet :: RuleSet <- decodeThrow $(embedFileRelative "test/eo/phi/rules/new.yaml")
return (False, ruleSet.title, convertRuleNamed <$> ruleSet.rules)
unless (single || json) $ logStrLn ruleSetTitle
unless (single || json || (chain && latex)) $ logStrLn ruleSetTitle
bindingsWithDeps <- case deepMergePrograms (program' : deps) of
Left err -> throw (CouldNotMergeDependencies err)
Right (Program bindingsWithDeps) -> return bindingsWithDeps
Expand Down Expand Up @@ -625,10 +625,22 @@ main = withUtf8 do
, output = (logEntryToPair . fmap printAsProgramOrAsObject <$>) <$> uniqueResults
}
| chain && latex -> do
logStrLn . toLatexString $ Formation bindings
logStrLn
[fmtTrim|
% {ruleSetTitle}

\\documentclass{{article}}
\\usepackage{{eolang}}
\\begin{{document}}
|]
forM_ uniqueResults $ \steps -> do
forM_ (init steps) $ \LogEntry{..} -> do
logStrLn . toLatexString $ logEntryLog
let latexLines = toLatexString (Formation bindings) : (toLatexString . (.logEntryLog) <$> steps)
transitions :: [String] = ((\x -> [fmt| \\trans_{{\\rulename{{{logEntryMessage x}}}}} \n|]) <$> steps) <> ["."]
linesCombined :: String = fold $ zipWith (\latexLine transition -> [fmt|{latexLine}{transition}|]) latexLines transitions
logStrLn "\\begin{phiquation*}"
logStrLn [fmtTrim|{linesCombined}|]
logStrLn "\\end{phiquation*}"
logStrLn "\n\\end{document}"
| latex ->
logStrLn . toLatexString $ logEntryLog (head (head uniqueResults))
| otherwise -> do
Expand Down

0 comments on commit e57de7f

Please sign in to comment.