typst / typst

A new markup-based typesetting system that is powerful and easy to learn.
https://typst.app
Apache License 2.0
33.06k stars 893 forks source link

Cannot use #link function in Abstract following docs #1623

Closed jaanli closed 1 year ago

jaanli commented 1 year ago

Description

Hi! We have been using Typst throughout @onefact -- thank you!!!

However, when creating an Abstract using this documentation: https://typst.app/docs/tutorial/making-a-template/ Links are unsupported and do not render when inserted into this code:

#import "datathinking.org-report-template.typ": datathinking
#show: body => datathinking(
  title: "Data Thinking Bootcamp: Tech Freedom Schools Edition",
  authors: (
    (
      name: "Dr. Jaan Altosaar Li",
      affiliation: "One Fact Foundation 
University of Pennsylvania
Tartu University",
      email: "jaan@onefact.org",
    ),
    (
      name: "Dr. Ruha Benjamin",
      affiliation: "Ida B. Wells Just Data Lab
African American Studies 
Princeton University",
      email: "",
    ),
    (
      name: "Cierra Robson",
      affiliation: "Ida B. Wells Just Data Lab
Department of Sociology
Harvard University",
      email: "",
    ),
  ),
  abstract: "test link: #link(https://google.com)",
  body,
)

Here is the code to reproduce if needed:

https://github.com/onefact/datathinking.org-report-template

Thank you!

Reproduction URL

https://github.com/onefact/datathinking.org-report-template

Operating system

macOS

Typst version

MDLC01 commented 1 year ago

You seem to be passing a string instead of content. strings do not get parsed. They are converted to content character by character.

Passing content instead should solve your problem :

abstract: [test link: #link(https://google.com)],

or simply

abstract: [test link: https://google.com],

Of course, the function you are calling has to support content instead of string only.

jaanli commented 1 year ago

That was it, thank you so much!! Now unfortunately I can't figure out how to do the same for the title field --

// Set document metadata.
set document(title: title, author: names)

If I try following this guide: https://typst.app/docs/tutorial/making-a-template/

Then the above code results in the error:

error: content does not contain field "str" and no default value was specified
   ┌─ datathinking.org-report-template.typ:23:28
   │
23 │   set document(title: title.str, author: names)

Almost there :) this is so cool!! @typst rocks :D

MDLC01 commented 1 year ago

This is because the title parameter of document has to be a string: https://typst.app/docs/reference/meta/document/#parameters-title. I'm not sure, but this is likely due to the title being used for metadata, which cannot contain formatted text.

laurmaedje commented 1 year ago

I'm not sure, but this is likely due to the title being used for metadata, which cannot contain formatted text.

Exactly. As this is a common problem, maybe we can allow content too and extract the plain text, but that's a separate discussion.