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

Text.Shakespeare.Text does not work well with superscripts in LaTeX text #217

Open
braunwolfgang opened this issue Feb 26, 2018 · 1 comment

Comments

@braunwolfgang
Copy link
Contributor

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
@snoyberg
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants