question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature request]: Support for function extension snippets

See original GitHub issue

This plugin works well enough and very elegantly allows me to edit latex formulas.

If it could support function fragments, it would be perfect! My thoughts are as follows.

mxi(3) outputs a 3x3 unit matrix and mxi(6) outputs a 6x6 unit matrix.I can also customize h(3) to output three-level headings.

Also, it would be easier to debug and backup if the configuration file could be separated into an md file.

Thanks for any replies, I really love this plugin!

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
artisticat1commented, May 14, 2022

Anyway, I’m convinced you can handle this gracefully because you made this plugin to make me feel graceful, haha😆!If I can be of any help, just ask, I’m happy to do so. For example, manually testing the functionality and stability of new features.

Haha, thank you! I’d be happy to have help with testing. I’ll let you know when I have things ready.

So, I’ve come up with an idea for how to achieve this. To achieve your example with “a33pmx” above, here’s what it would look like.

We can use the regular expression

([A-Za-z])([0-9])([0-9])pmx

to match the string “a33pmx”. This regex captures the groups “a”, “3”, and “3”. I assume these are the symbol of the matrix, the number of rows, and the number of columns.

Then we can write a function in javascript that takes the inputs “a”, “3”, and “3” as parameters and generates the corresponding matrix output in LaTeX. The plugin will pass in the capture groups to the function as an array.

function genMatrix(captureGroups) {
  const [symbol, rows, columns] = captureGroups;

  let arr = [];
  for(let j = 0; j < rows; j++) {
      arr[j] = [];

      for(let i = 0; i < columns; i++) {
          arr[j][i] = `${symbol}_{${j+1}${i+1}}`;
      }
  }

  let output = arr.map(el => el.join(" & ")).join(" \\\\\n");
  output = `\\begin{pmatrix}\n${output}\n\\end{pmatrix}`;

  return output;
}

image

Finally, we put all this together in a snippet that we can run by typing “a33pmx<kbd>Tab</kbd>”.

{trigger: "([A-Za-z])([0-9])([0-9])pmx", replacement: `

function genMatrix(captureGroups) {
  const [symbol, rows, columns] = captureGroups;

  let arr = [];
  for(let j = 0; j < rows; j++) {
      arr[j] = [];

      for(let i = 0; i < columns; i++) {
          arr[j][i] = \`\${symbol}_{\${j+1}\${i+1}}\`;
      }
  }

  let output = arr.map(el => el.join(" & ")).join(" \\\\\n");
  output = \`\\begin{pmatrix}\n\${output}\n\\end{pmatrix}\`;

  return output;
}

`, options: "rmx"}

Similarly, we can create a snippet for unit matrices, as you suggested in your first post.

image

{trigger: "mxi([0-9])", replacement: `

function genMatrix(captureGroups) {
  const [N] = captureGroups;

  let arr = [];
  for(let j = 0; j < N; j++) {
      arr[j] = [];

      for(let i = 0; i < N; i++) {
          arr[j][i] = (i === j) ? 1 : 0;
      }
  }

  let output = arr.map(el => el.join(" & ")).join(" \\\\\n");
  output = \`\\begin{pmatrix}\n\${output}\n\\end{pmatrix}\`;

  return output;
}

`, options: "rmx"}

Here typing “mxi6<kbd>Tab</kbd>” will create a 6x6 unit matrix.

How does this sound?

0reactions
artisticat1commented, Dec 6, 2022

It’s in the backlog at the moment, but any PRs to implement this would be welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Project-level extensions and snippets · Issue #8102 · ...
We have a custom set of snippets written per-project and would like to include them in the project repo, like our launch.json, tasks.json....
Read more >
Snippets in Visual Studio Code
Snippets in Visual Studio Code. Code snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements....
Read more >
Snippets - GitLab Docs
With GitLab snippets, you can store and share bits of code and text with other users. You can comment on, clone, and use...
Read more >
Sending a code snippet in Zoom Team Chat
The code snippet feature allows you to copy and paste code using Zoom Team Chat and apply code formatting and syntax highlighting that......
Read more >
Code Snippets – WordPress plugin
Code Snippets is an easy, clean and simple way to run code snippets on your site. It removes the need to add custom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found