Copy link to clipboard
Copied
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
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.
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
@Peter Kahrel Wow....thats a great explanation.
Thank you so much Peter.
As always, you have been of great help.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
> 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.
Copy link to clipboard
Copied
Here is the code which I tried:
Copy link to clipboard
Copied
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.)
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
Exactly, values of the HorizontalOffset shouldn't be taken literally - distance between them should be compared.
Copy link to clipboard
Copied
@Peter Kahrel, as you are using Words collection, I think there is one more thing to consider - when the word has been hyphenated - as long as it can occur in this / those languages?
Copy link to clipboard
Copied
Good point. Let's hope Arabic doesn't hyphenate (I think it doesn't).
Copy link to clipboard
Copied
Thanks for the updated script. Unfortunately there must be something wrong at my end. This script also does not change any color.
Arabic does not hyphenate.
Copy link to clipboard
Copied
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).