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

[proposal] Syntax for the previous element #606

Open
tapyu opened this issue May 24, 2024 · 2 comments
Open

[proposal] Syntax for the previous element #606

tapyu opened this issue May 24, 2024 · 2 comments
Assignees

Comments

@tapyu
Copy link
Contributor

tapyu commented May 24, 2024

Inspired by () for the previous coordinate, I propose anything equivalent to refer to a previous element. For instance:

line((y: 10), (rel: (x: 10)), mark: (end: ">"))
line("{}.5%", (rel: (y: 10)), mark: (end: ">"))

where {} would refer to the last element (i.e., the line).

Motivation

Although name: "my-name" would also serve for this purpose, I frequently find myself in a situation where I want to refer to the previous element as an starting point for the next element, and nothing more. Creating a label for this purpose seems an overkill and makes the syntax unnecessarily lengthy. I do believe that this proposal would make the typst syntax even more convenient. Regarding using "{}" or something else, it is opened to discussions.

@Bahex
Copy link

Bahex commented Jul 9, 2024

Using version 0.2.2, it seems like the same name can be used multiple times in a context, and only the latest usage stays addressable. So as a stopgap you can give all elements the name "{}" (or even "") by default and address the latest unnamed element like "{}.30deg" (or ".30deg")

let line = line.with(name: "")
line((y: 10), (rel: (x: 10)), mark: (end: ">"))
line(".5%", (rel: (y: 10)), mark: (end: ">"))

@tapyu
Copy link
Contributor Author

tapyu commented Jul 9, 2024

I know that. The point of this issue is to propose making this name built-in so that we don't need to name all elements as "{}" or something. If you think let line = line.with(name: "{}") is already enough to address it, so I will close this issue.

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

No branches or pull requests

4 participants