Funktion for automatic formatation defined words in Docs?

Hello thogether,
I write some very long texts with repetitive scientific terms and names. It’s a matter of professionalism that these are written in italics. Formatting each one individually is sometimes very time-consuming and annoying. I’ve already searched the forum for a solution but haven’t found one. Is there a way to automatically format certain defined words in italics?

regards

Hello @NScale,
You can use a macro like this:

(function()
{
    let doc = Api.GetDocument();
    let searchResult = doc.Search("your text");
    for (let i=0; i<searchResult.length; i++) {
        searchResult[i].SetItalic(true)}
})();

Hello @Carl ,
im not realy fit in scripting and macros. If i understand it right, i can not place a Macro for all Docs, only in the on i opened. So i would have to copy it from Doc to Doc i write, right?
Next is, after playing the macro, im only able to format the first searchResult. I copied the row and added my words like this:

(function()
{
    let doc = Api.GetDocument();
    let searchResult = doc.Search("Word1");
    let searchResult = doc.Search("Word2");
    let searchResult = doc.Search("WordXYZ");
    for (let i=0; i<searchResult.length; i++) {
        searchResult[i].SetItalic(true)}
})();

but this issnt working. Only “Word1” will be formated. Not realy a practicable solution by potentioal 50+ Words.

Macros are embedded into documents, so yes, you will need to copy it from one document to another.

For your use case, try this modified version of the macro:

(function()
{
    function italicizeSearch(text) {
    let result = doc.Search(text);
    for (let i = 0; i < result.length; i++) {
        result[i].SetItalic(true);
    }
}

let doc = Api.GetDocument();
italicizeSearch("Text1");
italicizeSearch("Text2");
italicizeSearch("Text3")
})();

Here you can add a new line with italicizeSearch("xxx") for each required word.

1 Like