Typst: Scaling Spacing Between Premises With Text Size

by SLV Team 55 views
Scaling Spacing Between Premises with Text Size in Typst

Hey guys! Let's dive into an interesting discussion about how the spacing between premises should scale with text size in Typst. This is a crucial aspect of ensuring that your documents and presentations look professional and polished, especially when dealing with different text sizes. So, let's break it down and see why this matters and how we can address it.

The Issue: Fixed Spacing vs. Scalable Spacing

The core of the problem lies in the current default spacing between premises in Typst. As it stands, this spacing is defined in fixed units. What does this mean? Well, it means that the spacing remains constant regardless of the text size you're using. You can find this fixed spacing defined in the curryst.typ file on GitHub. Specifically, the lines of code that dictate this are:

https://github.com/pauladam94/curryst/blob/f4f88e887cac037dfcd26748f18dc781a039dc7a/curryst.typ#L40-L41

Now, why is this a problem? Imagine you're working on a presentation, and you decide to increase the default text size to make your content more readable. With fixed spacing, the gap between your premises starts to look smaller and smaller relative to the text. This can lead to a cluttered and visually unappealing output. Think of it like wearing shoes that are the right size initially but become too tight as your feet swell – it just doesn't fit right!

Why Fixed Spacing Fails with Larger Text Sizes

When the text size increases, the fixed spacing becomes disproportionately small. This is especially noticeable in presentation slides where larger fonts are common to enhance readability from a distance. The result? Your beautifully crafted logical arguments can end up looking cramped and difficult to follow. It's like trying to fit too much into a small box – things get messy and hard to decipher.

Impact on Presentation Slides

The issue is particularly glaring when using curryst in presentation slides. The default settings, which might look perfectly fine for standard document text sizes, can appear completely off when the text size is bumped up. This is because the fixed spacing doesn't scale proportionally with the text, leading to a visually jarring experience. It’s like having a great idea but not being able to present it effectively because the visuals are distracting.

Minimal Reproduction Case: Seeing the Problem in Action

To really drive the point home, let's look at a minimal reproduction case. This is a simple code snippet that demonstrates the issue clearly. Here’s the Typst code:

#import "@preview/curryst:0.5.1": rule, prooftree

#let infer(..args) = prooftree(rule(..args))

#let der = $thick tack.r thick$
#let app(t,u) = $#t med #u$

#let application-rule = infer($Gamma der app(t, u) : B$, $Gamma der t : A -> B$, $Gamma der u : A$)

// default size: looks fine
$ #application-rule $

// larger size: looks meh
#set text(size: 20pt)
$ #application-rule $

// larger size: looks terrible
#set text(size: 30pt)
$ #application-rule $

In this code, we're defining a simple inference rule and then displaying it at different text sizes. When you run this code, you'll see that at the default size, the spacing looks fine. However, as you increase the text size to 20pt and then to 30pt, the spacing becomes progressively worse. This visual example really highlights the need for a scalable solution.

Visual Evidence: The Image Speaks Volumes

To further illustrate the problem, a visual result is provided. This image captures the output of the code snippet at different text sizes, making the issue immediately apparent. You can see how the spacing shrinks relative to the text, leading to a less readable and aesthetically pleasing result.

<img width="797" height="480" alt="Image" src="https://github.com/user-attachments/assets/02c1da47-2cfc-4b3a-b4f6-29c222390271" />

The image clearly shows that as the text size increases, the fixed spacing becomes inadequate, causing the premises to appear cramped together. This visual representation is a powerful way to understand the problem and the need for a fix.

The Solution: Scalable Spacing

So, how do we fix this? The answer is scalable spacing. Instead of using fixed units, the spacing between premises should be defined in units that are relative to the text size. This way, as the text size increases, the spacing will increase proportionally, maintaining a consistent and visually appealing layout.

Benefits of Scalable Spacing

  1. Consistent Appearance: Scalable spacing ensures that the layout looks consistent across different text sizes. Whether you're using a small font for a detailed document or a large font for a presentation, the spacing will always be proportional to the text.
  2. Improved Readability: By maintaining appropriate spacing, scalable spacing enhances the readability of your content. Premises won't appear cramped, and the logical structure of your arguments will be clear.
  3. Professional Look: A document with scalable spacing looks more polished and professional. It gives the impression that attention has been paid to the details, which can significantly impact how your work is perceived.
  4. Flexibility: Scalable spacing provides flexibility in design. You can easily adjust the text size without worrying about the spacing becoming an issue. This is particularly useful in dynamic environments where text sizes might need to be adjusted on the fly.

How to Implement Scalable Spacing

Implementing scalable spacing involves changing the way the spacing is defined in the curryst.typ file. Instead of using fixed units (like pt or px), we need to use relative units (like em or %). These units are relative to the font size, ensuring that the spacing scales with the text.

For example, if the current spacing is defined as 5pt, we might change it to 0.2em. This means that the spacing will be 0.2 times the current font size. So, if the font size is 12pt, the spacing will be 2.4pt, and if the font size is 24pt, the spacing will be 4.8pt. This simple change can make a huge difference in the visual appearance of your documents.

Example Implementation

To give you a clearer idea, let’s look at how this might be implemented in the code. Currently, the spacing might be defined like this:

#let premise-spacing = 5pt

To make it scalable, we would change it to something like this:

#let premise-spacing = 0.2em

This small change ensures that the spacing scales with the text size, providing a much better visual result.

Community Discussion and Next Steps

This issue has sparked a great discussion within the Typst community, and it’s fantastic to see people actively working to improve the platform. Addressing this spacing issue is a significant step towards making Typst an even more powerful and user-friendly tool for creating beautiful documents and presentations.

Pauladam94 and Curryst

The discussion was initiated by pauladam94, who highlighted the problem and provided a clear example of the issue. The context of this discussion revolves around the curryst package, which is used for creating proof trees in Typst. This package is particularly useful for academics and anyone working with formal logic or mathematics.

Next Steps for Improvement

  1. Update the curryst Package: The most immediate step is to update the curryst package to use scalable spacing. This will ensure that anyone using the package benefits from the improved layout.
  2. Contribute to Typst Core: The principles of scalable spacing can also be applied more broadly within Typst. By incorporating scalable spacing into the core typesetting engine, we can ensure that all documents benefit from this improvement.
  3. Community Feedback: Gathering feedback from the community is crucial. By sharing examples and discussing different approaches, we can refine the implementation of scalable spacing and ensure that it meets the needs of Typst users.

Conclusion: The Importance of Scalable Spacing

In conclusion, the spacing between premises should indeed scale with text size. Fixed spacing, while adequate for some scenarios, falls short when dealing with larger text sizes, particularly in presentations. Scalable spacing ensures a consistent, readable, and professional look across all text sizes.

By understanding the issue, implementing scalable spacing, and engaging with the community, we can continue to make Typst an even better tool for creating stunning documents and presentations. So, let's keep the discussion going and work together to improve Typst for everyone! You guys rock!