Copy link to clipboard
Copied
Hello,
I am typesetting a book on Persian food which has many words that should be italicised. However the formatting has been lost after copying/pasting from MS Word into inDesign and I can't think of having to re-do it manually.
I have a separate list of words that should be italicised, so I was thinking of applying a character style through a GREP style or similar. However, I don't know how to apply a GREP style to a list of words. Do GREP styles only work for single words? I hope not because I have more than 100 to format...
Thanks in advance for any advise.
Daniele
1 Correct answer
Hi
My first thought would be FindChangeByList script.
text
{findWhat:"your word here"}
{appliedCharacterStyle:"italic"}
{includeHiddenLayers:true, includeMasterPages:true, includeFootnotes:true, wholeWord:true, caseSensitive:false}
This would require some manipulation to stick your words in the above pattern.
However, it wouldn't be so difficult to do it in an Excel file.
See what I mean?
However, there might be easier ways, so I would wait for other users answers before going deeper into this process.
Copy link to clipboard
Copied
Hi
My first thought would be FindChangeByList script.
text
{findWhat:"your word here"}
{appliedCharacterStyle:"italic"}
{includeHiddenLayers:true, includeMasterPages:true, includeFootnotes:true, wholeWord:true, caseSensitive:false}
This would require some manipulation to stick your words in the above pattern.
However, it wouldn't be so difficult to do it in an Excel file.
See what I mean?
However, there might be easier ways, so I would wait for other users answers before going deeper into this process.
Copy link to clipboard
Copied
Hi,
… When all has already been written … since five years! …
textFile = File(Folder.myDocuments+"/list.txt");
if (textFile.open("r") == false)
{ alert ("yeah ... that file does not exist"); exit(0); }
strs = textFile.read ();
textFile.close();
strs = strs.split("\n");
app.findGrepPreferences = app.changeGrepPreferences = null;
app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("yourStyle");
while (strs.length > 0)
{
app.findGrepPreferences.findWhat = "\\b"+strs.pop()+"\\b";
app.activeDocument.changeGrep();
}
(^/)
Copy link to clipboard
Copied
… with this "French Touch" variant!
textFile = File(File($.fileName).parent.fullName + "/list.txt");
(^/)
Copy link to clipboard
Copied
Ah OK c'est bon j'ai capté.
C'est effectivement rapide et efficace, par contre comment tu limites à un style de paragraphe donné?
Copy link to clipboard
Copied
var myTextFile = File(File(app.activeDocument.filePath + "/list.txt"));
if(myTextFile.exists) {
myTextFile.open();
var myWord = myTextFile.read();
myWord = myWord.split("\n");
myTextFile.close();
app.findGrepPreferences = app.changeGrepPreferences = null;
app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("Italics");
while (myWord.length > 0 ) {
app.findGrepPreferences.findWhat = "\\b"+myWord.pop()+"\\b";
app.findGrepPreferences.appliedParagraphStyle = "Blue";
app.activeDocument.changeGrep();
app.findGrepPreferences.appliedParagraphStyle = "Green";
app.activeDocument.changeGrep();
}
}
else alert (decodeURI(myTextFile) + " not found");
My personal version, limited to 2 para styles, "Blue" and "Green"!
Just place the "list" (saved in .txt) at the same level as the .indd file, change the char/para styles names, defining the targets [lines 12-13 duplicated].
(^/)
Copy link to clipboard
Copied
"… C'est effectivement rapide et efficace …"
Je prends ça pour une litote !
(^/)
Copy link to clipboard
Copied
Pas bien compris ton script l'ami.
Tu le met où ton fichier .txt?
Copy link to clipboard
Copied
Thank you Vinny (and everyone else) for your help. Next time I will try to preserve the original formatting when importing the text!
Anyways, the FindChangeByList script method works pretty good in this case!
Is there by any chance a way to limit the search within text that has a specific Paragraph Style applied to it?
Most of the words that need to be italicised are in the Body text, but I wouldn't want them to be in italics when they appear in chapter titles / subheadings.
Thank again!
Copy link to clipboard
Copied
Sure:
text
{findWhat:"yourword",appliedParagraphStyle:"yourparastyle"}
{appliedCharacterStyle:"yourcharstyle"}
{includeHiddenLayers:true, includeMasterPages:true, includeFootnotes:true, wholeWord:true, caseSensitive:false}
Copy link to clipboard
Copied
Sometimes, I really ask myself if people understand what they are told!
(^/)
Copy link to clipboard
Copied
https://forums.adobe.com/people/Obi-wan+Kenobi wrote
Sometimes, I really ask myself if people understand what they are told!
quelquefois
Copy link to clipboard
Copied
Désolé maître Obi-Wan, but to me inDesign scripts are still a bit of a mystery.
I went with Vinny's script because I could figure out how to run it without using too much code that I don't really know what means...
Copy link to clipboard
Copied
To Learn Something Maybe Time For You!
Imagine a 100-words list, a 100-para styles doc!
… And the need to italicize these 100 words exluding paras where only 5 specific para styles are applied!!!
Just calculate: (100 - 5) * 100 = 9,500 code lines with FindChangeByList!! Funny!
I just prefer one work-minute and one click!
Your list:
Your ID file, before:
Your ID file, after:
The Script:
/*
0126_ApplyACharStyleToAWordsListWithExclusions_MichelAllio.jsx
Script written by Michel Allio [2017/03/17]
*/
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Italics! …");
function main()
{
var myDoc = app.activeDocument,
myTextFile = File(File(myDoc.filePath + "/list.txt"));
if(myTextFile.exists) {
if (!myDoc.conditions.item("Target").isValid) myDoc.conditions.add ({name: "Target", indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor: [255,255,255]});
var myCondition1 = "Target";
if (!myDoc.conditions.item("Italics").isValid) myDoc.conditions.add ({name: "Italics", indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor: [200,200,150]});
var myCondition2 = "Italics";
myDoc.conditionalTextPreferences.showConditionIndicators = ConditionIndicatorMode.HIDE_INDICATORS;
// Char Style Applied!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var myCharStyle = "Italics", // To Be Modified!
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Para Styles Excluded!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
myExcludedParaStyles = ["Blue", "Green"], // To Be Modified!
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
E = myExcludedParaStyles.length;
while ( E-- ) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = myExcludedParaStyles
; app.changeGrepPreferences.appliedConditions = [myCondition1];
myDoc.changeGrep( );
}
myTextFile.open();
var myWord = myTextFile.read();
myWord = myWord.split("\n");
myTextFile.close();
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.appliedConditions = [];
app.changeGrepPreferences.appliedCharacterStyle = myDoc.characterStyles.item(myCharStyle);
while (myWord.length > 0) {
app.findGrepPreferences.findWhat = "\\b"+myWord.pop()+"\\b";
app.changeGrepPreferences.appliedConditions = [myCondition2];
myDoc.changeGrep();
}
myDoc.conditions.item("Target").remove();
myDoc.conditionalTextPreferences.showConditionIndicators = ConditionIndicatorMode.SHOW_INDICATORS;
alert ("Done!\r\r(^/) ;-)");
}
else alert (decodeURI(myTextFile) + " not found");
}
I only think it's a better way to fix this kind of question!
(^/)
Copy link to clipboard
Copied
If you use Place instead of copy-paste, does that keep your italic formatting?
Copy link to clipboard
Copied
File > Place by default keeps your formatting such as italics
Copy > Paste does not
Clipboard Handling Preferences can be changed:
as can Import Options for placing:
Copy link to clipboard
Copied
If you are using CC ( it may also be in earlier versions), you can turn on "All information" under clipboard handling. This will allow you to preserve your word italicizing. From there, you can search for paragraph and character styles using command+f and apply your new character styles, or you can simply format the ones that will be brought in from word.
hope that does it!
Copy link to clipboard
Copied
When I import text that has been styled, I choose to strip out the styling (which tends not to be correct or consistent) but preserve local overrides. Then, as was suggested above, do a Find on character styling of italic and Replace it with your italic character style. All of this is assuming the original text is italicized where you need it.

