-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
typst images are block elements unless there's a box() around them #9104
Comments
I'm sorry, I think we need to reopen this. I only now realize the fix isn't good in the presence of relative sizes. Consider this:
It'll make the image 20%^2 = 4% of the width... |
OK, so what's the fix? Is it just a simple matter of making the inner width always 100%? |
Does the "not providing width for the image" approach still work when the box size is bigger than the image's native size? |
Isn't the pure typst behavior making the image take the full page width? If so, then setting width to 100% in a block-level image should have the same result, right? |
I think there's a simple algorithm that works here. I think Pandoc users would expect inline unstyled images to behave like they do in other Pandoc formats. So if the image is given without width or height attributes, then Pandoc automatically determines sizing information, and adds it, in pts, to a box surrounding the image. If Pandoc is given width or height attributes, on the other hand, then these attributes are the ones that determine the box attributes. The only important thing here is that these attributes shouldn't be repeated in both box and image to avoid compounding relative sizing. I was originally advocating for an attribute that restores the pure-typst behavior, but I think that option is easily achieved with a RawInline, so I no longer think that's truly necessary. It's still useful for Pandoc to be able to set width/height on either the box or the image, because that's not something users can do easily (notably from Lua in our case). But if the choice is to not provide such information, then the RawInline element works fine. |
My question was whether the appearance in typst is ever different between
and
(as independent blocks). If not, then we can get the behavior of a "pure typst" plain image in typst by just adding the width attribute. No need to result to raw. Anyway, I think we're in agreement about the algorithm: basically, do what we now do, but don't duplicate the width/height attributes; instead, just add them to the box and leave them off the image. |
I'm sorry I am quite confused as to the current status of this issue as it may pertain to standalone images. Currently in Pandoc we have this:
The |
I have fixed this issue along the lines agreed to above. More testing is welcome, of course. @iandol maybe you should introduce a separate issue. In your case is the problem with 1480pt that it is wider than the page width? We are trying here to make the typst writer behave like other pandoc writers behave. Other writers don't automatically resize images to page width. Instead, they leave the image at its native size, unless a size attribute is specified. Note that the LaTeX writer has some special code in the preamble that prevents images from overflowing the page; it would be nice to have something like that here, but I'm not sure how to achieve it. In any case, this should really be added as a separate issue. |
Explain the problem.
The output generated by the Typst writer uses
image()
directly, which is a block-level element. Typst's documentation on box explains:As a result, we get this:
This paragraph doesn't render as expected:
When wrapped around a box() call, this does:
We get this:
Pandoc version?
How to fix
Unfortunately, it's not a good idea to put a
box()
around every time, because the box will then be sized as big as possible by default (because of typst's layout algorithm). I've asked the typst devs about a trick for this, and am waiting for their answer. With that said, if users size their images explicitly as above, then it is safe to wrap them in abox()
call, since that's almost certainly going to produce the behavior the user expects.The text was updated successfully, but these errors were encountered: