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

Allow scale to tolerate absolute lengths #4191

Open
kram-tm opened this issue May 19, 2024 · 1 comment
Open

Allow scale to tolerate absolute lengths #4191

kram-tm opened this issue May 19, 2024 · 1 comment
Labels
feature request New feature or request layout Related to layout, positioning, etc.

Comments

@kram-tm
Copy link

kram-tm commented May 19, 2024

Description

Currently, the scale function only supports values of the type ratio, making it somewhat difficult to resize content to an absolute width/height such as that of the current page or container. This is possible in LaTeX using \resizebox{width}{height}{Foo} (for possible reference, not to add any pressure) and can currently be achieved in Typst by "normalizing" the size of the content to be scaled and multiplying it by a given length as in:

#layout(container => {
  let contents = $a^2 = b^2 + c^2$
  let contents-dimensions = measure(contents)
  let scale-ratio = container.width / contents-dimensions.width * 100%
  scale(reflow: true, x: scale-ratio, y: scale-ratio, contents)
})

Notably, setting contents to something that spans multiple lines such as lorem(50) here would produce questionable output due to the nature of measure.
image

Use Case

While I don't like tautologies, I'm feeling the urge to simply say that this would make scaling to an absolute length easier, which in turn would facilitate the use case presented above, among others, without needing to resort to using math explicitly. Admittedly, the uses of this are limited by the fact that most people resize images, where absolute lengths are indeed valid; however, I've seen a question from three different people on the Discord server about resizing text, a fletcher diagram as well as an equation to fit exactly in a page. This may not be a lot in terms of demand, but is indicative of utility.

@kram-tm kram-tm added the feature request New feature or request label May 19, 2024
@bluebear94
Copy link
Contributor

Would it also make sense for scale to allow at most one of x and y to be auto to indicate that that axis should be scaled with the same ratio as the other?

@Enivex Enivex added the layout Related to layout, positioning, etc. label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request layout Related to layout, positioning, etc.
Projects
None yet
Development

No branches or pull requests

3 participants