Skip to content

Unable to write snippet which decorates insert node. #987

@CrashAndSideburns

Description

@CrashAndSideburns

I've been trying to write a bunch of TeX snippets, based on the work of Gilles Castel and Elijan Mastnak. I wanted to implement a snippet for integrals which functions slightly differently from the ones described by Gilles and Elijan. Instead of having a variety of different snippets for integrals (one for definite integrals with lower and upper bounds, one for integrals over measure spaces, which only use a lower bound, and one for indefinite integrals with no bounds), I was hoping to write a single snippet with semantics which work something like this:

  • Upon initial expansion, the snippet expands to \int_{%}\,\text{d}x, where % denotes the position of the cursor.
  • When jumping to the next position in the snippet, we obtain \int_{foo}^{%}\,\text{d}x, if some text foo was entered, or \int^{%}\,\text{d}x if no text was entered.
  • Similarly for the upper bound.

I've tried to implement something like this functionality with the following snippet:

s(
    { trig = "in", snippetType = "autosnippet" },
    fmta("\\int<><><><><><><>\\text{d}", {
        f(function(args, _)
            if args[1][1] == "" then
                return ""
            else
                return "_{"
            end
        end, { 1 }),
        i(1),
        f(function(args, _)
            if args[1][1] == "" then
                return ""
            else
                return "}"
            end
        end, { 1 }),
        f(function(args, _)
            if args[1][1] == "" then
                return ""
            else
                return "^{"
            end
        end, { 2 }),
        i(2),
        f(function(args, _)
            if args[1][1] == "" then
                return ""
            else
                return "}"
            end
        end, { 2 }),
        i(3),
    })
)

but this is obviously very overwrought, and since function nodes only seem to update when the insert nodes which they reference are updated, there's no way for me to selectively show the _{} and ^{} based on whether or not I'm currently editing the node that they would contain. I'm not sure if the way that I'm trying to do this is entirely incorrect, and I'm somehow overlooking some other node that would provide functionality like this, but I've found myself stuck. It also seems possible that this issue could be fixed using some node which functions like a combination of an insert node and a function node, allowing the user to write some function to "decorate", in some sense, the text input to an insert node.

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