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

Compare Italic between docs

Engaged ,
May 07, 2018 May 07, 2018

Copy link to clipboard

Copied

Hello everyone!

I have 2 documents:

Original.indd

Typeset.indd

I need to compare if that Typeset.indd has the same italics as Original.indd

Is important to know, not always the same words have italics. The same word can in a paragraph have italic and in the same paragraph not have it. Like you can see in this paragraph, with the word human:

All human beings are born free and equal in dignity and rights. Human endowed with reason and conscience and should act towards one another in a spirit of brotherhood, human has the right to life, liberty and security of person.

Is posible do this with a script?

Here are my files ready to Download

Any help will be appreciate. Thanks so much!

TOPICS
Scripting

Views

1.2K

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

Engaged , Jun 15, 2018 Jun 15, 2018

here the solution, thanks to everyone for the help.

DOWNLOAD THE FILES

Download

OTHER SIMILAR SCRIPT TO COMPARE TEXT

Download

THE SCRIPT

// get documents to compare

$.writeln();

var myDocs= app.documents; 

var compareDoc1 = myDocs.itemByName ("Original.indd"); 

var compareDoc2 = myDocs.itemByName ("Typeset.indd"); 

 

// get all the stories 

var compareDoc1Stories = compareDoc1.stories.everyItem(); 

var compareDoc2Stories = compareDoc2.stories.everyItem(); 

 

 

// get all the words 

var compareDoc1Wor

...

Votes

Translate

Translate
Community Expert ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Hi,

Just to clarify so that I can see about a solution, you want to check if the same word in the same place has italics.

for example :

Original.indd, paragraph 1, word 2, is italic

TypeSet.indd: paragraph 1, word 2, is italic

Does it matter if they are the same word, or just that they are italic?

Regards

Malcolm

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
Engaged ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Hi Malcolm, thanks for your time,

yes, I want to check if the same word in the same place has italics.

yes, I need be the same word.

for example here I need get an ERROR because in the Original.indd only the first human has italic, and the TypeSet.indd has the first and the third human with italic:

Original.indd

All human beings are born free and equal in dignity and rights. Human endowed with reason and conscience and should act towards one another in a spirit of brotherhood, human has the right to life, liberty and security of person.

TypeSet.indd

All human beings are born free and equal in dignity and rights. Human endowed with reason and conscience and should act towards one another in a spirit of brotherhood, human has the right to life, liberty and security of person.

Please take note, this indesign files are only an examples, in a real document, I don't know previously which words will be with italic, sometimes are hundreds differents words. This script I need use in any documents with italics.

Thanks so much!

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 ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Hi,

Something like this should be some help.

// get documents to compare

var myDocs= app.documents;

var compareDoc1 = myDocs.itemByName ("Original.indd");

var compareDoc2 = myDocs.itemByName ("Typeset.indd");

// get all the stories

var compareDoc1Stories = compareDoc1.stories.everyItem();

var compareDoc2Stories = compareDoc2.stories.everyItem();

// get all the words

var compareDoc1Words = compareDoc1Stories.words.everyItem().getElements();

var compareDoc2Words = compareDoc2Stories.words.everyItem().getElements();

var numberOfWords = compareDoc1Words.length;

// incase they have differnet lengths, use the shorter one to make sure we don't access areas we are not allowed to be.

if ( compareDoc2Words.length < numberOfWords )

{

    numberOfWords = compareDoc2Words.length;

}

// for each word

for ( var i = 0; i < numberOfWords; i++)

{

    var currentDoc1Word = compareDoc1Words;

    var currentDoc2Word = compareDoc2Words;

     // get the word

    var currentDoc1Contents = currentDoc1Word.contents;

    var currentDoc2Contents = currentDoc2Word.contents;

    //get the font style

    var currentDoc1FontStyle = currentDoc1Word.fontStyle;

    var currentDoc2FontStyle = currentDoc2Word.fontStyle;

    // as we are only looking for italics

    if ( currentDoc1FontStyle === "Italic")

    {

        if ( ! ( ( currentDoc1Contents === currentDoc2Contents ) && ( currentDoc1FontStyle === currentDoc2FontStyle)))

        {

          // report a fail in whichever makes most sense for you.

            alert ( "unmatched italics");

        }

    }

}

Hope this helps

Malcolm

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
Engaged ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Hi Malcolm,

woow! is like magic.

But, if I test in a long document, is very hard to know where is the error. Is possible show in the alert the problematic word, or better a text around the word, just to find quickly. Like:

ALERT:

The next words did't match:

...spirit of brotherhood, human has the right to life...

Thanks so much!

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 ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

HI,

There are a number of options that you could use, but it would depend on your workflow as to which is more useful.

You could use the parentTextFrame of the word and select the frame for the user to compare.

You could use the parentStory to get the whole story that contains the difference.

You could use the textStyleRanges to get all the words that are italicized and use that as the reference string.

And probably a whole load of other options depending on your workflow and how you want the script to interact with the user.

Regards

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
Engaged ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Hi!

I only want add the current text paragraph.

I try to do:

          var currentDoc1Contents = currentDoc1Word.contents;

          alert ( "unmatched italics: " + currentDoc1Contents);

and I get the problematic word.

Do you know how get the full paragraph text?

Thanks!

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 ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Hi,

Getting the full paragraph is probably not as easy as it would appear, you can easily get a number of words that surround the word that failed, just by using the index to get the words.

In the code above we get the word to test "var currentDoc1Word = compareDoc1Words;"

you could easily add something like

var previousWordLocation = i - 1;

var previousWord = compareDoc1Words[previousWordLocation];

var nextWordLocation = i + 1;

var newWord = compareDoc1Words[nextWordLocation];

I have done this with word 1, but you could do it with both, there is also no reason you could take 2,3,4 or how ever many words you want before or after the one that failed, but you would need to make sure that those words exist, check that you are not out of range of the total number of words you have, or trying to access the array with a negative number.

Once you have all the words then you can just concat them to make  a string.

var retString = previousWord + FailedWord + nextWord; // simplification to keep code easy.

Hope this helps

Malcolm

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
Engaged ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Hi Malcolm!

I get this error:

Screen Shot 2018-05-08 at 18.41.57.png

I added your code in the lines 87 and 114:

// get documents to compare

var myDocs= app.documents;

var compareDoc1 = myDocs.itemByName ("Original.indd");

var compareDoc2 = myDocs.itemByName ("Typeset.indd");

// get all the stories

var compareDoc1Stories = compareDoc1.stories.everyItem();

var compareDoc2Stories = compareDoc2.stories.everyItem();

// get all the words

var compareDoc1Words = compareDoc1Stories.words.everyItem().getElements();

var compareDoc2Words = compareDoc2Stories.words.everyItem().getElements();

var numberOfWords = compareDoc1Words.length;

// incase they have differnet lengths, use the shorter one to make sure we don't access areas we are not allowed to be.

if ( compareDoc2Words.length < numberOfWords )

{

    numberOfWords = compareDoc2Words.length;

}

// for each word

for ( var i = 0; i < numberOfWords; i++)

{

    var currentDoc1Word = compareDoc1Words;

    var currentDoc2Word = compareDoc2Words;

     // get the word

    var currentDoc1Contents = currentDoc1Word.contents;

    var currentDoc2Contents = currentDoc2Word.contents;

    //get the font style

    var currentDoc1FontStyle = currentDoc1Word.fontStyle;

    var currentDoc2FontStyle = currentDoc2Word.fontStyle;

    // as we are only looking for italics

    var previousWordLocation = i - 1;

    var previousWord = compareDoc1Words[previousWordLocation];

    var nextWordLocation = i + 1;

    var newWord = compareDoc1Words[nextWordLocation];

    // as we are only looking for italics

    if ( currentDoc1FontStyle === "Italic")

    {

        if ( ! ( ( currentDoc1Contents === currentDoc2Contents ) && ( currentDoc1FontStyle === currentDoc2FontStyle)))

        {

          // report a fail in whichever makes most sense for you.

          var retString = previousWord + FailedWord + nextWord; // simplification to keep code easy.

          var currentDoc1Contents = currentDoc1Word.contents;

           alert ( "unmatched italics: " + currentDoc1Contents + retString);

        }

    }

}

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

HI,

Sorry, I used that as an example, in your code that would be currentDoc1Contents or currentDoc2Contents, depending on which one failed.

I also notice that you have added "var currentDoc1Contents = currentDoc1Word.contents" to the if statement this is not needed as you already have a valid currentDoc1Contents variable from above in the code.

Hope this helps

Malcolm

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
Engaged ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Hi Malcolm,

I declarate 2 variables in line 13, 14. And in the line 65 I try to print but didn't work. I don't know how declare properly:

var compareDoc1Stories = compareDoc1.stories.everyItem();

I try with

var compareDoc1Stories = compareDoc1.everyItem();

etc...

but didn't work. I was checking in Google, and Do you think I need first create a function to take the words before and after like here, or not is than complicate?

// get documents to compare

var myDocs= app.documents;

var compareDoc1 = myDocs.itemByName ("Original.indd");

var compareDoc2 = myDocs.itemByName ("Typeset.indd");

// get all the stories

var compareDoc1Stories = compareDoc1.stories.everyItem();

var compareDoc2Stories = compareDoc2.stories.everyItem();

// get previous and next words

var currentDoc1previousWord = currentDoc1Word.previousWord.everyItem();

var currentDoc2previousWord = currentDoc2Word.previousWord.everyItem();

// get all the words

var compareDoc1Words = compareDoc1Stories.words.everyItem().getElements();

var compareDoc2Words = compareDoc2Stories.words.everyItem().getElements();

var numberOfWords = compareDoc1Words.length;

// incase they have differnet lengths, use the shorter one to make sure we don't access areas we are not allowed to be.

if ( compareDoc2Words.length < numberOfWords )

{

    numberOfWords = compareDoc2Words.length;

}

// for each word

for ( var i = 0; i < numberOfWords; i++)

{

    var currentDoc1Word = compareDoc1Words;

    var currentDoc2Word = compareDoc2Words;

    // get the word

    var currentDoc1Contents = currentDoc1Word.contents;

    var currentDoc2Contents = currentDoc2Word.contents;

    //get the font style

    var currentDoc1FontStyle = currentDoc1Word.fontStyle;

    var currentDoc2FontStyle = currentDoc2Word.fontStyle;

    // get previous and next words, to show the text around the word

    var previousWordLocation = i - 1;

    var previousWord = compareDoc1Words[previousWordLocation];

    var nextWordLocation = i + 1;

    var newWord = compareDoc1Words[nextWordLocation];

    // as we are only looking for italics

    if ( currentDoc1FontStyle === "Italic")

    {

        if ( ! ( ( currentDoc1Contents === currentDoc2Contents ) && ( currentDoc1FontStyle === currentDoc2FontStyle)))

        {

          // report a fail in whichever makes most sense for you.

// simplification to keep code easy.

           alert ( "unmatched italics: " + currentDoc1previousWord);

        }

    }

}

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
Engaged ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Hi Malcolm!

I still testing, and I find the problem.

For example if In the alert I write:

previousWordLocation instead of retString, I get the number of the word. But the problem is in the line 35, when I try to get the word, I get a pop up like this:

Screen Shot 2018-05-09 at 23.25.44.png

Please any sugestion? thanks!

// get documents to compare

var myDocs= app.documents;

var compareDoc1 = myDocs.itemByName ("Original.indd");

var compareDoc2 = myDocs.itemByName ("Typeset.indd");

// get all the stories

var compareDoc1Stories = compareDoc1.stories.everyItem();

var compareDoc2Stories = compareDoc2.stories.everyItem();

// get all the words

var compareDoc1Words = compareDoc1Stories.words.everyItem().getElements();

var compareDoc2Words = compareDoc2Stories.words.everyItem().getElements();

var numberOfWords = compareDoc1Words.length;

// incase they have differnet lengths, use the shorter one to make sure we don't access areas we are not allowed to be.

if ( compareDoc2Words.length < numberOfWords )

{

    numberOfWords = compareDoc2Words.length;

}

// for each word

for ( var i = 0; i < numberOfWords; i++)

{

    var currentDoc1Word = compareDoc1Words;

    var currentDoc2Word = compareDoc2Words;

     // get the word

    var currentDoc1Contents = currentDoc1Word.contents;

    var currentDoc2Contents = currentDoc2Word.contents;

    //get the font style

    var currentDoc1FontStyle = currentDoc1Word.fontStyle;

    var currentDoc2FontStyle = currentDoc2Word.fontStyle;

    //get the previous Word Location

    var previousWordLocation = i -1;

    var previousWord = compareDoc1Words[previousWordLocation];

    var retString = previousWord;

    // as we are only looking for italics

    if ( currentDoc1FontStyle === "Italic")

    {

        if ( ! ( ( currentDoc1Contents === currentDoc2Contents ) && ( currentDoc1FontStyle === currentDoc2FontStyle)))

        {

            alert ( "unmatched italics: " + currentDoc1Contents + " " + retString); // report a fail in whichever makes most sense for you.

        }

    }

}

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 ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

Hi,

retString is a Word Object, hence the string you get in the dialog, if you want the actual word you need to add ".contents" so the alert line would read.

alert ( "unmatched italics: " + currentDoc1Contents + " " + retString.contents);

Or you could change the declaration line to

var retString = previousWord.contents;

Either would work.

hope this helps

Malcolm

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
Engaged ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

Hi Barlae!

yes now is working

But I was testing, and I get a error, if the word is place in the first position or at the end of the document. Like you can see in the picture, this is the last word of the document and I get a error:

Screen Shot 2018-05-10 at 11.53.05.png

Here the code:

// get documents to compare

var myDocs= app.documents;

var compareDoc1 = myDocs.itemByName ("Original.indd");

var compareDoc2 = myDocs.itemByName ("Typeset.indd");

// get all the stories

var compareDoc1Stories = compareDoc1.stories.everyItem();

var compareDoc2Stories = compareDoc2.stories.everyItem();

// get all the words

var compareDoc1Words = compareDoc1Stories.words.everyItem().getElements();

var compareDoc2Words = compareDoc2Stories.words.everyItem().getElements();

var numberOfWords = compareDoc1Words.length;

// incase they have differnet lengths, use the shorter one to make sure we don't access areas we are not allowed to be.

if ( compareDoc2Words.length < numberOfWords )

{

    numberOfWords = compareDoc2Words.length;

}

// for each word

for ( var i = 0; i < numberOfWords; i++)

{

    var currentDoc1Word = compareDoc1Words;

    var currentDoc2Word = compareDoc2Words;

     // get the word

    var currentDoc1Contents = currentDoc1Word.contents;

    var currentDoc2Contents = currentDoc2Word.contents;

    //get the font style

    var currentDoc1FontStyle = currentDoc1Word.fontStyle;

    var currentDoc2FontStyle = currentDoc2Word.fontStyle;

    //get the previous Word Location

    var previousWordLocation = i -1;

    var previousWord = compareDoc1Words[previousWordLocation];

    var previousString = previousWord;

    var previousWordLocation2 = i -2;

    var previousWord2 = compareDoc1Words[previousWordLocation2];

    var previousString2 = previousWord2;

    //get the next Word Location

    var nextWordLocation = i + 1;

    var nextWord = compareDoc1Words[nextWordLocation];

    var nextString = nextWord;

    // as we are only looking for italics

    if ( currentDoc1FontStyle === "Italic")

    {

        if ( ! ( ( currentDoc1Contents === currentDoc2Contents ) && ( currentDoc1FontStyle === currentDoc2FontStyle)))

        {

          

            alert ( "unmatched italics: " + previousString2.contents + " " +previousString.contents + " " + currentDoc1Contents + " " + nextString.contents); // report a fail in whichever makes most sense for you.

        }

    }

       

}

Thanks!

Here are my files ready to Download

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 ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

Hi,

Because the word that failed is the last word in the document, you cannot get the word after it, as there is no word to get.

If this is the case you need to check there is actually a word to get before you use it. You could do this in two ways.

1 - Check the number of words you have, and make sure that there are more words after the one that failed.

     var nextStringLocation = i + 1;

     var nextString = null; // define it so we know it has changed.

     if ( numberOfWords > nextStringLocation)

     {

          nextString = compareDocWords [ nextStringLocation];

     }

    

      if ( nextString !== null)    

     {

          alert ( "unmatched italics: " + previousString.contents + " " + currentDoc1Contents + " " + nextString.contents);

     }

2 - check that nextWord is valid before you use it.

     if ( nextString !== undefined)

     {

          alert ( "unmatched italics: " + previousString.contents + " " + currentDoc1Contents + " " + nextString.contents);

     }

It is up to you how you handle this, although note you probably need to handle the same for "previousString" in case the failed word is the first word in the document/story as there will be no word before it.

hope this helps

Malcolm

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
Engaged ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

Hi!

I use the second method, is working but when find end of the word, stop to work, and don't show any alert.

To fix this, I added a second alert like:

if ( nextString === undefined){

      ("Unmatched italics in the word: " + previousString.contents + " " + currentDoc1Contents);

But didn't work, maybe is not correct use undefined?

Thank you

// get documents to compare

var myDocs= app.documents;

var compareDoc1 = myDocs.itemByName ("Original.indd");

var compareDoc2 = myDocs.itemByName ("Typeset.indd");

// get all the stories

var compareDoc1Stories = compareDoc1.stories.everyItem();

var compareDoc2Stories = compareDoc2.stories.everyItem();

// get all the words

var compareDoc1Words = compareDoc1Stories.words.everyItem().getElements();

var compareDoc2Words = compareDoc2Stories.words.everyItem().getElements();

var numberOfWords = compareDoc1Words.length;

// incase they have differnet lengths, use the shorter one to make sure we don't access areas we are not allowed to be.

if ( compareDoc2Words.length < numberOfWords )

{

    numberOfWords = compareDoc2Words.length;

}

// for each word

for ( var i = 0; i < numberOfWords; i++)

{

    var currentDoc1Word = compareDoc1Words;

    var currentDoc2Word = compareDoc2Words;

     // get the word

    var currentDoc1Contents = currentDoc1Word.contents;

    var currentDoc2Contents = currentDoc2Word.contents;

    //get the font style

    var currentDoc1FontStyle = currentDoc1Word.fontStyle;

    var currentDoc2FontStyle = currentDoc2Word.fontStyle;

    //get the previous Word Location

    var previousWordLocation = i -1;

    var previousWord = compareDoc1Words[previousWordLocation];

    var previousString = previousWord;

    //get the next Word Location

    var nextWordLocation = i + 1;

    var nextWord = compareDoc1Words[nextWordLocation];

    var nextString = nextWord;

    // as we are only looking for italics

    if ( currentDoc1FontStyle === "Italic")

    {

        if ( ! ( ( currentDoc1Contents === currentDoc2Contents ) && ( currentDoc1FontStyle === currentDoc2FontStyle)))

        {

            if ( nextString !== undefined){

            alert ( "Unmatched italics in the word: " + previousString.contents + " " + currentDoc1Contents + " " + nextString.contents); // report a fail in whichever makes most sense for you.

            }

            if ( nextString === undefined){

                ("Unmatched italics in the word: " + previousString.contents + " " + currentDoc1Contents);

        }

    }

       

}

}

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 ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

HI,

Based on the error you are missing a closing '}'  in that if that you added it should be

Note: you are also missing the keyword "alert")

if ( nextString === undefined)

{

     alert ( ....);

}

Regards

Malcolm

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
Engaged ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

Hi Barlae!

I start to see the light

But small problem still, I try to test all posible cases using:

            if ( previousString !== undefined || nextString !== undefined){ 

                alert ( "Unmatched italics in: " + previousString.contents + " " + currentDoc1Contents + " " + nextString.contents); // report a fail in whichever makes most sense for you. 

            } 

            if ( previousString === undefined){ 

                alert("Unmatched italics in " + currentDoc1Contents + " " + nextString.contents); 

            }

            if ( nextString === undefined){ 

                alert("Unmatched italics in: " + previousString.contents + " " + currentDoc1Contents); 

            } 

            else{

                alert("Unmatched italics in the word: " + currentDoc1Contents); 

            }

But all the words are processed 2 times:

Screen Shot 2018-05-10 at 14.12.18.png

Screen Shot 2018-05-10 at 14.13.25.png

and finally I get a error:

Screen Shot 2018-05-10 at 14.14.14.png

Full code:

// get documents to compare 

var myDocs= app.documents; 

var compareDoc1 = myDocs.itemByName ("Original.indd"); 

var compareDoc2 = myDocs.itemByName ("Typeset.indd"); 

 

// get all the stories 

var compareDoc1Stories = compareDoc1.stories.everyItem(); 

var compareDoc2Stories = compareDoc2.stories.everyItem(); 

 

 

// get all the words 

var compareDoc1Words = compareDoc1Stories.words.everyItem().getElements(); 

var compareDoc2Words = compareDoc2Stories.words.everyItem().getElements(); 

var numberOfWords = compareDoc1Words.length; 

 

 

// incase they have differnet lengths, use the shorter one to make sure we don't access areas we are not allowed to be. 

if ( compareDoc2Words.length < numberOfWords ) 

    numberOfWords = compareDoc2Words.length; 

 

 

// for each word 

for ( var i = 0; i < numberOfWords; i++) 

    var currentDoc1Word = compareDoc1Words

    var currentDoc2Word = compareDoc2Words

 

 

     // get the word 

    var currentDoc1Contents = currentDoc1Word.contents; 

    var currentDoc2Contents = currentDoc2Word.contents; 

 

 

    //get the font style 

    var currentDoc1FontStyle = currentDoc1Word.fontStyle; 

    var currentDoc2FontStyle = currentDoc2Word.fontStyle; 

 

 

    //get the previous Word Location 

    var previousWordLocation = i -1; 

    var previousWord = compareDoc1Words[previousWordLocation]; 

    var previousString = previousWord; 

 

 

    //get the next Word Location 

    var nextWordLocation = i + 1; 

    var nextWord = compareDoc1Words[nextWordLocation]; 

    var nextString = nextWord; 

 

 

    // as we are only looking for italics 

    if ( currentDoc1FontStyle === "Italic") 

    { 

        if ( ! ( ( currentDoc1Contents === currentDoc2Contents ) && ( currentDoc1FontStyle === currentDoc2FontStyle))) 

        { 

            if ( previousString !== undefined || nextString !== undefined){ 

                alert ( "Unmatched italics in: " + previousString.contents + " " + currentDoc1Contents + " " + nextString.contents); // report a fail in whichever makes most sense for you. 

            } 

            if ( previousString === undefined){ 

                alert("Unmatched italics in " + currentDoc1Contents + " " + nextString.contents); 

            }

            if ( nextString === undefined){ 

                alert("Unmatched italics in: " + previousString.contents + " " + currentDoc1Contents); 

            } 

            else{

                alert("Unmatched italics in the word: " + currentDoc1Contents); 

            } 

    } 

         

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
Engaged ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

I was also testing this, but same problem:

if (previousString !== undefined || nextString !== undefined){

                alert ( "Unmatched italics in: " + previousString.contents + " " + currentDoc1Contents + " " + nextString.contents); // report a fail in whichever makes most sense for you.

            }

            if (previousString === undefined && nextString !== undefined){

                alert("Unmatched italics in " + currentDoc1Contents + " " + nextString.contents);

            }

            if (previousString !== undefined && nextString === undefined){

                alert("Unmatched italics in: " + previousString.contents + " " + currentDoc1Contents);

            }

            else{

                alert("Unmatched italics in the word: " + currentDoc1Contents);

            }

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
Engaged ,
Jun 15, 2018 Jun 15, 2018

Copy link to clipboard

Copied

LATEST

here the solution, thanks to everyone for the help.

DOWNLOAD THE FILES

Download

OTHER SIMILAR SCRIPT TO COMPARE TEXT

Download

THE SCRIPT

// get documents to compare

$.writeln();

var myDocs= app.documents; 

var compareDoc1 = myDocs.itemByName ("Original.indd"); 

var compareDoc2 = myDocs.itemByName ("Typeset.indd"); 

 

// get all the stories 

var compareDoc1Stories = compareDoc1.stories.everyItem(); 

var compareDoc2Stories = compareDoc2.stories.everyItem(); 

 

 

// get all the words 

var compareDoc1Words = compareDoc1Stories.words.everyItem().getElements(); 

var compareDoc2Words = compareDoc2Stories.words.everyItem().getElements(); 

var numberOfWords = compareDoc1Words.length; 

 

 

// incase they have differnet lengths, use the shorter one to make sure we don't access areas we are not allowed to be. 

if ( compareDoc2Words.length < numberOfWords ) 

    numberOfWords = compareDoc2Words.length; 

 

 

// for each word 

for ( var i = 0; i < numberOfWords; i++) 

    var currentDoc1Word = compareDoc1Words

    var currentDoc2Word = compareDoc2Words

 

 

     // get the word 

    var currentDoc1Contents = currentDoc1Word.contents; 

    var currentDoc2Contents = currentDoc2Word.contents; 

 

 

    //get the font style 

    var currentDoc1FontStyle = currentDoc1Word.fontStyle; 

    var currentDoc2FontStyle = currentDoc2Word.fontStyle; 

 

 

    //get the previous Word Location 

    var previousWordLocation = i -1; 

    var previousWord = compareDoc1Words[previousWordLocation]; 

    var previousString = previousWord; 

 

 

    //get the next Word Location 

    var nextWordLocation = i + 1; 

    var nextWord = compareDoc1Words[nextWordLocation]; 

    var nextString = nextWord; 

 

 

    // as we are only looking for italics 

    if ( currentDoc1FontStyle === "Italic") 

    { 

        if ( ! ( ( currentDoc1Word === currentDoc2Word ) && ( currentDoc1FontStyle === currentDoc2FontStyle))) 

        { 

            if (previousString !== undefined){ 

                alert ( "Unmatched italics in: " + previousString.contents + " " + currentDoc1Contents + " " + nextString.contents); // report a fail in whichever makes most sense for you. 

            } 

    } 

         

QUICK VIEW

01.png

02.png

03.png

04.png

06.png

07.png

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