jgm / typst-hs

Haskell library for parsing and evaluating typst
Other
41 stars 5 forks source link

Typst to Latex conversion error: unexpected end of input, function does not have a method "caption" #52

Closed m-krastev closed 1 week ago

m-krastev commented 4 months ago

Explain the problem. Include the exact command line you used and all inputs necessary to reproduce the issue. Please create as minimal an example as possible, to help the maintainers isolate the problem. Explain the output you received and how it differs from what you expected.

Pandoc does not compile a Typst document correctly.

 > pandoc --from typst --to latex main.typ  

"main.typ" (line 74, column 152):
unexpected end of input
expecting end of input
Function does not have a method "caption" or Function scope does not contain "caption"

The relevant line:

Monolingual data has been used for the improving of machine translation systems since the early days of statistical MT, with early models proposed by #cite(<brownStatisticalApproachMachine1990>, form: "prose"). 

The document compiles just fine by Typst 0.11, I am using a template called "lucky-icml" if that's any help.

Commenting out the relevant line leads to another error leading upwards in the documents to a #vruler statement. Commenting that one as well leads to an error with #show: icml2024.with(...) statement by the template. Finally commenting that one allows Pandoc to finish but then the produced document has references looking like this {[edunovUnderstandingBackTranslationScale2018{]}

Pandoc version? What version of pandoc are you using, on what OS? (If it's not the latest release, please try with the latest release before reporting the issue.)

pandoc 3.1.13 (macOS 14.4.1)

jgm commented 4 months ago

Can you upload a complete file (ideally trimmed down to the minimum necessary) that will allow me to reproduce this? Pandoc has no trouble with the one line you quote, in isolation. I need to be able to reproduce the issue or I can't solve it.

rpruim commented 1 month ago

Here is a relatively small example exhibiting similar behavior.

minim.typ:


#import "@preview/splendid-mdpi:0.1.0"

#show: splendid-mdpi.template.with(
  title: [Towards Swifter Interstellar Mail Delivery],
  date: (
    year: 2022,
    month: "May",
    day: 17,
  ),
  abstract: [#lorem(80)]
)

== Profound thoughts 

#lorem(120)

#lorem(80)

typst compile minim.typ produces the expected pdf output.

But:

pandoc     --from typst --to latex minim.typ
"minim.typ" (line 18, column 2):
Function does not have a method "caption" or Function scope does not contain "caption"

Note: The example does not contain any figures, but the template does have some code specifying how figures should be displayed:

  show figure: align.with(center)
  show figure: set text(8pt)
  show figure.caption: pad.with(x: 10%)

Locally, I made a copy of the template and deleted the only line related to figure captions. Then I get a different error message (also if I delete all three lines related to figures):

pandoc     --from typst --to latex minimal.typ
"minimal.typ" (line 55, column 2):
unexpected Elt {eltName = Identifier "block", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "text", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "text", eltPos = Just "minimal.typ" (line 5, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Txt "Towards Swifter Interstellar Mail Delivery"]))]}])),(Identifier "font",VString "TeX Gyre Pagella"),(Identifier "size",VLength (LExact 18.0 LPt))]}]))]} or Elt {eltName = Identifier "strong", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "block", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "text", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "text", eltPos = Just "minimal.typ" (line 5, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Txt "Towards Swifter Interstellar Mail Delivery"]))]}])),(Identifier "font",VString "TeX Gyre Pagella"),(Identifier "size",VLength (LExact 18.0 LPt))]}]))]},Elt {eltName = Identifier "v", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "amount",VLength (LExact 4.0 LPt))]},Txt "Johanna Swift",Elt {eltName = Identifier "text", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Txt " "])),(Identifier "font",VString "TeX Gyre Pagella"),(Identifier "size",VLength (LExact 10.0 LPt))]},Elt {eltName = Identifier "super", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "text", eltPos = Just "energies-template.typ" (line 52, column 73), eltFields = fromList [(Identifier "body",VContent (fromList [Txt "1"])),(Identifier "font",VString "TeX Gyre Pagella"),(Identifier "size",VLength (LExact 10.0 LPt))]}]))]},Txt ", ",Txt "Egon Stellaris",Elt {eltName = Identifier "text", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Txt " "])),(Identifier "font",VString "TeX Gyre Pagella"),(Identifier "size",VLength (LExact 10.0 LPt))]},Elt {eltName = Identifier "super", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "text", eltPos = Just "energies-template.typ" (line 52, column 73), eltFields = fromList [(Identifier "body",VContent (fromList [Txt "2"])),(Identifier "font",VString "TeX Gyre Pagella"),(Identifier "size",VLength (LExact 10.0 LPt))]}]))]},Txt ", ",Txt "Oliver Liam",Elt {eltName = Identifier "text", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Txt " "])),(Identifier "font",VString "TeX Gyre Pagella"),(Identifier "size",VLength (LExact 10.0 LPt))]},Elt {eltName = Identifier "super", eltPos = Just "minimal.typ" (line 55, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "text", eltPos = Just "energies-template.typ" (line 52, column 73), eltFields = fromList [(Identifier "body",VContent (fromList [Txt "3"])),(Identifier "font",VString "TeX Gyre Pagella"),(Identifier "size",VLength (LExact 10.0 LPt))]}]))]}]))]}
expecting end of input
jgm commented 1 month ago

typst-hs currently doesn't support figure.caption. This would need to be added in jgm/typst-hs