Skip to content

Add outline-title and bookmark-title to headings - #1892

Closed
balthild wants to merge 3 commits into
typst:mainfrom
balthild:main
Closed

balthild wants to merge 3 commits into
typst:mainfrom
balthild:main

Conversation

@balthild

@balthild balthild commented Aug 8, 2023 •

Copy link
Copy Markdown

Closes #1889

Follow-up considerations:

  1. Is it OK to use outline-title as the name of field?
  2. Should we add something like bookmark-title as well to support making the bookmark text different from the outline?

@reknih

reknih commented Aug 10, 2023

Copy link
Copy Markdown
Member

In general, Laurenz does not like hyphenated argument names, but I'd say that in this case, it's okay and quite clear. If you think about something equally clear but more concise, that would be preferable!

Given that outlined and bookmarked are two distinct arguments of the heading function, the title overrides should be too.

@balthild balthild changed the title Add outline-title to headings Add outline-title and bookmark-title to headings Aug 13, 2023
/// as `outline-title`. If `outline-title` is also `{auto}`, the title will
/// be the same as `body`.
#[default(Smart::Auto)]
pub bookmark_title: Smart<Content>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should probably be a string, since it's going to be stringified in the end anyway as it's PDF metadata.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder whether we need it at all. Shouldn't outline_title suffice for pretty much every use case? I think adding too many knobs isn't good either.

@laurmaedje laurmaedje Aug 21, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see that it would be parallel with bookmarked. I can't say that I'm a big fan of that existing either though. But I see how it can be useful, which I'm having a harder time for here. I think a pdf.bookmark function will exist sooner or later (in a pdf module. and there will be a html module for html primitives), which will allow arbitrary customization.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's useful to display something different for the PDF metadata, as it's a string, and content to string conversion isn't always lossless.

I should note that this could very well be reused for something like HTML or EPUB or anything that would take a stringified table of contents.

@laurmaedje laurmaedje Aug 21, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@PgBiel I am actually considering to allow content for set document(title) because it is such a common pitfall. Together with get rules this would allow to move more general properties from the template function to document set rules (also author e.g. which could allow richer standardized metadata like email and institution). For PDF, we would then use the internal content to plain-text functionality that is already used for bookmarks. If we indeed go down that route, it would be strange to introduce further string-only arguments for the sake of PDF.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The benefit of standardization for such metadata of course being that it's easier to switch templates.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure still. I think it might make perfect sense to add extra content to the outline title which you might not want to display in a PDF bookmark, such as a particular footnote (maybe not the best example as we could filter out footnotes, but there could be other kinds of undesirable content).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why would you have a footnote in the outline heading? The example seems pretty contrived to me to be honest.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Well... Another example would be having manual linebreaks in the outline but not in the bookmark (linebreaks in content result in spaces when converted to string, which is not expected in Chinese).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I should note that this could very well be reused for something like HTML or EPUB or anything that would take a stringified table of contents.

Then, the name bookmark-title would be super confusing if there's also outline-title.

@laurmaedje

Copy link
Copy Markdown
Member

Maybe this should also be extended to figures? It could be a separate PR, but might as well have that here too if you're up for it.

@laurmaedje

Copy link
Copy Markdown
Member

If we keep only one field (which I prefer I think), we could also consider calling it short-title (and then short-caption for figure). That would make it a bit more universal.

@reknih

reknih commented Aug 30, 2023

Copy link
Copy Markdown
Member

After discussing this with @laurmaedje, I'm also of the opinion that a heading has a single, semantic short title that should be used for outlines and bookmarks alike. The argument name short-title prevents users from assuming that there are two options as bookmarked and outlined do.

@balthild

balthild commented Aug 30, 2023 •

Copy link
Copy Markdown
Author

@reknih What about the situation I described above? What should I do if I really want to specify different contents for ToC (inside the pages) and PDF bookmarks but there're only one such option?

Well... Another example would be having manual linebreaks in the outline but not in the bookmark (linebreaks in content result in spaces when converted to string, which is not expected in Chinese).

@laurmaedje

Copy link
Copy Markdown
Member

I just had the idea that we could have a more general mechanism for this than adding evermore arguments to all elements. Basically, content that is reactive to the context it is placed into, so that it can be different in bookmark, outline, and normal text. This would require some sort of ancestry handling. I acknowledge that there are significant design challenges for such a generalization though, compared to this PR.

@reknih

reknih commented Sep 4, 2023

Copy link
Copy Markdown
Member

@reknih What about the situation I described above? What should I do if I really want to specify different contents for ToC (inside the pages) and PDF bookmarks but there're only one such option?

Well... Another example would be having manual linebreaks in the outline but not in the bookmark (linebreaks in content result in spaces when converted to string, which is not expected in Chinese).

In general, I think that bookmarks should not contain linebreaks and that therefore Typst should strip them from the short-title. Overall, I fear that documents may be less easy to navigate if a section can have three slightly different titles, one in the heading, one in the outline, and one in the bookmark.

@balthild

balthild commented Sep 4, 2023 •

Copy link
Copy Markdown
Author

In general, I think that bookmarks should not contain linebreaks and that therefore Typst should strip them from the short-title. Overall, I fear that documents may be less easy to navigate if a section can have three slightly different titles, one in the heading, one in the outline, and one in the bookmark.

However, this is a common practice in Chinese publicatons. We avoid breaking inside sense groups, so manual linebreaks are required.

韩立新, 新版《德意志意识形态》研究 (2008):

image

Jürgen Habermas, 公共领域的结构转型 (1999):

image

@laurmaedje

Copy link
Copy Markdown
Member

@balthild The point @reknih made wasn't that the outline can't contain linebreaks, just that even if the short-title contained one, it would be stripped from the PDF bookmark. Since the width of the PDF viewer's outline panel isn't known in advance, it wouldn't make sense to linebreak manually for creating sense groups.

@balthild

balthild commented Sep 4, 2023 •

Copy link
Copy Markdown
Author

@balthild The point @reknih made wasn't that the outline can't contain linebreaks, just that even if the short-title contained one, it would be stripped from the PDF bookmark. Since the width of the PDF viewer's outline panel isn't known in advance, it wouldn't make sense to linebreak manually for creating sense groups.

I stated the difficulty at the comment above... When eliminating linebreaks, some languages (e.g. English, Korean) require replacing the linebreak with a space, and some (e.g. Chinese, Japanese) require no space. Ultimately, what if the linebreak appears at the boundary between a Chinese character and an English word, and different users need to follow different standards that require a space or no space at the boundary? That is is the reason I cannot rely on an any automatic stripping procedure and require manual editing.

@balthild

balthild commented Sep 4, 2023 •

Copy link
Copy Markdown
Author

There are other situations too. One example is when I need to put "subtitles" describing each chapters into ToC but not in the bookmark because it isn't really a part of title or could be too long to fit in the bookmark panel.

Paul Feyerabend, 反对方法 (2007)
image

The bookmark contains only the excerpt of each "subtitles".

image

Axel Honneth, 理性的病理学 (2022)

image

@laurmaedje

laurmaedje commented Sep 4, 2023 •

Copy link
Copy Markdown
Member

In that case, I think the best way forward is a general mechanism for this as mentioned in the comment above: #1892 (comment) Then, it will work for figure's automatically too and custom elements can make use of the same mechanism.

@laurmaedje

Copy link
Copy Markdown
Member

@balthild @PgBiel We could have a general type for a thing that can be in the document/outline/pdf and make it cast from a dictionary. For now, we would keep the type internal and only use it with heading and figure, so that only the dictionary form is available, but perhaps down the road it could be exposed so that is also works for user-defined elements (once that's a thing).

Before:

#heading(
  [A],
  outline-title: [B],
  bookmark-title: "C",
)

#figure(
  [Body],
  caption: [A],
  outline-caption: [A],
)

After:

#heading((
  default: [A],
  outline: [B],
  bookmark: "C",
))

#figure(
  [Body],
  caption: (
    default: [A],
    outline: [B],
  )
)

We could go with

  • default / outline / bookmark (naming the default one is a bit hard, default feels a bit off)
  • long / short / outline / bookmark (two semantic ones and two specific ones, short would be a shorthand for outline and bookmark).

The type itself should be an element with a default show rule showing, well, the default. That way it.body on a heading continues to work as before while it.body.outline gives you the outline title.

@laurmaedje

Copy link
Copy Markdown
Member

I'm closing this for now. If work on the alternative design starts, this could be reopened or there can be a new PR.

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.

Different heading text for outline/bookmark and displaying

4 participants