0

Let's say that I want to highlight some words or some entire sentences in a .tex file. And assume I am using TexStudio as editor.

Is there the possibility of highlighting the whole word/sentence with the mouse and (maybe with a shortcut or a key combination) embed everything in \textbf{sentence to be highlighted} ?

Leos313
  • 639
  • They are called personal macros. http://texstudio.sourceforge.net/manual/current/usermanual_en.html#SECTION33 – Sango Feb 04 '20 at 09:59

2 Answers2

4

This should work, especially if you want to do more than just make it bold. Put that in the personal macros entry.

%SCRIPT
var text=cursor.selectedText()

if(text.length>0)
{
    //cut selected text
    cursor.removeSelectedText()
    editor.write("\\textbf{");
    editor.write(text);
    editor.write("}");
}

Based on: https://sourceforge.net/p/texstudio/wiki/Scripts

In TexStudio (sorry german)

enter image description here enter image description here

Then select Text

enter image description here

Hit (in my case Shift+F2) And there it is

enter image description here

Sango
  • 887
  • +1 it works and, thanks to your answer, I am discovering the MACRO in latex! Thank you – Leos313 Feb 04 '20 at 10:13
  • I am discovering a wonderful world! Where can I found the list of actions that can trigger a macro? – Leos313 Feb 04 '20 at 10:16
  • 1
    @Leos313 In embedded user manual, subsection 4.5 "Personal macros". – Mr. Sandman Feb 04 '20 at 10:21
  • @Sango, I must say your solution provided me some new knowledge and ideas for macros ... but, in this specific case, how is this better than just Ctrl + B? Would it be the exact operation that TeXstudio performs through the keyboard shortcut? – FHZ Feb 05 '20 at 03:52
  • 2
    I just didn't think about Ctrl+B, so thats the reason i did it this way. BUT as said, this has the potential to do more than just bold. Thats my excuse for keeping it :) – Sango Feb 05 '20 at 08:22
3

It's standard TeXstudio possibility: highlight some text by mouse and press Ctrl + B and whereupon you get \textbf{some text}.