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

Applying a same character style to different words inside a text

New Here ,
Mar 16, 2017 Mar 16, 2017

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

Views

888

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

Guide , Mar 16, 2017 Mar 16, 2017

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.

Votes

Translate

Translate
Guide ,
Mar 16, 2017 Mar 16, 2017

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.

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
LEGEND ,
Mar 16, 2017 Mar 16, 2017

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(); 

}

(^/) 

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
LEGEND ,
Mar 16, 2017 Mar 16, 2017

Copy link to clipboard

Copied

… with this "French Touch" variant! 

textFile = File(File($.fileName).parent.fullName + "/list.txt"); 

(^/)

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 ,
Mar 17, 2017 Mar 17, 2017

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é?

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
LEGEND ,
Mar 17, 2017 Mar 17, 2017

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

(^/) 

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
LEGEND ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

"… C'est effectivement rapide et efficace …"

Je prends ça pour une litote ! 

(^/)

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 ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

Pas bien compris ton script l'ami.

Tu le met où ton fichier .txt?

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 ,
Mar 17, 2017 Mar 17, 2017

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!

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 ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

Sure:

text

{findWhat:"yourword",appliedParagraphStyle:"yourparastyle"}

{appliedCharacterStyle:"yourcharstyle"}

{includeHiddenLayers:true, includeMasterPages:true, includeFootnotes:true, wholeWord:true, caseSensitive:false}

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
LEGEND ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

Sometimes, I really ask myself if people understand what they are told!

(^/)

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 ,
Mar 17, 2017 Mar 17, 2017

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

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 ,
Mar 17, 2017 Mar 17, 2017

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...

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
LEGEND ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

LATEST

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:

Capture d’écran 2017-03-17 à 18.06.37.png

Your ID file, before:

Capture d’écran 2017-03-17 à 18.18.08.png

Your ID file, after:

Capture d’écran 2017-03-17 à 18.18.41.png

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!

(^/)

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 ,
Mar 16, 2017 Mar 16, 2017

Copy link to clipboard

Copied

If you use Place instead of copy-paste, does that keep your italic formatting?

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 ,
Mar 16, 2017 Mar 16, 2017

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:

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 Beginner ,
Mar 16, 2017 Mar 16, 2017

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!

Screen Shot 2017-03-16 at 4.09.33 PM.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
Enthusiast ,
Mar 16, 2017 Mar 16, 2017

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.

textimport.jpeg

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