Skip to content

Allow obtaining sub-parts of some primitive types #753

@PgBiel

Description

@PgBiel

So, right now, when you have something like 100% + 2em + 2pt, internally that's somewhat divided between a relative part (100%) and an absolute part (2em + 2pt). Likewise, for strokes, you have something like 2pt + blue, which is divided between thickness (2pt) and color (blue). Right now, to perform this separation in typst, using regex with repr and eval is necessary. I think this indicates to me that this should definitely be a built-in feature to avoid that hassle. Maybe we could use some notation like stroke.thickness(2em + blue), which returns 2em; or stroke.thickness(2pt) which will return 2pt; or stroke.color(2pt + red) which will return red; and so on. Same for relative lengths - something (maybe?) like length.relative(50% + 2pt) returning 50%; length.absolute(60% + 4pt) returning 4pt, and so on. Of course, that notation can vary (personally, I think the stroke one is fine, but the length one could be made better, perhaps). I could perhaps attempt to eventually PR this depending on what is suggested here. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or requestscriptingAbout Typst's coding capabilities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions