-
-
Notifications
You must be signed in to change notification settings - Fork 360
Description
Following up on the discussion over on discourse regarding my proof of concept Typst backend for rendering strings in Makie, I have been digging through the text code, to see how we could provide an official way of extending the text rendering pipeline to more complex strings. Doing so would allow for a cleaner implementation of the currently supported
- Latex strings (currently hard coded in the text rendering pipeline, adds a linesegments plot to the otherwise atomic text plot, which results in a few places where Text has to get special treatment)
- "normal" strings
- Rich text
more stable integrations in the future with
- Typst strings
- TikZ Images currently provided by MakieTeX
and potentially other interesting applications in which "rendering text" does not necessarily mean producing glyphs at certain locations, such as PlantUML or Mermaid diagrams.
As this would be a fairly large piece of work, I want to put out proposal to discuss the approach that I would take, before I start implementing it.
Fundamentally, this proposal follows the suggestion of @asinghvi17, that we add an AbstractStringLayouter type, that users can subtype and then use their subtypes as an attribute in all text! calls to dispatch on custom text rendering behaviour.
To do this, I believe that we need to do the following:
- lift
Textout of the atomic plots, and replace it with a new atomic called something likeGlyphs Glyphsnow takes as arguments everything thatTextproduced up until this point, something like this: outputs of text rendering- The default theme gets a new attribute
string_layouter=SimpleStringLayouter() - as well as
Textgetting something likestring_layouter=@inherit string_layouter Textnow gets its ownplot!(text::Text)method, in which we resolve the appropriate string layouter for each given string, and then dispatch to something like_layout_with_layouter(plot::Text, layouter<:AbstractStringLayouter, current_string), which the user can overwrite toplot!arbitrary things into the text-plot. Rendering LaTeX strings would then for example contain a call toglyphs!, as well as tolinesegments!
Please let me know what you think!