Coder Social home page Coder Social logo

artisticat1 / obsidian-latex-suite Goto Github PK

View Code? Open in Web Editor NEW
1.0K 3.0 39.0 18.76 MB

Make typesetting LaTeX as fast as handwriting through snippets, text expansion, and editor enhancements

License: MIT License

JavaScript 10.09% TypeScript 86.76% CSS 3.15%
latex obsidian obsidian-plugin snippets math obsidian-md text-expansion

obsidian-latex-suite's Introduction

Obsidian Latex Suite

A plugin for Obsidian that aims to make typesetting LaTeX math as fast as handwriting.

Inspired by Gilles Castel's setup using UltiSnips.

demo

The plugin's main feature is snippets, which help you write LaTeX quicker through shortcuts and text expansion! For example, type

  • "sqx" instead of "\sqrt{x}"
  • "a/b" instead of "\frac{a}{b}"
  • "par x y " instead of "\frac{\partial x}{\partial y}"

See Gilles Castel's writeup for more information.

The plugin comes with a set of default snippets, loosely based on Gilles Castel's. You can modify them, remove them, and write your own.

Usage

To get started, type "dm" to enter display math mode. Try typing the following:

  • "xsr" → "x^{2}".

  • "x/y Tab" → "\frac{x}{y}".

  • "sin @t" → "\sin \theta".

Have a look at the cheatsheet for a list of commonly used default snippets.

Once these feel familiar, you can check out the default snippets for more commands. e.g.

  • "par Tab f Tab x Tab" → "\frac{\partial f}{\partial x}".

  • "dint Tab 2pi Tab sin @t Tab @t Tab" → "\int_{0}^{2\pi} \sin \theta \, d\theta".

You can also add your own snippets! See here for more info on writing snippets. You can view snippets written by others and share your own snippets here.

Features

Auto-fraction

Lets you type "1/x" instead of "\frac{1}{x}".

For example, it makes the following expansions:

  • x/\frac{x}{}
  • (a + b(c + d))/\frac{a + b(c + d)}{}

and moves the cursor inside the brackets.

Once done typing the denominator, press Tab to exit the fraction.

auto-fraction

Matrix shortcuts

While inside a matrix, array, align, or cases environment,

  • Pressing Tab will insert the "&" symbol
  • Pressing Enter will insert "\\" and move to a new line
  • Pressing Shift + Enter will move to the end of the next line (can be used to exit the matrix)

matrix shortcuts

Conceal

This feature must be enabled in settings!

Make your equations more readable by hiding LaTeX code, instead rendering it in a pretty format.

For example, "\dot{x}^{2} + \dot{y}^{2}" will be displayed as "ẋ² + ẏ²".

To reveal the LaTeX code, move the cursor over it.

conceal demo conceal demo 2

Tabout

  • Pressing Tab while the cursor is at the end of an equation will move the cursor outside the $ symbols.
  • Otherwise, pressing Tab will advance the cursor to the next closing bracket: ), ], }, >, or |.

Preview inline math

When the cursor is inside inline math, a popup window showing the rendered math will be displayed.

Color & highlight matching brackets

  • Matching brackets are rendered in the same color, to help with readability.
  • When the cursor is adjacent to a bracket, that bracket and its pair will be highlighted.
  • When the cursor is inside brackets, the enclosing brackets will be highlighted.

color and highlight matching brackets demo

Visual snippets

Sometimes you want to annotate math, or cancel or cross out terms. Selecting some math with the cursor and typing

  • "U" will surround it with "\underbrace".
  • "O" will surround it with "\overbrace".
  • "C" will surround it with "\cancel".
  • "K" will surround it with "\cancelto".
  • "B" will surround it with "\underset".

visual snippets

Auto-enlarge brackets

When a snippet containing "\sum", "\int" or "\frac" is triggered, any enclosing brackets will be enlarged with "\left" and "\right".

auto-enlarge brackets

Editor commands

  • Box current equation – surround the equation the cursor is currently in with a box.
  • Select current equation – select the equation the cursor is currently in.

Snippets

Snippets are formatted as follows:

{
  trigger: string | RegExp,
  replacement: string,
  options: string,
  priority?: number,
  description?: string,
  flags?: string,
}
  • trigger : The text that triggers this snippet.
  • replacement : The text to replace the trigger with.
  • options : See below.
  • priority (optional): This snippet's priority. Snippets with higher priority are run first. Can be negative. Defaults to 0.
  • description (optional): A description for this snippet.
  • flags (optional): Flags for regex snippets.

Options

  • t : Text mode. Only run this snippet outside math
  • m : Math mode. Only run this snippet inside math. Shorthand for both M and n
  • M : Block math mode. Only run this snippet inside a $$ ... $$ block
  • n : Inline math mode. Only run this snippet inside a $ ... $ block
  • A : Auto. Expand this snippet as soon as the trigger is typed. If omitted, the Tab key must be pressed to expand the snippet
  • r : Regex. The trigger will be treated as a regular expression
  • v : Visual. Only run this snippet on a selection. The trigger should be a single character
  • w : Word boundary. Only run this snippet when the trigger is preceded (and followed by) a word delimiter, such as ., ,, or -.
  • c : Code mode. Only run this snippet inside a ``` ... ``` block

Insert tabstops for the cursor to jump to by writing "$0", "$1", etc. in the replacement.

For more details on writing snippets, including regex snippets and function snippets, see the documentation here. You can view snippets written by others and share your own snippets here.

Warning

Snippet files are interpreted as JavaScript and can execute arbitrary code. Always be careful with snippets shared from others to avoid running malicious code.

Cheatsheet

Trigger Replacement
mk $ $
dm $$

$$
sr ^{2}
cb ^{3}
rd ^{ }
_ _{ }
sq \sqrt{ }
x/y Tab \frac{x}{y}
// \frac{ }{ }
" \text{ }
text \text{ }
x1 x_{1}
x,. \mathbf{x}
x., \mathbf{x}
xdot \dot{x}
xhat \hat{x}
xbar \bar{x}
xvec \vec{x}
xtilde \tilde{x}
xund \underline{x}
ee e^{ }
invs ^{-1}

When running a snippet that moves the cursor inside brackets {}, press Tab to exit the brackets.

Greek letters

Trigger Replacement Trigger Replacement
@a \alpha eta \eta
@b \beta mu \mu
@g \gamma nu \nu
@G \Gamma xi \xi
@d \delta Xi \Xi
@D \Delta pi \pi
@e \epsilon Pi \Pi
:e \varepsilon rho \rho
@z \zeta tau \tau
@t \theta phi \phi
@T \Theta Phi \Phi
@k \kappa chi \chi
@l \lambda psi \psi
@L \Lambda Psi \Psi
@s \sigma
@S \Sigma
@o \omega
ome \omega

For greek letters with short names (2-3 characters), just type their name, e.g. "pi" → "\pi"

Contributing

Any contributions and PRs are welcome!

Acknowledgements

Support

If you like this plugin and want to say thanks, you can buy me a coffee here!

Buy Me a Coffee at ko-fi.com

obsidian-latex-suite's People

Contributors

adamhl8 avatar anti-apple4life avatar artisticat1 avatar b4rc1 avatar bdm-k avatar benjymack avatar comprehensive-jason avatar duanwilliam avatar git-wil avatar itay-raveh avatar m4rch3n1ng avatar multisamplednight avatar strangegirlmurph avatar yalieny avatar yaozhuwa avatar you-n-g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

obsidian-latex-suite's Issues

Enabling "Tabout" prevents list indentation using tab

When "Tabout" is enabled and you use the tab key (when in a list and not in inline LaTeX), the default behavior in Obsidian is to further indent items in a list. When using this plugin with tabout enabled, pressing tab instead takes you to the start of the next item in the list.

Note that this includes checklists, so when pressing tab at the end of an item in a checklist will go to just after the close brackets of the next item:
- [ ]
____^ here, without a space afterwards, thus breaking the checklist if you were to write there

When reaching the end of a list, the plugin will navigate to the start of the next list in the file. When there is no more LaTeX and no more lines in the file, tabbing still works as expected.

Feature Request: Hotkey to disable latex-suite

If latex-suite is acting up, it'd be good to have a hot key to disable it, so one may type out the problematic part without the snippets enabled, and then turn latex-suite back on.

For example, latex suite won't allow me to type out the following

$$ 4 \left( c_1 \left( \frac{n}{2} \right) - c_2 \right) $$

It will understandably take time for these issues to get ironed out, but until then, I'd nice to have a quick way to turn off latex-suite to type out such equations and then turn it back on.

My workaround for now is to remove the trailing $$ to get out of math mode, type out the equation, and then paste $$ back in.

mA mode not working

I created a new Obsidian vault and installed the latex suite. I found only tA mode works and mA mode is not working.

Mobile support does not seem to work

The support for mobile (android) doesn't seem to work.

Recording

I tried it on both of my android devices but neither of them worked. I checked if other plug-ins caused that, so I made a fresh obsidian installation but it still has no effect.

Additional Details:

  • Live Preview editor is enabled
  • Lastest version is installed
  • Android version: 12

vim mode can sometimes trigger snippet

First, thank you very much for developing this -- this really does make working with LaTeX in Obsidian much nicer.

I wanted to report an issue that I'm having with snippets in vim-mode. Because moving up a line uses k, if you move up a line where the character before is a k, this triggers the snippet.

As an example, suppose I am in command mode and my cursor is on the a below.

math is fun
 ^

If I move up a line with k, this goes to

$$ath is fun

Unfortunately, I'm relatively new to obsidian, so not sure how the plugins work, but this might be as simple as disabling snippets when in command mode when using vim key bindings.

Again, thanks for a very useful plugin.

extend conceal map

Hello! Thank you for this great plugin, I love it!
I like using \geqslant and \leqslant instead of \geq and \leq, but it seems they are missing from the table, I'm getting ≤slant instead of just ≤.
I believe in the future somebody will find some symbol that she wants to be concealed, what is best way to add a new symbol?

Include Norm in Bracket behaviour

the idea would be to add “|” and “{“ “}” as a bracket type, so that the auto-enlarge behaviour applies to norms.

Your plugin is great.

Bug Report: Multiplying symbols in enhanced view

If i write $[\varphi]$ close obsidian and open it again the enhanced view shows [𝜑𝜑𝜑] instead of [𝜑]. Same in the $$ $$ mode. Also same with exponents in some cases so for example (A^n) becomes (after closing and reopening of obsidian) (Aⁿⁿⁿ) instead of (Aⁿ). The latex code itself is not changed, only the enhanced view. Seems to have something to do with the brackets?

extra closing bracket when conceal is enabled

When i have that code $\sum_{k=1}[cursor]$ and i try to add the ^ symbol for the upper limit, an extra bracket is added, and i get : $\sum_{k=1}}^[cursor]$.

I have tried to toggle everything that has anything to do with brackets or the plugin or latex, and i found that the bug is present only when the conceal feature is enabled.

Important Note : I use an azerty french keyboard, and the bug happends only because the french ^ key is a dead key (meaning that pressing ^ waits for another key to make for example â widh ^a). If i switch to a qwerty layout, the bug dissapears. I already noticed some similar problems with the vim bindings that don't detect properly the { (that is done using alt-() on azery, but perfectly on qwerty.

Submission to community plugins

Hi @tth05,

Thanks for writing the Completr plugin! I wrote this plugin that builds on your snippets with placeholders code. Just wondering whether you're OK with me sharing this with others and submitting it to the community plugins list? I've given you acknowledgement in the readme.

Have a great day! :)

[feature request]: Support for function extension snippets

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!

Better Concealing

First of all let me thank you for this awesome plugin. I have a few questions regarding the concealing of the latex code

  1. I noticed that \overline{x} does not render to x̄. In fact, only very few overlined letters (i suspect the ones who have a single unicode letter corresponding to it) render in the concealed mode. It should be theoretically possible to render every possible overlined character as unicode is stackable (so even greek ones and fat ones and so on). Same goes for dotted / double dotted / hat and so on.
  2. is it possible to have \frac{a}{b} simply render to a/b? If the fraction is larger it could render with brackets like {...}/{...}
  3. A little thing: is it possible to have \, and \: and \; just render to [space]? I think it would make the concealed view even easier to read

add an option to ignore case of trigger

would be great if there is an option to ignore case of trigger.

if there is a way to set flag in the trigger on regex mode would be a workaround.

thanks for this great plugin!

Can't load plugin since 0.15.0 (Insiderbuild)

Since the update to the new insiderbuild 0.15.0 or 0.15.1 the plugin can't be loaded anymore for me. I assume it has to do with the update to Codemirror 6, but I don't know.

By the way, I'm loving this plugin. It made writing so much faster and more fluid for me. So thank you very much ☺

[Bug] Plugin just literally doesn't work

None of the plugin's functions work, from the snippets to tabout, nothing. Tried a bunch of stuff already (disabling other plugins, reinstalling, etc.), to no avail. All I've got that might lead to a solution is these errors Obsidian throws up:

app.js:1 TypeError: Cannot read properties of undefined (reading 'main')
    at isWithinMath (eval at <anonymous> (app.js:1:1494667), <anonymous>:1444:36)
    at Object.editorCheckCallback (eval at <anonymous> (app.js:1:1494667), <anonymous>:4806:26)
    at Object.e.mobileOnly.xb.isMobile.e.checkCallback (app.js:1:1618478)
    at app.js:1:1619065
    at Array.filter (<anonymous>)
    at e.listCommands (app.js:1:1619003)
    at e.getCommands (app.js:1:1662005)
    at t.getItems (app.js:1:1663065)
    at t.getSuggestions (app.js:1:1469819)
    at t.updateSuggestions (app.js:1:1469049)
(anonymous) @ app.js:1
app.js:1 Command failed to execute:  obsidian-latex-suite:latex-suite-select-equation
app.js:1 TypeError: Cannot read properties of undefined (reading 'main')
    at isWithinMath (eval at <anonymous> (app.js:1:1494667), <anonymous>:1444:36)
    at Object.editorCheckCallback (eval at <anonymous> (app.js:1:1494667), <anonymous>:4830:26)
    at Object.e.mobileOnly.xb.isMobile.e.checkCallback (app.js:1:1618478)
    at app.js:1:1619065
    at Array.filter (<anonymous>)
    at e.listCommands (app.js:1:1619003)
    at e.getCommands (app.js:1:1662005)
    at t.getItems (app.js:1:1663065)
    at t.getSuggestions (app.js:1:1469819)
    at t.updateSuggestions (app.js:1:1469049)
(anonymous) @ app.js:1
app.js:1 Command failed to execute:  obsidian-latex-suite:latex-suite-box-equation
app.js:1 TypeError: Cannot read properties of undefined (reading 'main')
    at isWithinMath (eval at <anonymous> (app.js:1:1494667), <anonymous>:1444:36)
    at Object.editorCheckCallback (eval at <anonymous> (app.js:1:1494667), <anonymous>:4806:26)
    at Object.e.mobileOnly.xb.isMobile.e.checkCallback (app.js:1:1618478)
    at app.js:1:1619065
    at Array.filter (<anonymous>)
    at e.listCommands (app.js:1:1619003)
    at e.getCommands (app.js:1:1662005)
    at t.getItems (app.js:1:1663065)
    at t.getSuggestions (app.js:1:1469819)
    at t.updateSuggestions (app.js:1:1469049)
(anonymous) @ app.js:1
app.js:1 Command failed to execute:  obsidian-latex-suite:latex-suite-select-equation
app.js:1 TypeError: Cannot read properties of undefined (reading 'main')
    at isWithinMath (eval at <anonymous> (app.js:1:1494667), <anonymous>:1444:36)
    at Object.editorCheckCallback (eval at <anonymous> (app.js:1:1494667), <anonymous>:4830:26)
    at Object.e.mobileOnly.xb.isMobile.e.checkCallback (app.js:1:1618478)
    at app.js:1:1619065
    at Array.filter (<anonymous>)
    at e.listCommands (app.js:1:1619003)
    at e.getCommands (app.js:1:1662005)
    at t.getItems (app.js:1:1663065)
    at t.getSuggestions (app.js:1:1469819)
    at t.updateSuggestions (app.js:1:1469049)
(anonymous) @ app.js:1

EDIT: I'm using trying to use the default snippets.

How to add snippet for norm \|

Thanks for this amazing plugin!

I want add snippets for literal \| to \\| $0 \\| and literal @\| to \\left\\| $0 \\right\\|. However, I'm confused by the escaping rule. For literal \|, I tried \|, \\|, \\\| ... and seems none of these works.

I also tried regex, however, it didn't work either and wipe out the whole note.

Feature Request: Faster Fraction typing

Right now a+b/c gets translated to a+\frac{b}{c}. If one wants to write \frac{a+b}{c} one has to write {a+b}/c. To be faster,
would it be possible to have a+b/c be translated to \frac{a+b}{c} but a+[space]b/c be translated to a+\frac{b}{c}? That way, the bracket typing could be avoided.

tab/enter behaviour within align environment

The “tab” behaviour is conflicted within “align”: to insert a & or to get out of an bracket environment.
My preferred default would be to exit an environment whenever within brackets, since I rarely want to insert a “&” when within a bracket environment.

Thank you,

Matthew

Can we have a separate file to save our settings?

In vscode or vim, we have latex.snip to save all our settings. Right now, all the settings are within the plug-in setting. I am wondering if we could have a separate file. Then, we can use vscode or sublime to edit it. This will be much more efficient.

Mobile compatibility

Is there a reason why isDesktopOnly is set to true?
I looked at the imports and didn't see a reason why it shouldn't work on mobile.

Bracket close as alternative to tab

When within an environment, make typing the correct closing bracket behave like tab. That is, in the case “(blabla[cursor])” then typing “)” moves the cursor out, the same as typing [TAB].

To be clear, I like the tabout behaviour, but sometimes I forget it and make a mistake, and then I have to erase the extra closing bracket. This would also match the behaviour of code editors.

I think this would be a good feature. Let me know!

Replacements with "$\d" or "[[\d"

I've been trying to implement a text-mode regex snippet to convert any number to math mode after writing: e.g 3 -> $ 3 $. I quickly discovered that basically any snippet which inserts a $ followed by a digit is bound to spaz out and crash the plugin.

I think this is due to the detection of the tabstop syntax. May I suggest adding an option to escape the $ character's tabstop functionality in the replacement syntax, seeing as it's a crucial symbol for working with LaTeX?

My current workaround is 3 -> $ \hspace{0pt}3 $ which works but it's messy.

A similar issue occurs with double brackets as far as I can tell. I use snippets to auto-prettify my Obsidian links and I'd run into problems if I was using numerical note titles or headers.

(P.S. Didn't want to add an issue for this, but I'm in love with this plugin (thank you), and I'm wondering if you considered a page/google sheet where members of the community can share our custom snippets!)

Edit: Funny that I needed to escape out of the $ symbols on GitHub to convey my issue correctly, and found out they don't have that feature either.

Plugin Usage (Questions about how to get started)

I apologize in advance if I'm not going about this correctly, but I'm having trouble even just implementing the instructions in the README file. I have installed the plugin in my Obsidian Vault. I 'm not sure how to actually start using it. Is there a mode or something I'm missing? I honestly am not even sure what question to ask.

I typed 'dm' per instructions but nothing happens. I've tried various things such as, typing the pair of '$' signs and double '$' signs, following along with the GIF provided and I am not seeing any results that resemble what is in the README.

I'm sure I'm just missing something basic but I'm not sure what else to try and I need to be able to type up math notes quickly as possible. Thank you!

`tab` key indents while in math mode

Hi,

Thank you for the great plugin!
On my computer, in math mode, the tab space still indents the line, instead of just going to the next cursor $i:

tab

Here is my debug info, on the sandbox vault, where the issue still happens:

SYSTEM INFO:
	Obsidian version: v0.14.15
	Installer version: v0.12.19
	Operating system: Windows 10 Home 10.0.19043
	Login status: not logged in
	Insider build toggle: off
	Live preview: on
	Legacy editor: off
	Base theme: dark
	Community theme: none
	Snippets enabled: 0
	Safe mode: off
	Plugins installed: 1
	Plugins enabled: 1
		1: Latex Suite

RECOMMENDATIONS:
	Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the help vault or disable community plugins.

Thank you

Big thanks for building this and the learning curve is hard but worth it.

[Bug]: When I copy part of the latex formula, the ob program crashes and gets stuck.

Reproduce:

  1. Find a latex formula.
  2. Mouse to select the part of the formula.
  3. Press Ctrl + c
  4. Get stuck
WindilyCloud.-.Obsidian.v0.14.5.2022-04-14.10-43-27.mp4

Other information:

  1. When I turned off the wonderful plugin, everything was fine
  2. win11 ,obisidan v0.14.5,latest plugin version

This is the best latex plugin I've ever used, I can't say enough.

Thank you for any reply!

Feature Request: Math editor syntax highlighting themes

I've seen that the demo gifs from the README had a different color syntax highlighting compared to the original one from Obsidian. I am not sure if this can be integrated into the plugin, or if there is already some other plugin for this.

FR: Paired symbol matching

I love your plugin, use it everyday.
So I have some suggestions about paired symbol like (),{},[]
such as the picture, Can you make it appear in the obsidian notes?
image

VISUAL with vim shortcuts

I like the VISUAL idea for editing previously written latex. However it is easier to select text while in vim mode. Would there be a way to use the selection performed in vim mode?

I am not sure of what exactly this would look like.

Best,

Matthew

In inline math, remove the space at the end of snippets

In inline math, when a space is inserted before the closing dollar sign, the code is no longer read as a math equation. This causes snippets to stop working.

Solution: when a snippet is triggered in inline math, remove any spaces at the end of the replacement.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.