Welcome to our community

Be a part of something great, join today!

[SOLVED] Keyboard Shortcuts In The Editor

Prakhar

MHB Ambassador
MHB Ambassador
Mar 18, 2015
184
It would be better if this website supports more shortcuts like the command \frac{}{} should come with the press of a button inside the MATH environment along with more such latex commands. Also, some who puts an opening bracket will also close the bracket at some time. If he/she does not close, \(\displaystyle \LaTeX\) will not be rendered properly. So, if someone opens a bracket, the closing bracket should come automatically and the Tab key should switch to the typing area outside the bracket.



If someone types \begin{array }, the \end{array} command should come automatically. Similarly, \end{matrix} should automatically come after typing \begin{matrix}. It would be even better if these two commands come by the press of a button.
 

MarkFL

Administrator
Staff member
Feb 24, 2012
13,775
Hello Prakhar! :D

If you look to the right of the post message editor, you will see our Quick $\LaTeX$ tool. From this tool you can choose from a wide variety of commonly used symbols and commands. We have these symbols/commands grouped by categories which you can choose from the drop-down menu at the top, and then clicking on the icons will insert the appropriate code into the active text area, for example whether you are composing a post, using the $\LaTeX$ Live Preview.

Having closing brackets/commands be automatically generated would be computationally intensive as each keystroke or change to the affected elements would require a parsing of that element's contents. This may be something we consider for a future upgrade of the $\LaTeX$ Live Preview because it is already parsed for each change to the input element. When using the Quick $\LaTeX$ and $\LaTeX$ Live Preview to generate the various codes, the closing codes are automatically generated.

For example, if you click the "Begin/End" button on the $\LaTeX$ Live Preview, you will be guided though the process of creating matrices, piecewise functions, synthetic/polynomial division, and the begin/end statements are automatically generated for you. :D
 

Evgeny.Makarov

Well-known member
MHB Math Scholar
Jan 30, 2012
2,492
Speaking about keyboard shortcuts, I would really like a shortcut for the [m] tag similar to shortcuts for [b], [i] and [u]. There should probably also be a button on the toolbar for it, but for me personally having shortcut is more important.

I also suggest making the height of the gray region smaller. Compare StackExchange on the left and MHB on the right.

monospace1.png monospace2.png
 

Jameson

Administrator
Staff member
Jan 26, 2012
4,043
It would be better if this website supports more shortcuts like the command \frac{}{} should come with the press of a button inside the MATH environment along with more such latex commands. Also, some who puts an opening bracket will also close the bracket at some time. If he/she does not close, \(\displaystyle \LaTeX\) will not be rendered properly. So, if someone opens a bracket, the closing bracket should come automatically and the Tab key should switch to the typing area outside the bracket.

If someone types \begin{array }, the \end{array} command should come automatically. Similarly, \end{matrix} should automatically come after typing \begin{matrix}. It would be even better if these two commands come by the press of a button.
As Mark said, we already have in place a pretty extensive LaTeX menu that you won't find on many other sites. I really like it and think it works well. We also have a live preview LaTeX renderer so you can test out your code without having to refresh the page. I agree with Mark that the auto close tags would be hard to implement. It's a great idea of course and it's something that happens on overleaf.com for example, which I really like. Luckily the Quick LaTeX menu will close tags if they are opened in the aligned environment.

Speaking about keyboard shortcuts, I would really like a shortcut for the [m] tag similar to shortcuts for [b], [i] and [u]. There should probably also be a button on the toolbar for it, but for me personally having shortcut is more important.

I also suggest making the height of the gray region smaller. Compare StackExchange on the left and MHB on the right.
We can add a button to the toolbar. By a keyboard shortcut, you mean something like Ctr+B (for bold)? That kind of shorcut?
 

Evgeny.Makarov

Well-known member
MHB Math Scholar
Jan 30, 2012
2,492

MarkFL

Administrator
Staff member
Feb 24, 2012
13,775
As we speak, I am working on adding the Ctrl+M functionality. I have already reduced the height of the gray background, and once I have both done will make the changes to the live site. :D
 

MarkFL

Administrator
Staff member
Feb 24, 2012
13,775
I have decreased the height of the shaded area:

This is an [m]identifier[/m].

I have also added an event listener to the basic and standard editors so that pressing Ctrl-M or Ctrl-m will generate the tags as requested. The WYSIWYG editor seems to have an event handler that will not permit this (perhaps we can add a button on the toolbar if the WYSIWYG editor users desire). You must have either the basic or standard editors defined as your editor in your settings so that the needed element to which the event is attached is in place at the time the page loads.

You will also have to clear your browser cache so that the new version of our editor script file is loaded.
 

Evgeny.Makarov

Well-known member
MHB Math Scholar
Jan 30, 2012
2,492
Thanks, Mark! Ctrl+M seems to work in the standard editor.

For the gray background, I would still prefer the gap between the top of the box and the top of letters to be smaller. Perhaps the box could be moved down a little so that it is more vertically centered around the highlighted word. But this is not essential. Perhaps we can look at how highlighting is done in other websites and programs, such as text editors.
 

MarkFL

Administrator
Staff member
Feb 24, 2012
13,775
Glad to hear it works for you, Evgeny! I am going to continue to work to find a way for this to work in the WYSIWYG editor. :D

I lightened the gray color a bit and changed the line height attribute instead of manipulating the padding:

Tall letters:

[m]lth[/m]

Short letters:

[m]xxx[/m]

Low-hanging letters:

[m]qyg[/m]
 

MarkFL

Administrator
Staff member
Feb 24, 2012
13,775
It turns out I simply did not know how to add an event listener to an element within an inline document (iframe). I know now, and the Ctrl+M keyboard shortcut works with all of our editors. (Yes)

What's nice about this mod is it will be a breeze to add other keyboard shortcuts in the future.

Clear your cache again to get the most current editor script.
 

MarkFL

Administrator
Staff member
Feb 24, 2012
13,775
There aren't a lot of Ctrl+Letter key combinations that aren't already being used by our browsers and operating sytems, but one BBCode for which I wanted a keyboard shortcut is the noparse tags. Ctrl+N and Ctrl+P are already taken, so I assigned Ctrl+Q (for "quit") to generate these tags. :D

edit: Now the keyboard shortcuts work even if you switch back and forth between the editor modes. :D