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

[Feature] Add typst CAYW citations #2817

Closed
Kasi07 opened this issue Mar 20, 2024 · 14 comments
Closed

[Feature] Add typst CAYW citations #2817

Kasi07 opened this issue Mar 20, 2024 · 14 comments

Comments

@Kasi07
Copy link
Contributor

Kasi07 commented Mar 20, 2024

Debug log ID

TWJFUAK7-euc/6.7.169-7

What happened?

I would like to insert the citations into my typst document and thus would love to see typst support for the CAYW feature.

I noticed the pandoc uses the @citation-key syntax which also works with typst most of the time. But I would like to see the #cite(<citation-key>) syntax as this is much more versatile.

Also here is the link to the typst citation documentation.

@retorquere
Copy link
Owner

typst doesn't do multi-cite then?

@Kasi07
Copy link
Contributor Author

Kasi07 commented Mar 20, 2024

As per this comment:

Typst [...] merges adjacent cites if the CSL style requests it.

Copy link

🤖 this is your friendly neighborhood build bot announcing test build 6.7.169.2817.5949 ("cayw-typst")

This update may name other issues, but the build just dropped here is for you; it just means problems already fixed in other issues have been folded into the work we are doing here. Install in Zotero by downloading test build 6.7.169.2817.5949, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".

@Kasi07
Copy link
Contributor Author

Kasi07 commented Mar 20, 2024

This is almost working. But the citation key has to be surrounded by '<' and '>'.

As the <label> syntax only supports certain characters (see here) maybe we could insert a check using a regex (In this case /^[a-zA-Z0-9_\-:.]+$/ if I stand correctly) to determine when to use the arguably uglier label("example") syntax.

@Kasi07
Copy link
Contributor Author

Kasi07 commented Mar 20, 2024

Maybe this way?:

public async typst(citations, _options): Promise<string> {
    const regex = /^[a-zA-Z0-9_\-:.]+$/;
    return await citations.map(citation => 
        regex.test(citation.citationKey) 
            ? `#cite(<${citation.citationKey}>)` 
            : `#cite(label("${citation.citationKey}"))`
    ).join('\n');
}

retorquere added a commit that referenced this issue Mar 20, 2024
@Kasi07
Copy link
Contributor Author

Kasi07 commented Mar 20, 2024

I took that from your earlier implementation.
Also in typst new lines are generally ignored and this would make it look cleaner.
I just checked and putting them in separate lines works just fine.

@retorquere
Copy link
Owner

I took that from your earlier implementation.

Yeah my bad. New build incoming.

@retorquere
Copy link
Owner

No locators or anything?

@retorquere
Copy link
Owner

supplement and form could be filled, we have that info

@Kasi07
Copy link
Contributor Author

Kasi07 commented Mar 20, 2024

No locators or anything?

What do you mean by locators?

supplement and form could be filled, we have that info

The supplement could be useful.
As the form depends on the placement in the text I am unsure how we would know about it?

@retorquere
Copy link
Owner

retorquere commented Mar 20, 2024

Does typst accept #cite(<arrgh>,,"year") (or how else would I pass none for supplement)?

As the form depends on the placement in the text I am unsure how we would know about it?

You can suppress author in the cite, which would mean "year" for form

@Kasi07
Copy link
Contributor Author

Kasi07 commented Mar 20, 2024

You can just use the key in typst like: #cite(<arrgh>, form: "year")

retorquere added a commit that referenced this issue Mar 20, 2024
retorquere added a commit that referenced this issue Mar 20, 2024
retorquere added a commit that referenced this issue Mar 20, 2024
Copy link

🤖 this is your friendly neighborhood build bot announcing test build 6.7.169.2817.5952 ("fixes #2817")

This update may name other issues, but the build just dropped here is for you; it just means problems already fixed in other issues have been folded into the work we are doing here. Install in Zotero by downloading test build 6.7.169.2817.5952, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".

@Kasi07
Copy link
Contributor Author

Kasi07 commented Mar 20, 2024

This is working great, thank a lot!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants