Improving the Typst base template to match equivalent PDF options #10223
Replies: 4 comments 5 replies
-
Thanks for the suggestions. Note that a lot of the YAML options come directly from Pandoc and the template there. Also, I believe most of your suggestions should be applied on Pandoc side as I did for subtitle. cc. @gordonwoodhull FYI: |
Beta Was this translation helpful? Give feedback.
-
This is a really helpful catalog of areas where Typst output could be brought up to the level of Latex. Thanks! I agree with @mcanouil that most of these changes should be made on the Pandoc side. For instance, we will pick up his I would suggest contributing the Pandoc features directly to Pandoc! I am not sure, but I think the "more difficult layout problems" may require changes on the Quarto side. If you would be willing to do a little more background research to see where these changes need to be made, that would be super helpful. Please keep in mind that while we have a long-term plan for how to review and accept changes that improve feature parity between formats, that is at least some months away. (Among other things, we need guidelines and processes on how to add tests, docs, and feature-format matrix entries.) |
Beta Was this translation helpful? Give feedback.
-
Thank you both for the feedback. I can start an issue at Pandoc (edit: see jgm/pandoc#9956) that goes through the Pandoc pieces of this. I was not entirely clear how much templates differ between Pandoc and Quarto. My sense is that the layout problems would require Quarto changes, but I will look into how much is required there. Notably, since Quarto uses its own figure type, then any layout directives need to be handled here, separately from Pandoc. (This is because you have to target them with |
Beta Was this translation helpful? Give feedback.
-
Hi @christopherkenny, thanks for the long post. Let me add a bit of context to some of our design goals and decisions, so that you understand where we might land on eventual PRs you might make. Then I'll make some specific comments.
These three goals mean that we want Quarto to work, in general, as close to a "strict Pandoc superset". Specific comments
I'm not sure I understand: Quarto is very much designed in a way that doesn't prioritize the cleanliness of the intermediate output files. It's not that we're unwilling to make changes that make the output files cleaner; it's that we don't consider this to be particularly important. We instead choose to focus on uniformity of experience for Markdown and ipynb inputs, and will almost always prioritize that over cleanliness of output files. Quarto does intend the intermediate outputs to be consumable by downstream tooling without requiring Quarto to be installed. The typical use case here is that we want the intermediate latex files to exist and be available for submission to a journal that requires LaTeX sources. If (hopefuly when!) journals start accepting raw Typst as their format submission, we intend Quarto's Typst output to be directly usable as input to such submissions. But Quarto does not (and will not) ever emit Typst code that is as clean as you could write by hand. Next stepsI realize that this might mean that some of your proposed changes do not match our design goals. I think the best way to incorporate your suggestions into Quarto is for you to start with the very smallest PR you can envision, so that we can together experiment with how that feature interacts with Quarto's other formats and our design goals. |
Beta Was this translation helpful? Give feedback.
-
Description
I've had to create several new template classes for my work in Quarto recently. I made the switch to using Typst for all of them, but still using Quarto as the frontend.
As a heavy Quarto + LaTeX user prior, it's clear that there are many fewer features available for
-typst
formats compared to-pdf
formats. It looks like most of this is driven by (1) the relative youth of Typst (~5) compared to LaTeX (~40) and (2) the simplicity of the upstream Pandoc template.Typst itself is a very intuitive alternative to LaTeX and (at least to me) is substantially easier to learn and use than LaTeX ever was/is. As such, I think it would be great if some features of the Typst templates could be caught up to
-pdf
outputs.To this end, I've listed out many features where the implementation would be only a few lines and thus hopefully easy to maintain. Of course, in aggregate, this would add quite a few features at once.
I'm starting here with (1) default suggestions, (2) example syntax for how it would be implemented based on the YAML variables, and (3) details explaining the rationale behind any choices. If there are changes that would be helpful, I'm happy to make a (series of) pull requests to introduce these features to Quarto's templates.
One important thing to note: Some of these examples may need to be prefixed by
#
to start code while others may need to have#
removed. Each of those is context-dependent on where the "best" place to insert such a fix would be. The rest of the content would stay the same.Finally, I realize this is a long list of possibilities.
If you're not open to a pull request on some (or any) of these points, then this discussion just documents how to get the "equivalent" behaviors in Typst formats as in the other pdf formats.
The rest of this proceeds as follows:
Quarto -> Pandoc -> Typst
Pandoc aggressively escapes characters that can cause issues for Pandoc's processing, but would be valid in Typst. This can make it hard to pass things like colors, emails, or urls from Quarto to Typst. Specifically, if you pass a variable from Pandoc (say$my-variable$ ) to Typst, then $my-variable$ gets escaped. So, if you pass
email: chris@example.com
and try to make "$email$", it becomeschris\@example.com
. For things like emails, a simple Typst-evaluated regex might suffice, but it falls apart if you don't know all possible escapes.Instead, if you make
[$email$]
, it passes it as "context". This avoids nasty escape characters. Yet, context is messier to work with. The easiest way to extract text from context is a function like:This short function comes from an old issue but handles this problem very well.
Adding a function like this would also fix printing errors in templates, like the IEEE one. If you render that template, you can see how the Pandoc escaping makes the email links print incorrectly and have invalid links.
Simple updates based on template options
Title & Author
subtitle
Default:
none
This example solution is from a prior discussion and was made by
@mcanouil
.thanks
Default:
none
Details: This may actually be one of the most complicated suggestions, as it interacts with the title and a counter. However, this is just adding a footnote and using the "*" numbering. We then reset the counter to 0, which could be as simple as
counter(footnote).update(0)
. In case something gets stuck before the title, we can usen => n - 1
.Fonts
linestretch
Can be specified as any non-negative number.
Default:
1
(single spacing)set par(leading: linestretch * 0.65em)
Details: 0.65em is the measurement for one line.
mathfont
Default: New Computer Modern Math
Details: New Computer Modern Math is shipped with Typst.
codefont
Default: DejaVu Sans Mono (shipped with Typst)
Details: DejaVu Sans Mono is shipped with Typst.
Colors
linkcolor
Default: "#800000"
Details: Matches Quarto's PDF template default.
Related discussion: #9175
filecolor
,urlcolor
Default: "#800000"
Details: Try to match Quarto's PDF template default, but not possible in a simple way.
Note: These can't be separated without some regex, as far as I know.
citecolor
Default: "#0000FF"
Details: Try to match Quarto's PDF template default, but not possible in a simple way.
This catches both crossreferences and bibliographic references.
Note: These can't be separated, as far as I know.
toccolor
Default: "#0000FF"
Details: Not 100% sure the default, but this looks right to me from the LaTeX.
Metadata
keywords
Default: [don't set]
Details: Defaults to an empty array in Typst.
title-meta
Default:
title
(or [don't set])Details: Defaults to
none
in Typst.author-meta
Default: [don't set]
Details: Defaults to an empty array in Typst.
date-meta
Default:
auto
Details: Set by Typst to current date by default
More difficult layout problems
layout
These have very simple adjustments in theory.
Each fix is a line or two, but they are currently hardcoded when converted from Quarto to Typst.
For example, see this line.
cap-location
Problem: This is hardcoded when creating the figures and tables.
Otherwise, changing the default should be as simple as combining both the table and figure suggestions.
fig-cap-location
Problem: This is hardcoded when creating the figures.
Otherwise, changing the default should be a single line.
Default: "bottom"
Note: Also listed in Figures in the PDF Options document.
tbl-cap-location
Problem: This is also hardcoded when creating the figures.
Otherwise, changing the default should be a single line.
Default: "top"
Note: Also listed in Tables in the PDF Options document.
Beta Was this translation helpful? Give feedback.
All reactions