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

Let smallcaps be element function #3977

Closed
Coekjan opened this issue Apr 22, 2024 · 7 comments · Fixed by #3981
Closed

Let smallcaps be element function #3977

Coekjan opened this issue Apr 22, 2024 · 7 comments · Fixed by #3981
Labels
feature request New feature or request styling About set and show rules or style properties text Text layout, shaping, internationalization, etc.

Comments

@Coekjan
Copy link
Contributor

Coekjan commented Apr 22, 2024

Description

emph, strong, highlight and some other functions are element functions, so that we can use set/show rules to customize their behavior. This issue suggests smallcaps be element function.

For the past few days, I looked into how we can customize text font of smallcaps. Especially in math equations, the default math font does not support smallcaps feature. For fine-grained adaptation purpose (i.e. just change font of smallcaps, instead of all text font in math environment), I attempted to customize font of smallcaps in math equations using show rules, but I found it impossible since smallcaps is not element function.

Use Case

#show smallcaps: text.with(font: "linux libertine", fill: red)

just like what we can do with strong, emph...

@Coekjan Coekjan added the feature request New feature or request label Apr 22, 2024
@Coekjan
Copy link
Contributor Author

Coekjan commented Apr 22, 2024

If this is a good suggestion, I can help to implement it and send a PR :)

@Coekjan
Copy link
Contributor Author

Coekjan commented Apr 22, 2024

I slightly modified crates/typst/src/text/{smallcaps,mod}.rs, and now it can achieve the behavior:

#set align(center)

$ #smallcaps[SmallCaps] $

#show smallcaps: set text(font: "linux libertine", fill: blue)

$ #smallcaps[SmallCaps] $

#show math.equation: it => {
  show smallcaps: set text(font: "linux libertine", fill: red)
  it
}

$ #smallcaps[SmallCaps inside Math Equation] $

#smallcaps[SmallCaps outside Math Equation]

image

@Coekjan
Copy link
Contributor Author

Coekjan commented Apr 23, 2024

The reason why smallcaps in math behaves differently seems relative to #366

@Enivex
Copy link
Collaborator

Enivex commented Apr 23, 2024

The reason why smallcaps in math behaves differently seems relative to #366

It is. Math fonts rarely (never?) have small caps, because they're not intended for use as a text font.

@Coekjan
Copy link
Contributor Author

Coekjan commented Apr 23, 2024

It is. Math fonts rarely (never?) have small caps, because they're not intended for use as a text font.

When writing algorithm (using algorithmic:0.1.0), I meet such need:

#algorithm({
  import algorithmic: *
  Function("NewTime", args: ($t$,), {
    While(cond: $#CallI("CmpTime")[$t_"new"$ = #CallI("GetTime")[], $t$] != 1$, {
      Cmt[pause for a while and retry]
      State[*continue*]
    })
    Return[$t_"new"$]
  })
})

Where CallI will call smallcaps on function name "CmpTime". If using the default font, as you say, the smallcaps makes no effects. That's why I want to change font for smallcaps (by show rule) in math equations.

Though my need can be satisfied when that issue is resolved, I see that issue has been opened for a long time and seems not to be resolved in short time. Maybe just making smallcaps an element function could be a fast (and harmless?) solution.

@laurmaedje
Copy link
Member

The reason why I didn't make smallcaps an element function is that in contrast to emph, strong, highlight, etc. it isn't really a semantic thing to apply, but rather a purely visual text property. So it should rarely make sense to make all smallcaps red. At this point, you are assigning some semantic meaning to it that should be expressed through a new function.

At the same time, I can see how it's useful to be able to process smallcaps with show rules, since sometimes the smallcaps are in a different font and that can't be selected automatically by Typst.

@laurmaedje laurmaedje added styling About set and show rules or style properties text Text layout, shaping, internationalization, etc. labels Apr 29, 2024
@Coekjan
Copy link
Contributor Author

Coekjan commented Apr 29, 2024

Thanks for your reply.

So it should rarely make sense to make all smallcaps red.

Yes, the example (fill smallcaps red) I post above is just to demo the show rule behavior.

The reason why I didn't make smallcaps an element function is that in contrast to emph, strong, highlight, etc. it isn't really a semantic thing to apply, but rather a purely visual text property... At this point, you are assigning some semantic meaning to it that should be expressed through a new function.

At the same time, I can see how it's useful to be able to process smallcaps with show rules, since sometimes the smallcaps are in a different font and that can't be selected automatically by Typst.

I agree with your opinion that smallcaps is a visual property, and still hope it an element function so that we can customize text font (or other styles) in smallcaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request styling About set and show rules or style properties text Text layout, shaping, internationalization, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants