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

Add option to export PDF on type only when document has a title #555

Open
hffeka opened this issue Aug 25, 2024 · 5 comments · May be fixed by #1142
Open

Add option to export PDF on type only when document has a title #555

hffeka opened this issue Aug 25, 2024 · 5 comments · May be fixed by #1142
Labels
enhancement New feature or request export Features about exporting documents

Comments

@hffeka
Copy link

hffeka commented Aug 25, 2024

Motivation

Currently, I can only use onType in my workflow using Zathura for previewing. But whenever I create and edit modules / templates, I have to delete a bunch of unnecessary PDFs.

The onDocumentHasTitle option could solve this, if you could choose to pair it with either onSave or onType.

Description

Many possibilities for implementation. I guess the most simple one would be to add one additional option that would combine onDocumentHasTitle and onType.

@hffeka hffeka changed the title Add option to export PDF on save only when document has a title Add option to export PDF on type only when document has a title Aug 25, 2024
@Myriad-Dreamin
Copy link
Owner

Myriad-Dreamin commented Aug 25, 2024

I already noticed that it is not composable, but I didn't have time to improve it. There is a thing remaining to discuss, how could we design condition syntax to tell LSP to when export a document. Besides I don't want to break existing configurations, so I would like to improve export configuration totally on new configuration items and get our more powerful configuration work there.

@Myriad-Dreamin
Copy link
Owner

possibly design: use typst syntax, and provides several usable varaibles, and we can have conditions like:

  1. query(<label-that-indicates-I-m-a-main-file>).len() > 0
  2. documentTitle.len() > 0
  3. ("typed" in signals) and documentTitle.len()
  4. ("saved" in signals) and documentTitle.len()

@hffeka
Copy link
Author

hffeka commented Aug 25, 2024

I don't actually know Rust or the codebase enough to offer any valuable insight here. Just wanted to share since it's one of my biggest wishes for the LSP - that maybe there would be more people that share my sentiment.

Is there a reason to not simply add a new configuration option in addition to the existing ones, where it conditionally uses onType if the document has a title? Based on my layman understanding that wouldn't be a breaking change.

@Myriad-Dreamin
Copy link
Owner

Myriad-Dreamin commented Aug 25, 2024

Is there a reason to not simply add a new configuration option in addition to the existing ones, where it conditionally uses onType if the document has a title? Based on my layman understanding that wouldn't be a breaking change.

Adding onDocumentHasTitleAndOnType sounds like a temporary solution, since:

  1. other exporters like svg exporter cannot use the configuration, since it is only configured for pdf export.
  2. One cannot combine onDocumentHasTitle with onTyped, since it doesn't support condition expression.
  3. If we have more predicate on documents, this will increase the matrix rapidly. Like we may add onDocumentIsNotEmpty then we should have onDocumentIsNotEmptyAndOnType as well. We may continue have onDocumentIsNotEmptyAndOnDocumentHasTitleAndOnType.
  4. For previewing, we may have dedicate previewing feature, so only export PDF onDocumentHasTitle when on saved for final export sounds enough.

We may move things towards a new single export configuration that solve above all problems:

  1. The export configuration should support all rest export targets, like SVG or HTML.
  2. For example, a such configuration may be:
{ "export": [{"when": "onTyped", "filter": "query(document).first().title.len() > 0"}] }

You even get rid of "onDocumentHasTitle" by nice naming convention. Note we cannot do it by default since it is a user preferred convention rather than one is forced by official typst.

{ "export": [{"input": "**/*/main.typ", "when": "onTyped"}] }

Btw, for other formats, it may be:

{ "export": [{"format": ["html", "pdf"], "input": "**/*/main.typ", "when": "onSaved"}] }

@Myriad-Dreamin Myriad-Dreamin added the enhancement New feature or request label Aug 26, 2024
@hffeka
Copy link
Author

hffeka commented Aug 26, 2024

Ah, makes sense. That would be very nice indeed.

@Myriad-Dreamin Myriad-Dreamin added the export Features about exporting documents label Oct 9, 2024
@Myriad-Dreamin Myriad-Dreamin linked a pull request Jan 9, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request export Features about exporting documents
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@Myriad-Dreamin @hffeka and others