Skip to content
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

Refined math #452

Closed
wants to merge 3 commits into from
Closed

Refined math #452

wants to merge 3 commits into from

Conversation

upupming
Copy link
Contributor

@upupming upupming commented May 19, 2019

#421

@yzhang-gh Thanks for the suggestions, let's discuss the detail here.

Sorry, I don't get the point. What feature would you like to implement?

Exactly the Ctrl+M shortcut to quickly add a math block and move the cursor to the middle of the block.

For example, the current behaviour can be described as:
| -> $|$ -> $$ | $$ -> | -> ... (toggle with ctrl + m)

My previous idea is to add another state

$$
|
$$

between $$ | $$ and |.

Could you elaborate your expected behaviour like this?

Your idea is very good, but I think the user may need the cancel out the previously created math block, i.e. there are two states created & canceled, the user can switch between them. So I keep the function of Ctrl+M for inline blocks only and add another shortcut Ctrl+Shift+M for displayed blocks.

Ctrl+M will create an inline math block and move the cursor to the middle, and the user may write some tex. If the user wants to delete the math block quickly, he just presses Ctrl+M again. The same applies to the Ctrl+Shift+M for displayed math.

Do you like this way? If you would prefer only the Ctrl+M shortcut, I think it's well, too.

For KaTeX rendering, we are currently using markdwon-it-katex. For highlighting, what are we using now? I think we can learn from it and switch correctly between three states:

State 0: nothing
State 1: $|$
State 2: $$|$$
State 3: 
$$
|
$$

We can loop between them, for example: 0->1->2->3->0->...

@upupming upupming changed the title Added: math block shortcuts Refined math May 19, 2019
@upupming
Copy link
Contributor Author

upupming commented May 19, 2019

@yzhang-gh

<> is provided by the official extension. I'm not sure whether we can override it.

See https://github.com/Microsoft/vscode/blob/3a12b7ac2efd2f1f01a646ef5272313ad50bf618/extensions/markdown-basics/language-configuration.json#L28-L34

Sure, we can override them, but only override them in math is difficult, I have no idea to tell vscode to do so. Also, we need to get the context of the current position, i.e. am I in a math block?

@yzhang-gh
Copy link
Owner

Thanks for the efforts.

If the user wants to delete the math block quickly, he just presses Ctrl+M again

I am not very convinced whether anyone would ever want to do it. At least it is not a common operation.

Personally, I would like it to stay with only Ctrl+M and only math creation (loop on 4 states we discussed).

Sure, we can override them, but only override them in math is difficult, I have no idea to tell vscode to do so. Also, we need to get the context of the current position, i.e. am I in a math block?

It seems we cannot dynamically interact with the language configuration (autoClosingPairs). The notIn field might be usable. Our math syntax is defined here

"grammars": [
{
"scopeName": "markdown.math_display",
"path": "./syntaxes/math_display.markdown.tmLanguage.json",
"injectTo": [
"text.html.markdown"
]
},
{
"scopeName": "markdown.math_inline",
"path": "./syntaxes/math_inline.markdown.tmLanguage.json",
"injectTo": [
"text.html.markdown"
]
},
{
"scopeName": "text.katex",
"path": "./syntaxes/katex.tmLanguage.json"
}
]

Probably we can have something like notIn: ["string", "math"].

However, I prefer not to override the built-in language configuration only for the <> thing.
Because then we have more things to maintain 😥.
Looks like overkill to me.

For the {} auto closing, I think we can directly open a PR to vscode. I would argue no one wants a single {.

@upupming
Copy link
Contributor Author

upupming commented May 19, 2019

Personally, I would like it to stay with only Ctrl+M and only math creation (loop on 4 states we discussed).

I agree with you, but one more thing, too many states (currently 4) may be inconvenient for users want to quickly create the last state. How about creating a reverse loop using Ctrl+Shift+M? Just like Ctrl+Z and Ctrl+Y.

Our math syntax is defined here
Probably we can have something like notIn: ["string", "math"].

Thanks for pointing it out, I will look into it.

However, I prefer not to override the built-in language configuration only for the <> thing.
Because then we have more things to maintain 😥.
Looks like overkill to me.

I have seen this repo becomes more and more popular these days (much more popular than the official one), it's really not easy for you to maintain this big project. Thanks for your great works. I will try to find something easier to fixed <> autoClosingPairs problem.

For the {} auto closing, I think we can directly open a PR to vscode. I would argue no one wants a single {.

You are right, I will open a PR there and add { and } to surroundingPairs.

@yzhang-gh
Copy link
Owner

How about creating a reverse loop using Ctrl+Shift+M? Just like Ctrl+Z and Ctrl+Y.

Sounds interesting. After thinking for a while, I suggest changing the order to 1243. What do you think of it?

@upupming
Copy link
Contributor Author

upupming commented May 19, 2019

Let us clarify the states (to avoid misunderstanding):

State 1: not in any others states
State 2: $|$
State 3: $$ | $$
State 4:
$$
|
$$

Sorry, I finally realized you have implemented the first three states in your extension. I thought there is no Ctrl+M shortcut at all at first. Now I know I was wrong!

Your implementation is very good. And only go back to the state 1 when there is no tex content in $$|$$.

Sounds interesting. After thinking for a while, I suggest changing the order to 1243. What do you think of it?

I personally use displayed math a lot, so I prefer to put the state 4 before state 3. But why do you suggest place it before 3, what is your consideration? Finally, I think let the user reorder them is a better idea.

Another thing, what do you think about add Ctrl+Shift+M for the reverse loop? If yes, I will continue my work at your previous work~

@yzhang-gh
Copy link
Owner

It is simply I can go with 1243 😂. I don't think many people are using Ctrl+M. So I guess it won't cause many troubles for other users.

In this way, I assume you would be happy with "2 steps to get display math". If it is, we don't need Ctrl+Shift+M any more.
The reverse idea is interesting. But I just feel not that many people will ever use it.

@upupming
Copy link
Contributor Author

@yzhang-gh Haha, I have implemented it, it is really interesting~

@upupming
Copy link
Contributor Author

One more thing, it seems that autoClosingPairs.notIn can only be comment and string, no others like math.
image

@yzhang-gh
Copy link
Owner

it seems that autoClosingPairs.notIn can only be comment and string, no others like math

as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants