Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick attempt at fixing multicharacter identifiers #2865

Merged
merged 10 commits into from
Nov 13, 2021
8 changes: 4 additions & 4 deletions code/drasil-example/glassbr/lib/Drasil/GlassBR/Unitals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ dimlessLoad = vc "dimlessLoad" (nounPhraseSP "dimensionless load") (hat lQ) Real
gTF = dqdNoUnit glTyFac (variable "GTF") Real

isSafePb = vc "isSafePb" (nounPhraseSP "probability of glass breakage safety requirement")
(variable "is-safePb") Boolean
(variable "isSafePb") Boolean
isSafeProb = vc "isSafeProb" (nounPhraseSP "probability of failure safety requirement")
(variable "is-safeProb") Boolean
(variable "isSafeProb") Boolean
isSafeLR = vc "isSafeLR" (nounPhraseSP "3 second load equivalent resistance safety requirement")
(variable "is-safeLR") Boolean
(variable "isSafeLR") Boolean
isSafeLoad = vc "isSafeLoad" (nounPhraseSP "load resistance safety requirement")
(variable "is-safeLoad") Boolean
(variable "isSafeLoad") Boolean

lDurFac = vc'' loadDurFactor (variable "LDF") Real
loadSF = dqdNoUnit loadShareFac (variable "LSF") Real
Expand Down
43 changes: 14 additions & 29 deletions code/drasil-printers/lib/Language/Drasil/TeX/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Numeric (showEFloat)
import Control.Arrow (second)

import qualified Language.Drasil as L
import qualified Language.Drasil.ShortHands as LD (cDelta)
import qualified Language.Drasil.Display as LD
import Utils.Drasil (checkValidStr, foldNums)

Expand Down Expand Up @@ -79,32 +78,6 @@ lo (Cell _) _ = empty
print :: PrintingInformation -> [LayoutObj] -> D
print sm = foldr (($+$) . (`lo` sm)) empty

------------------ Symbol ----------------------------
-- | Converts a symbol into a printable document form.
symbol :: LD.Symbol -> D
symbol (LD.Variable s) = pure $ text s
symbol (LD.Label s) = pure $ text s
symbol (LD.Integ n) = pure $ text $ show n
symbol (LD.Special s) = pure $ text $ unPL $ L.special s
symbol (LD.Concat sl) = foldl (<>) empty $ map symbol sl
--
-- handle the special cases first, then general case
symbol (LD.Corners [] [] [x] [] s) = br $ symbol s <> pure hat <> br (symbol x)
symbol (LD.Corners [] [] [] [x] s) = br $ symbol s <> pure unders <> br (symbol x)
symbol (LD.Corners [_] [] [] [] _) = error "rendering of ul prescript"
symbol (LD.Corners [] [_] [] [] _) = error "rendering of ll prescript"
symbol LD.Corners{} = error "rendering of Corners (general)"
symbol (LD.Atop f s) = sFormat f s
symbol LD.Empty = empty

-- | Converts a decorated symbol into a printable document form.
sFormat :: L.Decoration -> L.Symbol -> D
sFormat LD.Hat s = commandD "hat" (symbol s)
sFormat LD.Vector s = commandD "symbf" (symbol s)
sFormat LD.Prime s = symbol s <> pure (text "'")
sFormat LD.Delta s = symbol LD.cDelta <> symbol s
sFormat LD.Magnitude s = fence Open Norm <> symbol s <> fence Open Norm

-- | Determine wether braces and brackets are opening or closing.
data OpenClose = Open | Close

Expand All @@ -113,6 +86,17 @@ data OpenClose = Open | Close
-----------------------------------------------------------------
-- (Since this is all implicitly in Math, leave it as String for now)

-- | Escape all special TeX characters.
-- TODO: This function should be improved. It should escape all special
-- TeX symbols that would affect rendering. For example, `_`
-- turns the RHS of text into subscript, and `^` would turn it
-- into superscript. This will need to be much more comprehensive.
-- e.g., `%`, `&`, `#`, etc
escapeIdentSymbols :: String -> String
escapeIdentSymbols ('_':ss) = '\\' : '_' : escapeIdentSymbols ss
escapeIdentSymbols (s:ss) = s : escapeIdentSymbols ss
escapeIdentSymbols [] = []

-- | Print an expression to a document.
pExpr :: Expr -> D
pExpr (Dbl d) = pure . text $ showEFloat Nothing d ""
Expand All @@ -123,7 +107,8 @@ pExpr (Case ps) = mkEnv "cases" (cases ps)
pExpr (Mtx a) = mkEnv "bmatrix" (pMatrix a)
pExpr (Row [x]) = br $ pExpr x -- FIXME: Hack needed for symbols with multiple subscripts, etc.
pExpr (Row l) = foldl1 (<>) (map pExpr l)
pExpr (Ident s) = pure . text $ s
pExpr (Ident s@[_]) = pure . text . escapeIdentSymbols $ s
pExpr (Ident s) = commandD "mathit" (pure . text . escapeIdentSymbols $ s)
pExpr (Label s) = command "text" s
pExpr (Spec s) = pure . text $ unPL $ L.special s
--pExpr (Gr g) = unPL $ greek g
Expand Down Expand Up @@ -334,7 +319,7 @@ pUnit (L.US ls) = formatu t b
pow (n,p) = toMath $ superscript (p_symb n) (pure $ text $ show p)
-- printing of unit symbols is done weirdly... FIXME?
p_symb (LD.Concat s) = foldl (<>) empty $ map p_symb s
p_symb n = let cn = symbolNeeds n in switch (const cn) $ symbol n
p_symb n = let cn = symbolNeeds n in switch (const cn) $ pExpr $ I.symbol n

-----------------------------------------------------------------
------------------ DATA DEFINITION PRINTING-----------------
Expand Down
Loading