Skip to content

Make auto subscript 2 more general #9

@kiryph

Description

@kiryph

The suggested snippet by G. Castel

  s({
    trig = "([%a])_(%d%d)",
    name = "auto subscript 2",
  }, {
    f(function(_, snip)
      return string.format("%s_{%s}", snip.captures[1], snip.captures[2])
    end, {}),
    i(0),
  }),

does not work when using letters in indices such as a_ij and is constrained that only a single leading letter is allowed, e.g. when using greek letters \alpha_12, the snippet is also not triggered.

My snippet definition looks like

        s({
          trig = "_(%w%w)",
          name = "auto subscript 3",
          regTrig=true,
          wordTrig=false,
          snippetType="autosnippet",
        }, {
          f(function(_, snip)
            return string.format("_{%s", snip.captures[1])
          end, {}),
          i(1),
          t("}"),
          i(0),
        }, {condition = is_math}),

It is not yet battle tested. If there is a good reason why this is a bad idea, I am happy to hear it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions