Skip to content

Add support for page references through new ref.form property#4729

Merged
laurmaedje merged 7 commits intotypst:mainfrom
mkorje:pageref
Nov 12, 2024
Merged

Add support for page references through new ref.form property#4729
laurmaedje merged 7 commits intotypst:mainfrom
mkorje:pageref

Conversation

@mkorje
Copy link
Collaborator

@mkorje mkorje commented Aug 11, 2024

Closes #2873.

Although now in 0.11 it is fairly simple to write a pageref() function yourself in Typst (see #2873 (comment) by @laurmaedje), the consensus in the linked issue seems to be that this should be built-in. This PR does just that.

I'm not sure whether it should be scoped with ref or not. Currently it isn't, and can be called with #pageref(). Since pageref() can take any label (not just ones attached to elements that are referenceable), imo it doesn't quite make sense being #ref.page().

I also added the function in #2873 (comment) to the doc comment of pageref(). I think it is a good example of context, though maybe it would be better placed elsewhere.

@laurmaedje
Copy link
Member

I think it is very close to ref and we should reflect that in the design. Both take a label and cross-reference it. ref requires the element to be referenceable because the default form requires a supplement and numbering. But the page form doesn't need that so it can have other requirements.

So, I think perhaps the best solution is not even ref.page, but rather ref(<label>, form: "page"). Similar to cite(.., form: ".."). And ref.form would be "normal" | "page". What do you think?

@mkorje
Copy link
Collaborator Author

mkorje commented Aug 13, 2024

Okay I see what you mean, and I agree that is a nicer solution.

Just two questions on how ref should then work with forms.

  • Do you think that the "page" form should allow the target to be an entry from the bibliography?

  • Should the default supplement for the "page" form be none? Or, should it be similar to a figure's supplement where it is based on the kind and the active text language? So maybe the page element function has the argument supplement: auto added, which defaults to the equivalent of "page" in the set language. That way, users get (a perhaps more expected, as in, more inline with the "normal" form) "page X" (in their language) when using the "page" form.

    I think it makes a lot of sense to at least add a supplement argument, with default none, to page which is used as the supplement in the "page" form.

@mkorje mkorje marked this pull request as draft August 13, 2024 08:14
@laurmaedje
Copy link
Member

Do you think that the "page" form should allow the target to be an entry from the bibliography?

I'm not sure how useful it is, so I think I would skip it.

Should the default supplement for the "page" form be none? Or, should it be similar to a figure's supplement where it is based on the kind and the active text language? So maybe the page element function has the argument supplement: auto added, which defaults to the equivalent of "page" in the set language. That way, users get (a perhaps more expected, as in, more inline with the "normal" form) "page X" (in their language) when using the "page" form.

Tricky question. But I general agree that I would expect it to behave similarly to normal refs.

@laurmaedje laurmaedje changed the title Add built-in pageref() element function Add support for page references through new ref.form property Aug 15, 2024
@mkorje mkorje marked this pull request as ready for review August 18, 2024 15:53
@mkorje
Copy link
Collaborator Author

mkorje commented Aug 18, 2024

I've added page.supplement so page refs have similar behaviour to normal refs. I'm just not sure whether there's any point in implementing the Synthesize trait for Packed<PageElem>. I'm not sure what situation would require its supplement to be resolved from auto before show rules. It makes sense for headings or figures, but pages I'm not so sure.

@laurmaedje
Copy link
Member

I'm just not sure whether there's any point in implementing the Synthesize trait for Packed.

No, it doesn't make sense. Also since instances of PageElem won't exist anymore with #4840.

@mkorje
Copy link
Collaborator Author

mkorje commented Aug 26, 2024

I think I've fixed everything up so that it all works now that #4840 has been merged. Though I might have missed some things that need to be done differently.

@laurmaedje laurmaedje added the waiting-on-review This PR is waiting to be reviewed. label Sep 2, 2024
@EpicEricEE
Copy link
Contributor

Can we use the translations from babel?

@mkorje
Copy link
Collaborator Author

mkorje commented Sep 5, 2024

Can we use the translations from babel?

We should be able to. I didn't want to go through babel and try to add them to this PR though until after its been reviewed.

I am also not sure whether for other languages the following are the same as in English: page number after the page word, capitalisation of the page word (*), the grammar. Though I suppose this falls under #2485.

(*) In the current implementation, the page word "Page" is always capitalised. I don't know if this is the right default; for figures or equations it makes sense for the word to be capitalised. I guess ideally we would automatically detect if ref is called at the start of the sentence to decide on the capitalisation (but this is certain to cause issues for other languages and be annoying in some situations).

Copy link
Member

@laurmaedje laurmaedje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling suppelements properly is really tricky (not just for page references, more generally). With starting sentence, language, etc. Maybe there's a reason why LaTeX doesn't add a supplement by default ...

@laurmaedje laurmaedje removed the waiting-on-review This PR is waiting to be reviewed. label Sep 26, 2024
@laurmaedje
Copy link
Member

We should be able to. I didn't want to go through babel and try to add them to this PR though until after its been reviewed.

I think we could add translations now.

@mkorje
Copy link
Collaborator Author

mkorje commented Sep 27, 2024

I'll have a look at doing that.

@mkorje mkorje force-pushed the pageref branch 2 times, most recently from 888ac0f to 285135e Compare September 27, 2024 09:29
@mkorje
Copy link
Collaborator Author

mkorje commented Sep 27, 2024

A couple of things from my attempt at adding translations, using the info from babel.

  • For languages with Latin alphabets, I've made the first letter lowercase. The babel translation files appear to be inconsistent with the capitalisation, so I have no idea if this is correct for all these languages.
  • he is RTL I think, and might be wrong in the files.
  • tl has no translations at all.

@mkorje

This comment was marked as resolved.

@mkorje mkorje force-pushed the pageref branch 2 times, most recently from df293a5 to f05bcd8 Compare September 27, 2024 12:55
heading = الفصل
outline = المحتويات
raw = قائمة No newline at end of file
raw = قائمة
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "raw" in this context? because the Arabic word means "menu".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a code listing from a backtick block

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah following the git blame it seems I am to blame, but this does not sound right. Apparently the etymology for "listing" is that it is, literally, a printed list of lines.

I do not actually know what a good Arabic word for that would be. قائمة (which does mean List, in my defense) is not it, however. Maybe مثال , "Example" ?

(In topic, the word for "page" is correct.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got curious and did a bit of Googling, and it seems I found a suitable Arabic word: عادي. The phrase نص عادي is used in the Arabic Wikipedia to denote the term "plain" or "raw" text.

So, it's probably better to use the word عادي as it seems to be the closest and most commonly used term for conveying "plain" or "raw" text.

And the word قائمة really only shows images related to menus and lists😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

عادي means regular. Has nothing to do with code, or code listings

I spent the day yesterday looking at Arabic computer papers, they either use شكل meaning figure or nothing at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it'd be best to create an issue for the translation of raw, and move this discussion there. Unless a correct translation has been decided upon, then I guess I can add it to this PR.

@laurmaedje laurmaedje added this pull request to the merge queue Nov 12, 2024
@laurmaedje
Copy link
Member

Thank you! I was a bit unsure about this but it's true that if we change the reference system in the future in a larger way (which I think will be necessary), things will be highly breaking either way.

Merged via the queue into typst:main with commit 8d4f01d Nov 12, 2024
@mkorje mkorje deleted the pageref branch November 12, 2024 13:00
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.

Pageref in Typst like it exists in LaTeX

7 participants