Skip to main content
Bedazzled532
Inspiring
August 18, 2023
Answered

How to automatically highlight Justification Alternate words

  • August 18, 2023
  • 9 replies
  • 6667 views

Hi
Is there a way to highlight a word with color through character styles when justification alternate words are substituted by Indesign, automatically ?

In the image I have attached two lines. The one which is black in color is normal justificaiton or justification has been disabled in paragraph style.

The second line, red in color is the same text but Justification Alternate (Naskh) has been enabled in Justification section in paragraph style. Indesign automatically substitute the words if it requires.
My question is when Indesign substitutes a word, is there a way to highlight them ? I know that it can be done manually through character styles, but that is a lot of work. GREP, Script or any other method in Indesign ?
Thanks

This topic has been closed for replies.
Correct answer Peter Kahrel

An additional clarification: you can find all words that have just alt applied, and you can find the width of those words (using horizontal offset, as you did in your script), but that doesn't tell you whether an alternate was in fact used. 

9 replies

Community Expert
August 22, 2023

That's bad. I mentioned earlier that it could be a bug in the composer, but since I used the same composer (even though my installed ID is the standard English one) that's not likely to be the case. It may be a bug in the ME version of InDesign. Anyway, it works for me, but not for you. I'm afraid I have no other ideas to offer.

 

You can submit a bug report at https://indesign.uservoice.com. Include the script, your file (as the result) and the screenshot I sent (as the expected result).

Community Expert
August 21, 2023

That's strange. If I take your test_jalt.indd and run the script, it highlights various words -- though not all, some because of edge cases (see below).

 

But that document has various overrides, in some places those overrides disable otfJustificationAlternate. When you remove those overrides you get this:

 

Then when I run the (updated) script I get this:

So it gets some words (the green ones), but not all (those remaining red). I've no idea why. If you flip just alt on those red words nothing happens. So although InDesign flagged them, no alternates were used for them. Maybe it's a bug, I don't know.  The world-ready composers are known to be buggy. Changing the composer to the WR paragraph composer (you use the line composer) makes no difference.

 

Now for the updated script. Checking just the endHorizontalOffsets of the words before and after changing just alt produces false negatives for words at the end of a line. So you have to look at the length of words, not just where they end:

 

myWords = app.activeDocument.stories.everyItem()
  .words.everyItem().getElements();

for (i=0;i<myWords.length;i++) {
  if (!myWords[i].otfJustificationAlternate) {
    continue;
  }
  w1 = myWords[i].endHorizontalOffset - myWords[i].horizontalOffset;
  myWords[i].otfJustificationAlternate = false;
  w2 = myWords[i].endHorizontalOffset - myWords[i].horizontalOffset;
  if (w1 != w2) {
    myWords[i].fillColor = "green";
  }
  myWords[i].otfJustificationAlternate = true;
}

 

 

Robert at ID-Tasker
Brainiac
August 21, 2023

Exactly, values of the HorizontalOffset shouldn't be taken literally - distance between them should be compared.

 

Community Expert
August 21, 2023

You should leave the paragraph justification alone. Instead, use each word's otfJustificationAlternate property. Also, you can get the document's words in one go:

 

 

 

myWords = app.activeDocument.stories.everyItem()
  .words.everyItem().getElements();

for (i=0;i<myWords.length;i++) {
  if (!myWords[i].otfJustificationAlternate) {
    continue;
  }
  hfb = myWords[i].endHorizontalOffset;
  myWords[i].otfJustificationAlternate = false;
  hfa = myWords[i].endHorizontalOffset;
  if (hfb < hfa) {
    myWords[i].fillColor ="green";
  }
  myWords[i].otfJustificationAlternate = true;
}

 

 

 

(This one ignores footnotes and tables.)

Bedazzled532
Inspiring
August 21, 2023

@Peter Kahrel First of all, thank you so much for this wonderful script.

Unfortunately, I still do not see any change in color in my text. I am attaching a screenshot. 

What am I doing wrong ?

Thanks

Note: I am not manually changing to justification alternate. I am leaving it on paragraph style. I have attached a screenshot of paragraph style also.

Community Expert
August 21, 2023

I tried that but it didn't work.

 

What did you try? There have been numerous suggestions by now. @Robert at ID-Tasker suggested someting in the first reply in this post, there were some other suggestions, and what I came up with is basically an explanation of Robert's rather compact suggestion.

Bedazzled532
Inspiring
August 21, 2023

Here is the code which I tried:

var doc = app.activeDocument;
var myParas = doc.stories.everyItem().paragraphs.everyItem().getElements();
myWords= myParas[0].words;
 
var myPage = doc.pages.item(0);
var myStory = myPage.textFrames.item(0).parentStory;
 
for (i=0;i<myWords.length;i++){
 
myWords[i].paragraphJustification = ParagraphJustificationOptions.DEFAULT_JUSTIFICATION;
//myStory.paragraphJustification = ParagraphJustificationOptions.DEFAULT_JUSTIFICATION;
hfb = myWords[i].endHorizontalOffset;
myWords[i].paragraphJustification = ParagraphJustificationOptions.NASKH_KASHIDA_JUSTIFICATION;
//myStory.paragraphJustification = ParagraphJustificationOptions.NASKH_JUSTIFICATION;
hfa = myWords[i].endHorizontalOffset;
 
 
if (hfb < hfa)
myWords[i].fillColor ="green";
}
 
Nothing changed.
Community Expert
August 20, 2023

It can be done with a script, though it'll be horribly slow:

 

Find all words that have just alt set. Then with each word:

– take its width

– disable just alt

– take the word's width again

 

If the two widths are the same (or differ by half a point or less to account for rounding differences and other minor inaccuracies) then the word is not an alternate.

 

Then re-enable just alt on the word.

 

The problem, of course, is that all that en-/re-enabling can cause reflow. You can't control that. The results should be compared carefully.

 

Brainiac
August 20, 2023

It has been fun thnking about this problem. It is a shame that there is not an efficient scrpting solution.

 

If it were a thing that was in demand, I would be happy to write the PlugIn. 

Peter KahrelCorrect answer
Community Expert
August 20, 2023

An additional clarification: you can find all words that have just alt applied, and you can find the width of those words (using horizontal offset, as you did in your script), but that doesn't tell you whether an alternate was in fact used. 

Brainiac
August 20, 2023

Hello Peter,

 

I believe that would be possible with a PlugIn. You would access the composer and mark the text accordingly. Not a trivial task. 

 

P.

Community Expert
August 20, 2023

There are all kinds of challenges. First, in your sample text, just. alt. is applied to some words but also to phrases, parts of sentences. To see where just alt was applied, run this one-liner to set just alt in your Find/Change window (from Pickory's script):

app.findTextPreferences.otfJustificationAlternate = true;

Now search the document: each instance of just alt will be highlighted in succession. When you apply highlighting you see this:

 

 

Second, even if just. alt. was applied to a word doesn't mean that the alternates will actually be used: they may not be necessary for some words.

 

To see what difference the use of just alt makes, copy the frame on p. 1, move it to the left out of the way so that the duplicate sits next to the original. Then remove all just alt from the duplicated frame. Run another one-liner to prime the F/C window:

app.changeTextPreferences.otfJustificationAlternate = false;

 Select the duplicated story, then set the F/C window to search in the story only, and click Change All.

 

You can already see the differences. You can then move the duplicated frame back over the original and the differences become even clearer:

 

Bedazzled532
Inspiring
August 20, 2023

@Peter Kahrel Wow....thats a great explanation. 

Thank you so much Peter. 

As always, you have been of great help.

 

Brainiac
August 18, 2023

Hello,

Where do you set 'Justification Alternate (Naskh) '

Would you have a sample document that I could look at.

P.

 

Edited to say:

This looks like it is an attribute added to the text. It would be possible to detect the attribute and highlight from an PlugIn. Or, even better, if the attribute is a style override you could switch on style override highlighter.

Bedazzled532
Inspiring
August 18, 2023
Hi
Thanks for the reply.

I am attaching an image where you can find the option of Justification
Alternate.

The document is in Arabic and it requires an Arabic font with Justification
Alternate capabilities.

Justification Alternates do not work on all the fonts. If a Font developer
programs JALT table with extra glyphs, then only it works.
Bedazzled532
Inspiring
August 20, 2023

After you change "1"to" j" - it should be pretty straightforward - you need to save info about HorizontalOffset before and after each found text, temporarily turn off this substituting option, compare new HorizontalOffset values, set  substituting option back on. 

 

Or you could save info for all of them to an array, turn off the option for the whole text and then compare and then turn it back on. 

 


I ran this script but nothing happened.

 

app.findTextPreferences = null;

app.findTextPreferences.otfJustificationAlternate = true;

 

var found = app.activeDocument.findText ();

for ( var j = 0; j < found.length; j++ )

found[j].fillColor = "green";

 

I even selected the text and ran the script again but no change.

Robert at ID-Tasker
Brainiac
August 18, 2023

Script could compare HorizontalOffset of the InsertionPoints before and after the substituted Character - but script would need access to the "original" text.