-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allows for matrix commands in inline math #310
base: main
Are you sure you want to change the base?
Conversation
Thank you for the PR! |
// Modify matrix expansion for inline math | ||
const regex = new RegExp("\\n\\$0\\n", "g"); | ||
replacement = replacement.replace(regex, " $0 "); | ||
|
||
// Trim whitespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed with the current default snippets (
obsidian-latex-suite/src/default_snippets.js
Lines 239 to 244 in 4021ed5
{trigger: "pmat", replacement: "\\begin{pmatrix}$0\\end{pmatrix}", options: "nA"}, | |
{trigger: "bmat", replacement: "\\begin{bmatrix}$0\\end{bmatrix}", options: "nA"}, | |
{trigger: "Bmat", replacement: "\\begin{Bmatrix}$0\\end{Bmatrix}", options: "nA"}, | |
{trigger: "vmat", replacement: "\\begin{vmatrix}$0\\end{vmatrix}", options: "nA"}, | |
{trigger: "Vmat", replacement: "\\begin{Vmatrix}$0\\end{Vmatrix}", options: "nA"}, | |
{trigger: "matrix", replacement: "\\begin{matrix}$0\\end{matrix}", options: "nA"}, |
We can add the ability to remove newlines when expanding snippets inside inline math, but it should probably be separate from the trimWhitespace
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, my environment was the issue. I'll remove this segment.
@@ -20,7 +20,7 @@ export const runMatrixShortcuts = (view: EditorView, ctx: Context, key: string, | |||
if (!isInsideAnEnv) return false; | |||
|
|||
|
|||
if (key === "Tab") { | |||
if (key === "Tab" && !shiftKey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has no effect ("Tab" advances to the next tabstop, not "Shift+Tab") because snippet expansion/tabout is handled before matrix shortcuts in handleKeydown
.
I'd prefer to keep the original behaviour anyway ("Tab" to move to the next tabstop), unless you have an argument against it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly I think changing settings.matrixShortcutsEnabled && ctx.mode.blockMath
to strictlyInMath made it register the shortcut, but when I revise the code I'll confirm.
Re the second part: I think it makes more sense to have the inline commands identical to the block math commands, where Tab inserts an ampersand, since it'd also be the least cumbersome to type.
Right now in a block math matrix, Shift-Enter advances to the next tab stop (unless the closing $$ aren't on their own line), so we could also make Shift-Enter behave the same way inline as it does in block math. Let me know what makes the most sense here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it makes sense to align the behaviour in inline math with that of block math.
Right now in a block math matrix, Shift-Enter advances to the next tab stop (unless the closing $$ aren't on their own line), so we could also make Shift-Enter behave the same way inline as it does in block math.
(I thought Shift-Enter moved the cursor to the end of the next line?)
So, in summary, we could do something like this. Let me know what you think.
Block math | Inline math | |
---|---|---|
Tab | Insert & |
Insert & |
Enter | Insert \\\\\n |
Insert \\\\ |
Shift-Enter | Move cursor to end of next line | Move cursor to end of matrix (?) |
Resolves #262.
Removes the newlines from the matrix snippet expansion while in inline mode, and allows the tab/enter keys insert & or \ to even if you're inline. Under the new behavior, shift-tab will bring the cursor to the next tabstop, and shift-enter will move the cursor to the next line.
Demo:
https://github.com/artisticat1/obsidian-latex-suite/assets/64773493/130d8ad9-e9ff-4104-a589-a6af14ee8f2a