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

[Features] Preserve heading style in title and subtitle #71

Closed
f3fora opened this issue Sep 5, 2024 · 7 comments
Closed

[Features] Preserve heading style in title and subtitle #71

f3fora opened this issue Sep 5, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@f3fora
Copy link

f3fora commented Sep 5, 2024

I would like to be able to set a style for all heading, which if not explicitly modified in the theme is honored.

For example, I would like to set the style for all the headings, even if they are the title or the subtitle of the slide.
In the following code, I would expect that Title, First Slide and 123 will be always red and smallcaps.
Currently, only 123 is red and smallcaps

Also adding this option in the init of the config-methods doesn't work.

#import "@preview/touying:0.5.2": *
#import themes.simple: *

#show: simple-theme.with(aspect-ratio: "16-9")
#show heading: it => text(fill: red, smallcaps(it))

= Title

== First Slide

=== 123

Hello, Touying!

Hello, Typst!
@OrangeX4
Copy link
Member

OrangeX4 commented Sep 5, 2024

I think that's hard to implement, you might consider setting the color of primary.

@OrangeX4 OrangeX4 added the wontfix This will not be worked on label Sep 5, 2024
@f3fora
Copy link
Author

f3fora commented Sep 5, 2024

As you wish, However, I believe the solution is really simple.

You can just remove the .body in https://github.com/touying-typ/touying/blob/334f8a2190ae1767c269b75474c7d33f0aa8f0bc/src/utils.typ#L344, or at least allow an option to trigger this.

@OrangeX4
Copy link
Member

OrangeX4 commented Sep 5, 2024

Ok, I thought removing .body would cause numbering and outline errors, but it doesn't seem to be. However, there will still be problems with text size. I would consider adding this as an option in the next release. Thanks!

@OrangeX4 OrangeX4 added enhancement New feature or request and removed wontfix This will not be worked on labels Sep 5, 2024
@f3fora
Copy link
Author

f3fora commented Sep 5, 2024

I suggest that the function display current heading can be modified as:

#let display-current-heading(
  self: none,
  level: auto,
  numbered: true,
  hierachical: true,
  depth: 9999,
  setting: body => body,
  ..sty,
) = (
  context {
    let sty = if sty.pos().len() == 0 {
      current-heading => {
        if numbered and current-heading.numbering != none {
          _typst-builtin-numbering(
            current-heading.numbering,
            ..counter(heading).at(current-heading.location()),
          ) + h(.3em)
        }
        current-heading
      }
    } else if sty.pos().len() == 1 {
      sty.pos().at(0)
    } else if sty.pos().len() > 1 {
      panic("sty allows only a positional argument")
    }
    let current-heading = utils.current-heading(level: level, hierachical: hierachical, depth: depth)
    if current-heading != none {
      setting(sty(current-heading))
    }
  }
)

To achieve the same results in e.g. in simple theme, modifying header as

  header: self => display-current-heading(
    setting: utils.fit-to-width.with(grow: false, 100%),
    depth: self.slide-level,
    it => it.body,
  ),

Moreover, given that there is a scale factor in the headings with level 1 and 2 (see https://github.com/typst/typst/blob/8a8c4cec77342cc8c0772122cd2d0a71085c2c24/crates/typst/src/model/heading.rs#L266-L287), one may want to set

#show heading.where(level: 1): set text(size: (1em / 1.4))
#show heading.where(level: 2): set text(size: (1em / 1.2))

@OrangeX4
Copy link
Member

OrangeX4 commented Sep 5, 2024

This doesn't solve the text-size problem and can lead to double numbering. I'd consider adding a 'native' parameter that defaults to false to control this behavior, so that theme developers can choose from it.

@f3fora
Copy link
Author

f3fora commented Sep 5, 2024

Nonetheless, the parameter of sty in the utils.display-current-heading currently is

  • never used in any function call
  • has a wrong check: ...len() > 1 should be ...len() == 1. See:

    touying/src/utils.typ

    Lines 331 to 336 in 334f8a2

    ..sty,
    ) = (
    context {
    let sty = if sty.pos().len() > 1 {
    sty.pos().at(0)
    } else {

After some thoughts, I suggest this implementation:

#let display-current-heading(
  self: none,
  level: auto,
  hierachical: true,
  depth: 9999,
  sty: (setting: body => body, numbering: false, current-heading) => setting({
    if numbering and current-heading.numbering != none {
      _typst-builtin-numbering(
        current-heading.numbering,
        ..counter(heading).at(current-heading.location()),
      ) + h(.3em)
    }
    current-heading.body
  }),
  ..setting-args,
) = (
  context {
    let current-heading = utils.current-heading(level: level, hierachical: hierachical, depth: depth)
    if current-heading != none {
      if sty == none {
        current-heading
      } else {
        sty(..setting-args, current-heading)
      }
    }
  }
)

In this way, the current behavior is preserved, and one can easily use a custom sty function.
For the "native" behavior one can simply set sty: it => it or sty: none.

@OrangeX4
Copy link
Member

OrangeX4 commented Sep 5, 2024

I think it's a good idea, and I'll consider adding it in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants