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

Lua - add quarto.format.typst module #9527

Merged
merged 3 commits into from Apr 30, 2024
Merged

Conversation

cscheid
Copy link
Collaborator

@cscheid cscheid commented Apr 29, 2024

Adds _quarto.format.typst module. That's not exposed to user filters but opens the door for us to do so.

(cc @baptiste - note that this isn't usable to you just yet, but we'll do it soon.)

@cscheid
Copy link
Collaborator Author

cscheid commented Apr 29, 2024

This is currently a purely-internal change, so no changelog entry.

@cscheid cscheid force-pushed the feature/typst-function-call-api branch from e9259c0 to 324beb3 Compare April 29, 2024 21:05
@cscheid
Copy link
Collaborator Author

cscheid commented Apr 29, 2024

Now quarto.format is a public API, using public API Lua case conventions. This needs to be documented on quarto-web.

@cscheid
Copy link
Collaborator Author

cscheid commented Apr 29, 2024

Minimal example usage of quarto.format.typst.function_call:

---
format: 
  typst:
    include-before-body: 
      text: >
        #let add(x, y) = x + y
filters:
  - quartoluatypst.lua
---

::: {#find-me}

:::

quartoluatypst.lua

function Div(div)
  if div.identifier == "find-me" then
    return quarto.format.typst.function_call("add", {3, 4})
  end
end

Relevant .typ output

// ...

#let add(x, y) = x + y

#add(
3
, 
4
)

We could do a better job at formatting function_call, but this is good enough to use.

@baptiste
Copy link

That looks great, thanks! Just wondering if the function call can deal with the #function(argument: something)[body] kind of syntax?

@cscheid
Copy link
Collaborator Author

cscheid commented Apr 30, 2024

Yes, it "can". The syntax we'll end up emitting is slightly different, but it should work. Typst does currying of the last argument automatically. AIUI, #function(arg: something)[body]) is equivalent to #function(arg: something, [body]) (which is the syntax we should be emitting).

You'll note that the typing we use is a little convoluted, and that's designed to differentiate between named arguments and positional arguments. As you call the function, you'll need to be mindful of that order. We should have more examples in the docs (when I write them).

@cscheid cscheid merged commit 188ea6d into main Apr 30, 2024
47 checks passed
@cscheid cscheid deleted the feature/typst-function-call-api branch April 30, 2024 16:02
@cscheid cscheid changed the title Lua - add _quarto.format.typst module Lua - add quarto.format.typst module Apr 30, 2024
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.

None yet

2 participants