obsidian-latex-suite icon indicating copy to clipboard operation
obsidian-latex-suite copied to clipboard

[DOCS] how to format a file containing file snippets

Open userrand opened this issue 2 years ago • 7 comments

Description

It is unclear to me how one should format a file containing snippets. What file extension should the file have?

Should there be more than just the snippets in the file ? For example javascript commands or a json structure ?

Another user mentioned their confusion regarding this here: https://github.com/artisticat1/obsidian-latex-suite/discussions/148

Importance

Importance level: 4/10 (I can manage without it)

userrand avatar Jul 27 '23 21:07 userrand

I also had the same question. After searing for the keyword "file", I found the following remark that answered my doubt: https://github.com/artisticat1/obsidian-latex-suite/pull/75#issuecomment-1297370748

In short, one can following the following steps to achieve this:

  • Copy and paste everything in the settings
  • Put them in .js files and add own snippets
  • Add the path to the folder where the .js files are stored to the settings

wenlzhang avatar Aug 01 '23 13:08 wenlzhang

I also had the same question. After searing for the keyword "file", I found the following remark that answered my doubt: #75 (comment)

In short, one can following the following steps to achieve this:

  • Copy and paste everything in the settings
  • Put them in .js files and add own snippets
  • Add the path to the folder where the .js files are stored to the settings

Hello thanks, I tried following this but then none of the snippets worked and I got linting issues when i saved the file as a js file. Did you add anything else to the file ?

userrand avatar Aug 03 '23 00:08 userrand

What kind of linting issues do you have? I did not add anything special, except for defining some snippets for my use case.

My .js file looks something like the following:

image

wenlzhang avatar Aug 03 '23 07:08 wenlzhang

@wenlzhang

Using the solarlint vscode extension (which I am not very familiar with) i am getting the error below whereas the snippets work if i copy paste them to the settings text area

image

userrand avatar Aug 03 '23 08:08 userrand

Using the solarlint vscode extension (which I am not very familiar with) i am getting the error below

I also saw such errors when installing the extension. However, I did not do anything about them, and the plugin works in Obsidian.

wenlzhang avatar Aug 03 '23 08:08 wenlzhang

Hi, this is just because sonarlint sees a single javascript file and thinks you are running a standalone script. In a standalone script, defining an array like this makes no sense, you would instead do something like

const array = [
    ...
]

However, in this scenario, the plugin is using this file, sonarlint just can't see that. Basically you can ignore the sonarlint errors in this file. (Try //NOSONAR) on the line with the error if you aesthetically want to make it disappear - this shouldn't interfere with the plugin.

mayurankv avatar Aug 03 '23 10:08 mayurankv

@wenlzhang @mayurankv

Thank you both for your help regarding the error. I was unable to get the snippets to run from a file but i can manage with the snippets in the settings.

userrand avatar Aug 03 '23 12:08 userrand

Latex suite imports the default export so an example for an file would be

export default [
{trigger: "mk", replacement: "$$0$", options: "mA"},
// insert your other snippets here
];

You could also do


const greek_snippets = [
// greek snippets here
];
const symbol_snippets = [
// symbol snippets here
];
export default [...greek_snippets, ...symbol_snippets];

A few examples in the docs probably wouldn't hurt.

superle3 avatar Oct 12 '25 14:10 superle3