Skip to content

Fetch output format in Typst#5755

Closed
Andrew15-5 wants to merge 1 commit intotypst:mainfrom
Andrew15-5:multioutput-html
Closed

Fetch output format in Typst#5755
Andrew15-5 wants to merge 1 commit intotypst:mainfrom
Andrew15-5:multioutput-html

Conversation

@Andrew15-5
Copy link
Contributor

@Andrew15-5 Andrew15-5 commented Jan 25, 2025

Since currently it's not possible to conditionally use paged output (e.g., PDF) and HTML output (e.g., when overriding body tag), I whipped up this workaround.

It adds sys.output-format that can be "pdf", "png", "svg", or "html". For typst query it will use "pdf" since we can't resolve the output format for that command (could potentially change it to none or "query").

I thought that instead of just providing the same target() output but non-contextual, I would just add all inputs. This can make the document more customizable. Which is actually kind of a separate proposal, though it is not really how Typst should work.

#if sys.output-format != "html" {
  set page(...)
  [document-body]
} else {
  html.elem("body", attrs: ..., html.frame([document-body]))
}

@laurmaedje
Copy link
Member

The target() API is designed exactly for this need. It is intentionally

  • more coarse in granularity (paged/html instead of pdf/png/svg/html) so that users can continue relying on pdf/png/svg looking the same.
  • contextual because with laid-out-SVG-in-html (via html.frame), the mode of operation can switch within the document.

Adding an additional API that serves the same purpose is redundant and will lead to confusion. Moreover, it will cause problems down the road if people use this API instead of the contextual API in packages because then their code will not compose correctly with html.frame.

The target() API is also intentionally only supported behind the HTML feature because it is not yet finalized.

@laurmaedje laurmaedje closed this Jan 25, 2025
@Andrew15-5
Copy link
Contributor Author

I'll close it, since it's highly unlikely something will come out of it, fix- or proposal-wise. But I think it's still a nice workaround and a feature for those who really want the ability to check the output format of the document (and use it conditionally for virtually anything). For example, you can just change background or margin, or make completely different outputs.

@Andrew15-5
Copy link
Contributor Author

Oops, already closed.

@Andrew15-5 Andrew15-5 deleted the multioutput-html branch January 25, 2025 13:58
@ensko
Copy link
Contributor

ensko commented Jan 25, 2025

You can always use --input format=... if your document depends on stuff that Typst doesn't expose to you. As for whether Typst should expose the output format, I agree with Laurenz.

@Andrew15-5
Copy link
Contributor Author

Andrew15-5 commented Jan 25, 2025

Since you've mentioned it, this doesn't work in the web app. I think the web app uses a different World. If so, then I can't change it myself, but if I could, then sys.output-format would work in the web app as well.

@ensko
Copy link
Contributor

ensko commented Jan 25, 2025

in the web app this depends on typst/webapp-issues#391, yes (sort of, that issue is specifically about batch --input but if it's added the basic use case would also be supported I'd imagine)

@Andrew15-5
Copy link
Contributor Author

Yeah.

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.

3 participants