Skip to content

Conversation

MDLC01
Copy link
Collaborator

@MDLC01 MDLC01 commented May 21, 2024

This PR implement the design that was briefly discussed on Discord. delim can now be specified in one of the following form.

  • none, for no delimiters.

  • A delimiter to use as the opening delimiter. The closing delimiter is inferred automatically.

    • In case of an "opening", the corresponding closing delimiter is the corresponding "closing".
    • In case of a "closing", the corresponding closing delimiter is the corresponding "opening".
      • For example, specifying delim: ")" results in inverted parentheses.
    • In case of a "fence", the corresponding closing delimiter is the same as the opening delimiter.
  • An array of two delimiters to use respectively as the opening delimiter and as the closing delimiter.

In the definition above, the term "delimiter" refers to a value of one of th following forms.

  • none, for no delimiter.

  • A symbol, or a single-character str.

    • Must be a Unicode math "opening", "closing", or "fence".

"somewhat arbitrary" in the PR title refers to the fact that only "opening", "closing" and "fence" characters are allowed.

Original description.

This PR adds double brackets, triple bars, and angles as valid mat, vec, and cases delims.

I also made it possible to use Unicode characters to specify the delimiters (specifically, "⟦" for double brackets, "‖" for double bars, "⦀" for triple bars, and "⟨" for angles).

Regarding other potential delimiters, I tried double angles, but they did not seem to work in the tests (instead resulting in a box glyph), and fences and double fences, which do not scale.

For reference, below are all the possible delimiters:
Parentheses, brackets, double brackets, curly braces, vertical bars, double vertical bars, angles.

@Enivex
Copy link
Collaborator

Enivex commented May 21, 2024

Is there a specific reason why there is so much duplication when it comes to delimiters? To me, it seems like typst should "know" what all the scalable delimiters are, and allow them where appropriate (matrices, vectors, cases, possibly more?)

@MDLC01
Copy link
Collaborator Author

MDLC01 commented May 21, 2024

I'm not sure exactly, but I figured we needed an enum like Delimiter because a delimiter is inputted as a string by the user, but actually corresponds to two Unicode codepoints (one for the opening delimiter, one for the closing delimiter).

Also, matrices, vectors and cases already share the same Delimiter type.

@Enivex
Copy link
Collaborator

Enivex commented May 21, 2024

I'm not sure exactly, but I figured we needed an enum like Delimiter because a delimiter is inputted as a string by the user, but actually corresponds to two Unicode codepoints (one for the opening delimiter, one for the closing delimiter).

Also, matrices, vectors and cases already share the same Delimiter type.

Does that mean cases automatically gets these as well?

@MDLC01
Copy link
Collaborator Author

MDLC01 commented May 21, 2024

I'm not sure exactly, but I figured we needed an enum like Delimiter because a delimiter is inputted as a string by the user, but actually corresponds to two Unicode codepoints (one for the opening delimiter, one for the closing delimiter).
Also, matrices, vectors and cases already share the same Delimiter type.

Does that mean cases automatically gets these as well?

Yes, it does!

@Enivex
Copy link
Collaborator

Enivex commented May 21, 2024

While you're at it, you may as well add triple bars as well.

(There are plenty of other delimiters too, but most are very obscure)

@laurmaedje
Copy link
Member

I'm also opening to discussing a design where we can directly use all Unicode opening/closing delimiters. Maybe something where the delimiter is directly passed as math content instead of a string? (We can also support both for a while.)

@MDLC01
Copy link
Collaborator Author

MDLC01 commented May 21, 2024

This PR is quickly becoming a mess, mainly due to me trying to do too many things at once. Maybe we should close it and discuss a design that would allow specifying any pair of delimiters?

@MDLC01 MDLC01 force-pushed the angle-vec-delim branch from 0097cb3 to bad4fe0 Compare May 21, 2024 17:18
@Enivex
Copy link
Collaborator

Enivex commented May 21, 2024

I didn't mean to derail this PR. The other changes could be a future one?

@MDLC01
Copy link
Collaborator Author

MDLC01 commented May 21, 2024

If we opt for a design similar to smartquote's quote parameter, I can implement it as part of this PR, especially because this PR would be pretty much overridden by one that implements the other changes.

@MDLC01 MDLC01 force-pushed the angle-vec-delim branch from bad4fe0 to 7b2bfcd Compare May 21, 2024 17:38
@MDLC01 MDLC01 changed the title Add double brackets and angles as valid matrix delimiters Allow somewhat arbitrary characters as mat, vec and cases delim May 21, 2024
@MDLC01
Copy link
Collaborator Author

MDLC01 commented May 21, 2024

I implemented the ability to use any Unicode "opening", "closing" or "fence" character. See the updated PR description for more information.

Copy link
Member

@laurmaedje laurmaedje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this.

|| is not supported anymore, correct? I think that's fine, but it is a breaking change, so notable.

@MDLC01
Copy link
Collaborator Author

MDLC01 commented May 22, 2024

|| is not supported anymore, correct?

Indeed. Moreover, mat(delim: ||, ..) does not work either, probably due to some parsing limitations. This has to be done with math(delim: bar.double, ..) or math(delim: "‖", ..).

@laurmaedje laurmaedje added this pull request to the merge queue May 22, 2024
@laurmaedje
Copy link
Member

Moreover, mat(delim: ||, ..) does not work either, probably due to some parsing limitations. This has to be done with math(delim: bar.double, ..) or math(delim: "‖", ..).

Not a big deal I think. Thank you!

Merged via the queue into typst:main with commit a6cf584 May 22, 2024
@MDLC01 MDLC01 deleted the angle-vec-delim branch May 22, 2024 19:41
PgBiel added a commit to tulio240/typst that referenced this pull request May 30, 2024
Refactor frame metadata into tags (typst#4212)


Require `Send` and `Sync` for worlds (typst#4219)


Optimize counters and state (typst#4223)


Add `windows` method to array (typst#4136)

Improve `CITATION.cff` file (typst#4201)


Fix equation resizing when adding the equation number (typst#4179)


`layout` documentation improvements (typst#4196)

Allow somewhat arbitrary characters as `mat`, `vec` and `cases` `delim` (typst#4211)


Do layout short-circuit in flow instead of realization (typst#4231)


Split `BitSet` into two types and make it a bit nicer (typst#4249)


Set default value of `raw.theme` to `auto`, and allow setting `raw.theme` to `auto` (typst#4186)


Extended cargo installation instructions (typst#4168)

Hint for language-region pair on `text.lang` (typst#4183)


Improve macro docs (+ Native*Data docs) (typst#4240)


Rephrase the sentence on variable scope in Scripting documentation (typst#4250)


Refactor `Capable::vtable` to return `Option<NonNull<()>>` (typst#4252)


Nicer test helper CSS (typst#4269)


Trim weak spacing at line start/end in paragraph layout (typst#4087)


Add ability to choose between minified and pretty-printed JSON (typst#4161)


Refactor PDF export (typst#4154)

Reorder syntax kinds (typst#4287)


Fix figure centering (typst#4276)

Fix `Default` impls for AST nodes (typst#4288)


Bump libc to v0.2.155 (typst#4268)


Bump time dependency (typst#4294)
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

Successfully merging this pull request may close these issues.

3 participants