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

Feature request: { auto closing #421

Closed
upupming opened this issue Apr 16, 2019 · 22 comments
Closed

Feature request: { auto closing #421

upupming opened this issue Apr 16, 2019 · 22 comments
Labels
Issue: Feature Something brand new.

Comments

@upupming
Copy link
Contributor

What is the problem?

It would be nice if the { is a js file was $ in an md file in the screenshot below:

auto-enclose

How can I reproduce it?

Enter $ in an md file.

Is there any error message in the console?

@upupming upupming changed the title Feature request: $$ auto enclose Feature request: $ auto enclose for math block Apr 16, 2019
@yzhang-gh
Copy link
Owner

It might not be a good idea since $ is not a punctuation mark. I suggest using ctrl+m

toggle math

@upupming
Copy link
Contributor Author

Sure! I prefer the hotkey, too. One thing more, we should not insert whitespace when user press ctrl + m twice, otherwise we will get warning from markdownlint once enter a newline.

@yzhang-gh
Copy link
Owner

We can add a third case

$$
|
$$

on third press

@yzhang-gh yzhang-gh added Issue: Feature Something brand new. Help wanted Looking for help. labels Apr 17, 2019
@upupming
Copy link
Contributor Author

If this is difficult, we should auto-close $ because auto complement of KaTeX is only supported in text surrounded by $$.

Also, we should auto-close { and } in math blocks.

auto-close-{

@yzhang-gh
Copy link
Owner

we should auto-close $ because auto complement of KaTeX is only supported in text surrounded by $$.

I don't get the point. The math completion also works inside $...$ 😳


As for the { thing, we can do it.

@upupming
Copy link
Contributor Author

upupming commented Apr 23, 2019 via email

@yzhang-gh
Copy link
Owner

I understand.

For {, it is natural because no one wants a single {.

But for $, it is kind of different. The math is an extension to Markdown and I believe most of the users don't use that.
It will cause a problem when people literally want a $ symbol (as US dollars, or as a special character).

So that is why we have the hotkey ctrl+m. Typing shift+4 and ctrl+m is both two keystrokes, why not using it 😉.

@upupming
Copy link
Contributor Author

upupming commented Apr 23, 2019

Very reasonably.

I remembered that when I used Microsoft Word to edit formulas. There were many symbols that couldn't be typed by the keyboard, so I set up a lot of shortcuts, which I used very familiarly and could be typed very quickly.
Perhaps we should draft or find some standard shortcuts for mathematical symbols and apply it to Markdown All in One. Or, just let the user define the shortcut for a new symbol easily.

@upupming
Copy link
Contributor Author

Another proposal, we can add some shortcut for quick surround current math code block with \begin{aligned} and \end{aligned}, because I always want to change an ordinary math equation into aligned math block.

@upupming
Copy link
Contributor Author

Another thing, < should not be auto-closed.

auto-close-《

@yzhang-gh
Copy link
Owner

Thanks for the suggestion.

I also have some custom snippets (with keybindings). For your case, it can be

{
    "key": "ctrl+whatever",
    "command": "editor.action.insertSnippet",
    "args": {
        "snippet": "\\begin{aligned}\n$TM_SELECTED_TEXT$1\\end{aligned}"
    },
    "when": "editorTextFocus && editorLangId == markdown"
},

However, as a Markdown extension, I guess this might be too special a feature. Let's see whether there are other people also want this.


<> 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

@upupming
Copy link
Contributor Author

Thanks, I will try it.

I have another suggestion, you can see that the auto complement is always the same order and the user may press arrow down several times to get the complementation he/she needs.

image

As far as I can see, Eclipse IDE will change the complete order according to users' previous input, I think this is a good feature to be added.

@upupming
Copy link
Contributor Author

If I am free, I should try to make these possible. But I am also quite busy right now, someday will come a PR!

@yzhang-gh
Copy link
Owner

👍

VSCode seems to be able to auto reorder the completions. It does work for TypeScript. Maybe there are some options for the extension authors. I will have a look in this weekend.

@linsui
Copy link
Contributor

linsui commented Apr 27, 2019

About snippets for math, maybe we can consult LaTeXWorkshop's snippets.

@yzhang-gh
Copy link
Owner

VSCode seems to be able to auto-reorder the completions

Need to set editor.suggestSelection to recentlyUsedByPrefix.

@yzhang-gh yzhang-gh changed the title Feature request: $ auto enclose for math block Feature request: { auto closing Apr 29, 2019
@yzhang-gh yzhang-gh removed the Help wanted Looking for help. label May 11, 2019
@upupming
Copy link
Contributor Author

Let's sort out this one by one, for Ctrl+M shortcut, I wanted to reuse the highlighting logic to detect the current math block and create/cancel the math block. But I am not familiar with it, so I created my own logic to deal with them. I have created two small algorithms to detect them.

@upupming
Copy link
Contributor Author

This is the current style I finished:

Create

math-create-2019-5-19.gif

Cancel

math-cancel-2019-5-19.gif

Note that I added extra space for users, do you like it?

@yzhang-gh
Copy link
Owner

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

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?

@upupming
Copy link
Contributor Author

I finally used ctrl+shift+m to toggle displayed math.

@upupming
Copy link
Contributor Author

Let us discuss it in a PR.

@upupming upupming mentioned this issue May 19, 2019
@upupming
Copy link
Contributor Author

upupming commented May 19, 2019

Keeping the plugin simple is a better idea, let me simply close this issue, for the <> auto closing problem, it is not very inconvenient when typing, but the implementation is too difficult. For math shortcuts, LaTeX-workshop is too complex, too. I will consider using my own key bindings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Feature Something brand new.
Projects
None yet
Development

No branches or pull requests

3 participants