You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using shakespeare to render LaTeX code with template files. I found that shakespeare creates compile errors when superscripts in LaTeX are used. I guess that the reason is based on the ^{ syntax from the html/css shakespeare part.
I dont know if this is intended or a bug of the parser.
A minimal example (stack lts-10.7) is given in the code fragment below.
#!/usr/bin/env stack
-- stack --resolver lts-10.7 script --package shakespeare --package text
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Text.Shakespeare.Text
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.IO as TLIO
{-
Using text for LaTeX import can be difficult:
foo provides the text in "tex file" 2^23
but pdflatex will render it with 2 in superscript and 3 in normal font
-}
foo :: TL.Text
foo = [lt|2^#{bar}|]
where bar = 23 :: Int
{-
To fix this the superscript has to be enclosed in { .. }, however this results
in compile errors:
shakespeare-caret-bug.hs:18:8: error:
• Exception when trying to run compile-time code:
"2^{#{foo}}" (line 1, column 4):
unexpected "#"
expecting "[", "(", "-", digit, "\"", uppercase letter, letter or digit, "_" or "'"
CallStack (from HasCallStack):
error, called at ./Text/Shakespeare.hs:202:23 in shakespeare-2.0.15-HbvJ7t5PaRN2XZniCryTrC:Text.Shakespeare
Code: template-haskell-2.12.0.0:Language.Haskell.TH.Quote.quoteExp
lt "2^{#{foo}}"
• In the quasi-quotation: [lt|2^{#{foo}}|]
|
18 | foo2 = [lt|2^{#{foo}}|]
| ^^^^^^^^^^^^^^^^
-}
foo2 :: TL.Text
foo2 = [lt|2^{#{bar}}|]
where bar = 23 :: Int
{-
A workaround can be achieved using ^\{, but this is not documented in
https://www.yesodweb.com/book/shakespearean-templates
or in the haddock
http://hackage.haskell.org/package/shakespeare-2.0.15/docs/Text-Shakespeare-Text.html
-}
foo3 :: TL.Text
foo3 = [lt|2^\{#{bar}}|]
where bar = 23 :: Int
main :: IO ()
main = do
TLIO.putStrLn foo
TLIO.putStrLn foo2
TLIO.putStrLn foo3
The text was updated successfully, but these errors were encountered:
This is intentional, we treat the parsing the same way. If you can send a PR update for the docs to clarify the necessity of escaping, that would be great.
I am using shakespeare to render LaTeX code with template files. I found that shakespeare creates compile errors when superscripts in LaTeX are used. I guess that the reason is based on the ^{ syntax from the html/css shakespeare part.
I dont know if this is intended or a bug of the parser.
A minimal example (stack lts-10.7) is given in the code fragment below.
The text was updated successfully, but these errors were encountered: