[Tex/LaTex] help on create a macro for text color


I used Winedt before and when I need to apply color to certain text, I only need to highlight the text and click the color button and then choose the color I want.

Can I make a macro in TeXstudio, say for blue color, and then create a shortcut button so that I can simply highlight the text and click the button to change the text to blue?

Best Answer

You can do something like this in TeXstudio with user macros:

Go to Macros --> Edit macros. Create a new macro by clicking the plus sign in the lower left. Give it a useful name, and in the LaTeX content field write \textcolor{blue}{%|}, so it looks like this:

enter image description here

If you add this as macro number one, it will have the shortcut Shift + F1. You can select text, or hit the shortcut without any selection.

If you want to be able to choose both colour and text, you can use \textcolor{%<color%>}{%<text%>} as the LaTeX content. When hitting the shortcut you can use Ctrl + /Ctrl + to move between the placeholders for color and text. Note that if you select text and use this shortcut, the text will be placed in the colour slot, I don't know how to fix that, if it's possible.

If you want a button on the toolbar, go to Options --> Configure TeXstudio --> Toolbars (you need to have selected *Show advanced options in the lower left for it to be visible). Choose the Custom toolbar, scroll down to the end of the list on the right to find your new macro, doubleclick to move it to the left side.

To make the toolbar visible, right click in the existing toolbars and check Custom.

Related Question