Skip to main content
Participant
November 7, 2023
Answered

Find/Replace italics in word?

  • November 7, 2023
  • 6 replies
  • 1604 views

I have a text of about 300 pages in InDesign. Some words, which should be in italics, have one or 2 letters in regular. Is there a way to automatically find all words where one or two letters are not in italics and change them to italics like the remaining letters in the word?

This topic has been closed for replies.
Correct answer Brito Haroldo

Hello @michalart see if this helps you: https://creativepro.com/how-to-find-and-fix-partially-italic-words-with-grep/

6 replies

FRIdNGE
November 7, 2023

… Hmm! Sometimes, a partial italic can justify the entire word(s) are italicized, sometimes not!  😉

 

So, "Do" or "Skip"!

 

Just For Fun! …

 

 

(^/)  The Jedi

[paid script]

Willi Adelberger
Community Expert
Community Expert
November 7, 2023

Select in Word 1 formatted word or letter, in the style menu is command to select all with this formatting. Now you can apply or create a character style. 

Brito Haroldo
Inspiring
November 7, 2023

hello @Willi Adelberger . I love solutions that scale from something just within reach to more sophisticated solutions.

I tested here in Word for Mac I managed to get the italics, not italics but mixed: italics/non-italics, at least in my Word, it didn't work: it selected all the text without understanding my intention of just "mixed".

 

Maybe it works on Windows, or I'm definitely doing something wrong.

Robert at ID-Tasker
Legend
November 7, 2023

No, on Windows it won't work either, it will only select letters with this particular formatting - not whole words:

 

 

GNDGN
Inspiring
November 7, 2023

This does the job:

var c = 0;
var tfs = app.activeDocument.textFrames;

for(i=0; i<tfs.length; i++) {
	for(j=0; j<tfs[i].words.length; j++) {
		var italicChars = 0;

		for(k=0; k<tfs[i].words[j].characters.length; k++) {
			if(tfs[i].words[j].characters[k].fontStyle == "Italic") {
				italicChars++;
			}

			if( (k == tfs[i].words[j].characters.length-1) && (tfs[i].words[j].characters.length > italicChars) && (italicChars != 0) ) {
				tfs[i].words[j].fontStyle = "Italic";
				c++;
			}
		}
	}
}

alert(c + " words replaced in " + tfs.length + " text frames.");

 

Before:

 

After:

 

 

____________________Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5
Robert at ID-Tasker
Legend
November 7, 2023

Don't want to sound patronising, just trying to be helpful:

  • You don't have to continue anlysing all letters in the word - first occurence is enough and you can break the internal loop - will be much quicker - right now you are re-styling each word over and over again - as many times as there are letters in the Word,
  • Instead of processing TextFrames - you should be processing Stories,
  • Instead of applying "italic" FontStyle - you should apply CharStyle - otherwise it's pointless as someone will have to do another Find&Replace manually to apply CharStyle to local formatting.
  • Right now, TextFrames with overflow won't be processed - that's why you should be processing Stories.

 

Brito Haroldo
Inspiring
November 7, 2023

hello @Robert at ID-Tasker , firstly congratulations on your tool it really looks very robust. For now I'll need to wait for the Mac version.

 

Now about your comment it seems perfect! It would be incredible, and I believe the community would appreciate it, if you had some time to improve your suggestions on the code suggested, which is functional within what is proposed, by colleague @GNDGN . 😃

 

In any case, your comments are valuable especially for those, like me, who are struggling to learn scripts and being able to relate action x result and strategy is undoubtedly an important layer in learning.

Brito Haroldo
Brito HaroldoCorrect answer
Inspiring
November 7, 2023
Robert at ID-Tasker
Legend
November 7, 2023
quote

Hello @michalart see if this helps you: https://creativepro.com/how-to-find-and-fix-partially-italic-words-with-grep/


By @Brito Haroldo

 

Thanks for this link - it just gave me an idea how to improve my tool even more. 

 

Robert at ID-Tasker
Legend
November 7, 2023

Either some fancy GREP or script. 

 

Anantha Prabu G
Legend
November 7, 2023

Hi @michalart 

Can you show a screenshot of what you need before and after? It would be easiest for anyone reading here.

Design smarter, faster, and bolder with InDesign scripting.