• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
11

Find/Replace italics in word?

New Here ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

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?

TOPICS
Scripting , Type

Views

583

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 07, 2023 Nov 07, 2023

Votes

Translate

Translate
Engaged ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

Hi @michalart 

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

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

Either some fancy GREP or script. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

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. 

RobertTkaczyk_0-1699374393075.pngRobertTkaczyk_0-1699374194712.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

LATEST

Hello @Brito Haroldo  thank you, the link you provided solves exactly what I needed to solve, it is perfect and simple 🙂 Thanks a lot

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

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:

bef.PNG

 

After:

aft.PNG

 

 

____________________
Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

Thanks, unfortunately, for various reasons, mainly because I don't have a Mac and I don't think it would be possible to create such advanced UI on a Mac - I mean with such advanced functionality - I don't plan on creating version for Mac ... but you can always use it in your network, you would need a dedicated PC and WatchedFolders Mode.

 

I'm not a JS guy so if I can, I may try to share some JS code but rather prefer to give an "algorithm", just in case I'm mistaken.

 

Sometimes, my replies may sound harsh, as English isn't my main language, I might be too direct and not polite enough.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

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

 

RobertTkaczyk_0-1699367114087.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

… 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]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines