Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Add special case to rendering TeXSeq to insert spaces after TeXCommS when necessary. #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Text/LaTeX/Base/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ module Text.LaTeX.Base.Render
, showFloat
) where

import Data.Text (Text,lines,unlines)
import Data.Text (Text,lines,unlines,uncons)
import Text.LaTeX.Base.Syntax
import Text.LaTeX.Base.Class
import Data.String
import Data.Char (isAlpha)
import Data.Text.Encoding
import Data.List (intersperse)
import qualified Data.ByteString as B
Expand Down Expand Up @@ -136,6 +137,11 @@ instance Render LaTeX where
in if null xs then "%\n"
else Data.Text.unlines $ fmap ("%" <>) xs

render (TeXSeq l1@(TeXCommS _) l2) = let r2 = render l2 in
render l1 <> (case uncons r2 of
Just (c,_) | isIdentChar c -> " "
_ -> "") <> r2
where isIdentChar = isAlpha
render (TeXSeq l1 l2) = render l1 <> render l2
render TeXEmpty = mempty

Expand Down
2 changes: 1 addition & 1 deletion test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ main = defaultMain $ testGroup "HaTeX"
]
, testGroup "Parser"
[ QC.testProperty "render . parse = id" $
\l -> let t = render (l :: LaTeX)
\l -> let t = render . parse . render (l :: LaTeX)
in fmap render (parseLaTeX t) == Right t
]
]