Skip to content

Adding new features to the Typst template #9970

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

christopherkenny
Copy link

This implements the changes suggested in #9956, with the exception of the filecolor/urlcolor one. These would require adding some regex to guess the link types. This is theoretically possible to do, but it wasn't clear to me that this is a good thing to put in a default template. Happy to adjust if you have thoughts on this.

Some things to note:

  • I'm converting colors by passing them as content, as I was seeing pandoc escape # if that was included. An alternative here is to just do something like: rgb(linkcolor.replace("\\#", "#")).
  • I set the default fonts for math and code ("raw") to fonts that are bundled with Typst. These need not be those fonts if there are more familiar pandoc preferences.

@christopherkenny
Copy link
Author

Hi @jgm, I don't want to bother you if this is already on your radar, but should I add you as a reviewer (for when you have time)? I'm not 100% sure of the norms for contributions here.

@jgm
Copy link
Owner

jgm commented Aug 23, 2024

Sorry for the delay on this!

Copy link
Owner

@jgm jgm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, and sorry I took so long to review it. I made a number of queries and comments, which you can look over.

Comment on lines +75 to +80
$if(mathfont)$
mathfont: ($for(mathfont)$"$mathfont$",$endfor$),
$endif$
$if(codefont)$
codefont: ($for(codefont)$"$codefont$",$endfor$),
$endif$
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why you used $for$ here. mathfont would normally be expected to be a string in pandoc templates.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of an odd one, but Typst uses a vector of fonts because it automatically falls back to the next font if one is not found. This use of $for$ keeps that idea, where you might set (for example) EB Garamond and then Garamond. If EB Garamond is downloaded, then the template uses that. If not, it falls back to the (less featured, but more common) Garamond. This goes to the design choice that Typst will cycle through all the fonts chosen until it finds one available or ends up back at the default.

Comment on lines +90 to +92
$if(citecolor)$
citecolor: [$citecolor$],
$endif$
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works in content like this, with the escaped #?

citecolor: [\#ffffff]

You've tested I assume?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that this works, as I'm currently using it in a custom template. If there's something that you don't like about it, happy to brainstorm alternatives.

Comment on lines 31 to 38
author: authors.map(author => content-to-string(author.name)),
author: authors.map(author => content-to-string(author.name)).join(", ", last: ", and "),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this because and is an English word; anyone writing in another language would need to change the template. We could consider using &, or just use commas.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to go either way here. I pushed a change to make it &. I can make it anything that you think is least problematic, even removing the last special case.

Comment on lines +48 to +49
leading: linestretch * 0.65em
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the leading do here, and why is it needed with linestretch? Is the result the same as Typst's defaults when the default linestretch is used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leading sets the space between lines. Here, mixing it with linestretch ensures that a value of 1 * 0.65em = 0.65em or Typst's default single-spaced. For double spacing, then 1.3 = 2 * 0.65em. Here, this setting just makes it explicit so that setting 1 for single, etc, all map onto what is expected.

#text(weight: "bold", size: 1.5em)[#title]
#text(weight: "bold", size: 1.5em)[#title #if thanks != none {
footnote(thanks, numbering: "*")
counter(footnote).update(n => n - 1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is needed because otherwise the first note would be 2? That's a bit unexpected when numbering is explicitly specified, but maybe Typst works that way? (I'd consider it a bug if so.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so the numbering is a wrapper on top of a counter for footnotes. The numbers for footnotes are the counting numbers (1, 2, ...) and don't update even when you change the style. So this simply says: use * for the title, then set it back to 1 so that it can use 1, 2, ... for future footnotes.

@christopherkenny
Copy link
Author

Sorry for the long delay on this. I've been on the academic job market and a bit crazed. I'm using Quarto + pandoc + Typst for my dissertation and will resolve these over the next few days while in the midst of this.

@christopherkenny
Copy link
Author

christopherkenny commented Mar 19, 2025

d05ca30 handles the merging with the pagenumber change

@christopherkenny christopherkenny requested a review from jgm May 3, 2025 02:51
@christopherkenny
Copy link
Author

Hi @jgm. I've rerequested your review for when you have a chance. These are all now set to be less opinionated and better fit with the default typst settings, especially removing colors and fonts unless specified.

@christopherkenny
Copy link
Author

Apologies, spoke too soon on the last message. Just went through and triple checked things and now it is ready for re-review.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice not to force the use of an English word "Abstract" here. People write in other languages, too. If typst doesn't have a way of retrieving a localization of this, we colud introduce $abstract-title$, and I could set it to a localized default in the Tyspt writer.

@jgm
Copy link
Owner

jgm commented May 11, 2025

looks pretty good -- I made one comment about "Abstract."

@jgm
Copy link
Owner

jgm commented May 11, 2025

The other thing that needs to be done is modifying MANUAL.txt so that the new variables are documented.
There should be a section "Variables for Typst."

@jgm
Copy link
Owner

jgm commented May 15, 2025

TODO (for me): set abstract-title variable to a localized default in the typst writer.

@jgm
Copy link
Owner

jgm commented May 15, 2025

  abstractTitle <- translateTerm Abstract

and then when setting template variables,

                  defField "abstract-title" abstractTitle .

@christopherkenny
Copy link
Author

The MANUAL.txt and abstract-title defaults are now updated. Thanks for the review!

@jgm
Copy link
Owner

jgm commented May 16, 2025

Looks like the branch has to be rebased on to main in order to be merged cleanly.

@christopherkenny
Copy link
Author

So, I just rebased onto main, but I have a strong suspicion that this is not what you wanted. Before doing this, I made a backup branch which is just a copy prior to me rebasing. I can open a clean PR from that if this is not what you wanted.

@rnwst
Copy link
Contributor

rnwst commented May 24, 2025

@christopherkenny -- I had a look at what may have gone wrong with your rebase. My theory is as follows (please correct me if any of this is wrong!):

  • During your work on this branch, you used the 'Update branch' button a few times to merge jgm:main into christopherkenny:typst-template.
  • Your pandoc fork hasn't been synced since June 2024 and so the latest commit on christopherkenny:main is correspondingly old.
  • When you rebased onto main, you therefore rebased onto a commit from June 2024 rather than the latest main. In addition, you ran rebase without the --rebase-merges option, so your merge commits (created previously via the 'Update branch' button) were replaced with all of the respective commits from jgm:main, which is how you ended up with 662 commits on your branch. If the --rebase-merges option had been used, I think the rebase would have had no effect (since the rebase would've been done on the same commit on jgm:main that your branch was branching out from anyway).

To fix this, you could restore your previous version of this branch (via your backup branch), sync your fork (and do a git pull to make sure your local main is up to date as well), and perform an interactive rebase on main, during which you would drop all merge commits.

@christopherkenny
Copy link
Author

Yeah, that sounds exactly like what happened. Thanks for the help @rnwst. I will get this cleaned up tomorrow.

@christopherkenny
Copy link
Author

Thanks @rnwst, that was exactly it. All cleaned up now. Thanks for the help!

@rnwst
Copy link
Contributor

rnwst commented May 24, 2025

Looks like you have opted to undo and then redo (after merging jgm:main) the commit that would be causing a merge conflict, instead of rebasing the whole branch on top of latest jgm:main, which would result in a cleaner commit history. Some of the commit messages could also be tidied up, and perhaps some or all of the commits squashed. But I don't know if @jgm is as pedantic as I am, so let's wait to see what he says.

@jgm
Copy link
Owner

jgm commented May 27, 2025

I was thinking this could all be rebased into one commit (unless there's some strong reason for having more than one commit for this change).

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

Successfully merging this pull request may close these issues.

4 participants