Skip to content

Custom Preamble #77

Closed
Closed

Description

@fabh2o

Great plugin, thanks!
I was using LaTeXiT up until now, which is a macOS application that allows to create .svg files from LaTeX code and that embed the formula used to generate them in the svg so that if they are opened again in LaTeXiT its possible to continue the editing (i have a short example here).
I miss a feature from LaTeXiT that would make pptypst a perfect replacement, and its the possibility to specify a custom preamble which gets executed before the code entered in the input form. In this way, its possible to import packages that are used often without the need to (re)write the imports for every element added.

Here is what a preamble might look like for me:

#import "@preview/unify:0.7.1": *
#import "@preview/physica:0.9.8": *
#import "@preview/chemformula:0.1.2": ch
#add-unit("decibel_milliwatt", "dBm", "upright(\"dBm\")")
#add-unit("rpm", "rpm", "upright(\"rpm\")")
#let _qty = qty
#let qty(value, unit, per: "fraction-short", ..args) = _qty(value, unit, per: per, ..args)
#let ebl_dose(value) = qty(str(value), "micro coulomb per centi meter squared")

In this way, could directly enter

Dose #math.gt.eq #ebl_dose(800) when using PMMA #ch("(C5O2H8)_n")

and render as

Image

without having to import the packages, define the function etc. every time.

Activity

  1. Splines commented on Apr 17, 2026

    @Splines
    Owner

    Thanks, that sounds like a cool feature to have indeed. I'm wondering about the UI/UX. One could have a separate button that opens a popup where you can enter this praemble.

    But one problem is editing the Typst code after you have inserted it. Because, we definitely need to store this preamble in the shape itself such that you can still re-create it, e.g. when you want to fix a mistake.

    So I think this means we have to store the Typst code as two separate information in the shape: the usual Typst code and the preamble. In the UI, we could maybe have a collapsible text box showing the preamble, above the regular text box. Such that you can still modify the preamble of an already inserted item.

    If you have some better ideas, let me know.

  2. Splines commented on Apr 17, 2026

    @Splines
    Owner

    I think the typical workflow would be to write your preamble once and then use it for many new Typst shapes. That's why maybe the following would work?

    • When the UI currently shows "Insert", you can edit the global preamble (in a collapsible text box above the text box we have right now)
    • When the UI currently shows "Update" (indicating that you are editing a Typst shape), you get to see (in the same collapsible text box) the preamble of that shape (which might differ from the global preamble).

    This also implies you can only edit the global preamble when you are in "Insert" mode, i.e. not while editing an existing shape.

    Does that make sense?

  3. fabh2o commented on Apr 20, 2026

    @fabh2o
    Author

    Yes, i think that doing it this way is clear and straightforward.

    This also implies you can only edit the global preamble when you are in "Insert" mode, i.e. not while editing an existing shape.

    That's perfect, so that there is no confusion. Each shape has his own preamble and the only way to change it is updating the shape. When in "Insert" mode, we are changing the default/global preamble.

    Another cool feature, but less important, would be to have the possibility to load (for every newly inserted shape) the global preamble from a file, with the advantage that the preamble file can be tracked with version control systems such as git.

  4. Splines commented on Apr 20, 2026

    @Splines
    Owner

    I've opened #79 for this. Feel free to play around with it locally and to report any bugs you face and to even give a PR review if you'd like to. You can find the developer guide here. Otherwise, I will probably merge it this Wednesday evening.

  5. fabh2o commented on Apr 21, 2026

    @fabh2o
    Author

    Wow, that was fast!

    I've tested it (on macOS) following your dev guide and everything seems to work as intended. Maybe the only thing missing is an update to the README? Installation on macOS is super simple, i only needed to copy the manifest.xml file to the folder ~/Library/Containers/com.microsoft.Powerpoint/Data/Documents/wef.

    I had some problems running the add-in at first and they seemed to be related to blocking network traffic (eg with Little Snitch) of the powerpoint app. I've disabled the blocking and the add-in works as intended. I don't have time right now to create a pr to add these informations to INSTALL.md but i can do it later this week or next week if needed.

    I will leave the issue open if you want to also implement the loading of the preamble from a file, feel free to close if its not a priority for now.

    Great work, thanks!

  6. added a commit that references this issue on Jun 3, 2026
    217ad06
  7. Splines commented on Jun 3, 2026

    @Splines
    Owner

    I will leave the issue open if you want to also implement the loading of the preamble from a file, feel free to close if its not a priority for now.

    Yeah sorry, this is not in the scope right now, but I hope you can still profit from the new feature, that I finally also released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions