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

Color text on set of subslides #111

Closed
JoshuaLampert opened this issue Nov 4, 2024 · 11 comments
Closed

Color text on set of subslides #111

JoshuaLampert opened this issue Nov 4, 2024 · 11 comments
Labels
enhancement New feature or request

Comments

@JoshuaLampert
Copy link
Contributor

First of all, thank you for the very nice package. I recently built my own template based on my previous LaTeX template and managed to create almost identical results (while benefiting from typst and touying compared to LaTeX and beamer).
I mainly have two issues, which currently hinder me in completely switching to typst for presentations (this issue and an upcoming one).
I usually heavily use coloring of certain parts (in LaTeX with \color<>[]{}), i.e. I want some text (or part of a formula) to be colored only in a set of subslides. If I haven't missed anything, this is currently not supported by touying out-of-box. After looking at the source code, I figured out I can hack something together by defining it on my own. See https://typst.app/project/r2RWPmJouYepvYdkL3EtPE for an MWE. This already works quite nicely in simple situations, but doesn't work for more complex ones, where I need the callback style because IIUC I cannot get my colors function by utils.methods(self). Note that my example works without the semi-transparent-cover, which I don't quite understand.
Is there interest in including such a function in touying? If yes, I would be happy to create a PR with an initial suggestion.

@OrangeX4
Copy link
Member

OrangeX4 commented Nov 4, 2024

This is because semi-transparent-cover will place paused contents into a context expression, making touying-fn-wrapper cannot working properly. However, you can use config-methods(color: my color) to add it to methods and obtains it by #let (uncover, color) = utils.methods(self).

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

#let my_color(self: none, visible-subslides, col, cont) = {
  if utils.check-visible(self.subslide, visible-subslides) {
    text(fill: col, cont)
  } else {
    cont
  }
}

#let color(visible-subslides, col, cont) = {
  touying-fn-wrapper(
    my_color,
    last-subslide: utils.last-required-subslide(visible-subslides),
    visible-subslides,
    col,
    cont,
  )
}

#show: simple-theme.with(
  aspect-ratio: "16-9",
  config-methods(
    cover: utils.semi-transparent-cover.with(alpha: 85%),
    color: my_color,
  ),
)

= Title

== Title of Slide

#color("2-", red, "this works as I want")

#slide(repeat: 3, self => [
  #let (uncover, color) = utils.methods(self)
  This doesn't:

  $ f(x) &= (x + 1)^2 \
    uncover("2-", color("2", #red, &= x^2 + x + x + 1)) \
    uncover("3", &= x^2 + 2x + 1)
  $
])

@OrangeX4
Copy link
Member

OrangeX4 commented Nov 4, 2024

Thanks for your comments, I'm not against including such a function into touying, but I think it should be more elegant designed, for example we might use syntax.

#effect("2", text.with(fill: red))[Something]

@OrangeX4 OrangeX4 added the enhancement New feature or request label Nov 4, 2024
@JoshuaLampert
Copy link
Contributor Author

Ah, that makes sense! Thanks!

Thanks for your comments, I'm not against including such a function into touying, but I think it should be more elegant designed, for example we might use syntax.

Yes, that's true. I like your suggestion. That would also make it more general. I would really like to see this feature in touying.

@OrangeX4
Copy link
Member

OrangeX4 commented Nov 4, 2024

I may consider it further in the future, thanks.

@JoshuaLampert
Copy link
Contributor Author

I see a function #effect is included in touying:0.5.4. So thanks a lot for that @OrangeX4. However, I noticed that the callback-style doesn't seem to work with #effect, see my MWE here: https://typst.app/project/rBorvFignPms9v2tUqFSxz. I guess this is because effect is not listed here:

touying/src/configs.typ

Lines 375 to 387 in e54003c

methods: _get-dict-without-default((
init: init,
cover: cover,
uncover: uncover,
only: only,
alternatives-match: alternatives-match,
alternatives: alternatives,
alternatives-fn: alternatives-fn,
alternatives-cases: alternatives-cases,
alert: alert,
show-notes: show-notes,
convert-label-to-short-heading: convert-label-to-short-heading,
)) + args.named(),

Is that intentional? And if not could it be added?
I also noticed a typo in the example of the docstring for the function here:
/// Example: `#effect(text.with(fill: red), "2-")[Something]` will display `[Something]` if the current slide is 2 or later.

I guess the example should rather read #effect("2-", text.with(fill: red))[Something]?

@OrangeX4
Copy link
Member

I forgot to add it to methods, I will add it in the next version.

#effect(text.with(fill: red), "2-")[Something] is right, because I am considering an abbreviation by using #let effect-red = effect.with(text.with(fill: red))

@JoshuaLampert
Copy link
Contributor Author

I forgot to add it to methods, I will add it in the next version.

Great, thanks! Do you have a rough estimate, when that will be? I'm considering updating my template to touying:0.5.4. But if version 0.5.5 will be out soon, I will directly update it to 0.5.5.

#effect(text.with(fill: red), "2-")[Something] is right, because I am considering an abbreviation by using #let effect-red = effect.with(text.with(fill: red))

I'm not sure I understand. visible-subslides and fn are positional arguments. So #effect(text.with(fill: red), "2-")[Something] as you suggest in the example simply errors as it is the wrong order of arguments. In the example you don't use the abbreviation effect-red? But also something like

#let effect-red = effect.with(text.with(fill: red))
effect-red("2-")[Something]

doesn't work because of the same reason. I updated the above link to demonstrate it. Maybe I'm misunderstanding what you mean. Could you clarify?

@OrangeX4
Copy link
Member

I made a mistake, I'm sorry, I will immediately release a new version to fix.

@JoshuaLampert
Copy link
Contributor Author

Thanks!

@JoshuaLampert
Copy link
Contributor Author

I saw your fix f56991b. That already looks nice. I have a small suggestion. I think the easiest is to make the suggestion in a PR. Is this fine for you @OrangeX4?

@OrangeX4
Copy link
Member

Oh, I have already released a new waiting version. Since I have been busy recently, I just rushed to deal with these things, so it may be a little rough :-(

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