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

Unexcepted escape seq in typst template. #9823

Closed
black-desk opened this issue May 30, 2024 · 13 comments
Closed

Unexcepted escape seq in typst template. #9823

black-desk opened this issue May 30, 2024 · 13 comments
Labels

Comments

@black-desk
Copy link
Contributor

Explain the problem.

I have a 1.md like this:

---
author:
  - name: XXX
    email: [email protected]
---

XXX

Then I run:

pandoc ./1.md --standalone -o 1.typ

I got 1.typ as:

// Some definitions presupposed by pandoc's typst output.
#let horizontalrule = [
  #line(start: (25%,0%), end: (75%,0%))
]

#let endnote(num, contents) = [
  #stack(dir: ltr, spacing: 3pt, super[#num], contents)
]
#show terms: it => {
  it.children
    .map(child => [
      #strong[#child.term]
      #block(inset: (left: 1.5em, top: -0.4em))[#child.description]
      ])
    .join()
}

#set table(
  inset: 6pt,
  stroke: none
)

#let conf(
  title: none,
  authors: (),
  keywords: (),
  date: none,
  abstract: none,
  cols: 1,
  margin: (x: 1.25in, y: 1.25in),
  paper: "us-letter",
  lang: "en",
  region: "US",
  font: (),
  fontsize: 11pt,
  sectionnumbering: none,
  doc,
) = {
  set document(
    title: title,
    author: authors.map(author => author.name),
    keywords: keywords,
  )
  set page(
    paper: paper,
    margin: margin,
    numbering: "1",
  )
  set par(justify: true)
  set text(lang: lang,
           region: region,
           font: font,
           size: fontsize)
  set heading(numbering: sectionnumbering)

  if title != none {
    align(center)[#block(inset: 2em)[
      #text(weight: "bold", size: 1.5em)[#title]
    ]]
  }

  if authors != none and authors != [] {
    let count = authors.len()
    let ncols = calc.min(count, 3)
    grid(
      columns: (1fr,) * ncols,
      row-gutter: 1.5em,
      ..authors.map(author =>
          align(center)[
            #author.name \
            #author.affiliation \
            #author.email
          ]
      )
    )
  }

  if date != none {
    align(center)[#block(inset: 1em)[
      #date
    ]]
  }

  if abstract != none {
    block(inset: 2em)[
    #text(weight: "semibold")[Abstract] #h(1em) #abstract
    ]
  }

  if cols == 1 {
    doc
  } else {
    columns(cols, doc)
  }
}
#show: doc => conf(
  authors: (
    ( name: "XXX",
      affiliation: "",
      email: "XXX\@xxx.com" ),
    ),
  cols: 1,
  doc,
)


XXX

The problem is that email: "XXX\@xxx.com", which make the pdf output of 1.typ looks like this:

图片

Note:

needsEscape '@' = True

I think we maybe need a new context type like this:

needsEscape ':' = context == TermContext

Pandoc version?

❯ pandoc --version
pandoc 3.2
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /home/black_desk/.local/share/pandoc
Copyright (C) 2006-2024 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
@black-desk black-desk added the bug label May 30, 2024
@black-desk
Copy link
Contributor Author

@iandol
Copy link
Contributor

iandol commented May 30, 2024

I also have this problem with my email addresses, not sure what is correct in terms of escaping from the yaml to the email field, but I think before the @ was just passed through without problems (at least I previously used Typst and didn't see this but now I do)...

@black-desk
Copy link
Contributor Author

I also have this problem with my email addresses, not sure what is correct in terms of escaping from the yaml to the email field, but I think before the @ was just passed through without problems (at least I previously used Typst and didn't see this but now I do)...

Might related to this commit:

ea9317c

@iandol
Copy link
Contributor

iandol commented May 30, 2024

I'm not sure that commit is responsible, if I edit my custom template to use the [$author.email$] or "$author.email$" syntax both get the @ escaped. My internet is very flakey for searching commits, but there were a few recent changes to escape more typst content.

@jgm
Copy link
Owner

jgm commented May 30, 2024

The field is parsed as Markdown, so it turns into Str "[email protected]". This in turn is rendered into typst with an escaped @ (because if we don't escape literal @s we can get accidental citations and references).

Some possible solutions:

(will format as a linked email address)

(will format as verbatim text)

    email: `[email protected]`{=typst}

(will just be a plain string without escapes).

@jgm
Copy link
Owner

jgm commented May 30, 2024

In any case: not a bug.

@jgm jgm closed this as completed May 30, 2024
@iandol
Copy link
Contributor

iandol commented May 30, 2024

OK, ` is reserved[1] (didn't it used to work before?), but YAML block literal syntax doesn't cause any YAML errors:

author:
  - name: XXX
    email: |
      `[email protected]`

... although the typst output gets some extra newlines these don't affect the PDF I think:

authors: (
    ( name: "XXX",
      affiliation: "",
      email: "`[email protected]`

" ),

[1] https://yaml.org/spec/1.2.2/#rule-c-reserved

@jgm
Copy link
Owner

jgm commented May 30, 2024

Yeah, the link idea was not good. And the other idea requires using block syntax or maybe single quotes.

@jgm jgm reopened this May 30, 2024
@jgm
Copy link
Owner

jgm commented May 30, 2024

Perhaps we can adjust the escaping so that word-internal @ isn't escaped. I think that would be safe.

@jgm
Copy link
Owner

jgm commented May 30, 2024

No such luck.

in typst.app raises an error because the label aoeu.com isn't found.

@jgm
Copy link
Owner

jgm commented May 30, 2024

Maybe the solution is to use [..] instead ".." in the template.

@iandol
Copy link
Contributor

iandol commented May 30, 2024

This works (at least for Typst CLI), using the current pandoc default template:

---
title: XXX
author:
  - name: XXX
    email: |
      `[email protected]`{=typst}
---

XXX
image

@jgm jgm closed this as completed in 0e92d94 May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants