The Hidden Way to Highlight Styles
May 10, 2012 | StyLighter | en | fr
[Addendum, 06/04/2012] — I must credit Jongware for his original discovery of previewColor
(the trick behind StyLighter). Indeed, my irreplaceable colleague had already detected and discussed this hidden property in the InDesign Scripting Forum. See also this all-important note from Ashley Mitchell, who “was part of the InDesign team that implemented this feature back in CS4.”
Two years ago we discovered a secret key that allows to magically highlight paragraph and/or character style overrides in InDesign. This was good news for ePUB designers and generally those InDesign users who aspire to the cleanest document structure and formatting. However, we did not go through with the demonstration!
In essence—and to make a long story short!—InDesign CS4 and later offers a very special Preview Mode dedicated to styles. This mode is only available and disclosable by a script command: TextPreference.enableStylePreviewMode = true
. I don't know why InDesign developers decided to hide this feature (which by the way remains secret in CS6 and CC) but there are good reasons to believe that the intended functionality has been only partially implemented so far, if not aborted. Digging that topic, I hit on another obscure property you've probably never heard of until today: previewColor
, which regards ParagraphStyle
and CharacterStyle
objects. Also available since CS4, this parameter expects a UIColors
enum (or a RGB triplet, theoretically!) which has no visible effect… unless the Style Preview mode is enabled!
Can you guess what follows?
Ta-da! I swear that the above screenshot is not based on any colored underline. Instead, I applied a specific previewColor
value to each paragraph or character style I wanted to highlight. Note that red lines (character styles) and red vertical rules (paragraph styles) still mark all the overrides. So we now see the Style Preview Mode feature in all its magnitude.
StyLighter, the Style Preview Manager
From there, my whole problem was to fully expose this magic feature in the InDesign UI. Confident, I started by designing a nice script interface that provides a subtle control of each color assignment and allows the user to selectively enable / disable preview on specific styles—while storing the last used settings.
This looked very promising, except that some colors were improperly assigned, or simply ignored! I finally figured out, on the one hand, that the previewColor
property only supports the restricted set of UIColors
—contrary to what the DOM claims arbitrary [R,G,B] triplets are not implemented—and, secondly, UI color assignments are out of sync since CS5. For example, UIColors.CYAN
is rendered as UIColors.VIOLET
in InDesign CS5, CS5.5 and CS6. Based on various tests, it appears that a shift of 8 items is systematically applied, but under some circumstances such as IDML export/re-import, the wrong offset falls to 2!
I tried to get around all these technical complications as much as possible, but the resulting script is de facto doomed to somewhat brittle. I hope this script can still be of some service. StyLighter has been roughly tested in InDesign CS4, CS5+, CS6 (Mac and Win). Give it a try!
• See also: Show Local Formatting in InDesign CS4/CS5
Comments
Great script!! Thanks for sharing
Excellent Marc.
Will it be a menu item, or do you leave this opportunity to Gabe ?
Je n'ose y croire ! Merci beaucoup pour tout ce travail d'excavation.
Encore bravo pour cette réalisation que je pensais pouvoir détourner aussitôt pour simuler le surlignement. Est-ce possible de rendre visible la prévisualisation dans un PDF ?
@ profeivan
Hi Iván. Glad to hear from you. Thanks for thanking ;-)
@ fr
> Will it be a menu item, or do you
> leave this opportunity to Gabe ?
Franck, je te sens d'humeur taquine sur ce coup-là…
@ -ep-
> Je n'ose y croire […]
Magie d'InDesign : on n'en a jamais fait le tour. (Ce que j'aime dans les gloses d'Indiscripts, c'est qu'on y lit sans éternuer le mot « excavation ».)
@ Laurent
> Est-ce possible de rendre visible la
> prévisualisation dans un PDF ?
À mon avis, même pas en rêve ! On est vraiment ici sur une modalité d'APERÇU qui ne concerne d'aucune façon le contenu effectif du document. D'ailleurs, c'est tout l'avantage de ce dispositif dans InDesign. On peut enfin contrôler visuellement la distribution des styles dans la composition sans les toucher physiquement. Exemples typiques : voir si on a laissé traîner du « [Paragraphe standard] », faire ressortir les appels de notes (s'ils sont stylés !), etc.
Concernant ta quête — rendre visible les surlignages dans un PDF de contrôle —, il me semble que cela vise une problématique toute différente. En général, l'objectif est alors pour le maquettiste d'attirer l'attention de son client sur tels et tels élements problématiques. Pour moi, cela correspond sémantiquement à un style dédié (que j'appelle le style « Stabilo ») basé sur un surlignage physique, bien qu'il soit détruit en fin de parcours. Le problème qui peut se poser pour le style Stabilo, c'est qu'il écrase d'autres styles de caractères. Un vieux débat entre nous, ça, Laurent… ;-)
@+
Marc
Très beau travail, très utile, comme souvent !
Merci beaucoup !
Thank you for that script, Marc!
One addition to that script could be an option where you can set back the previewColor of a paragraph style or a character style to "Nothing".
I realised that one could do that by applying a RGB triplet like that:
app.documents[0].paragraphStyles.itemByName("ParagraphStyleName").previewColor = [0,0,0];
Instead of applying the color "Black"(RGB = 0,0,0), like what I would think in the first place, the previewColor is set back to "Nothing". In fact you could try any triplet and you will get "Nothing" for the previewColor.
Another observation with that approach:
If you try to add an array of FOUR colors like [0,0,0,0] by mishap, InDesign will crash immediately…
@ Uwe
> One addition to that script could be an option where you can set back
> the previewColor of a paragraph style or a character style to "Nothing".
Good point. Technically, this is exactly what the script does when you select a style in the listbox and press the "Preview OFF" icon button. The previewColor is then set back to nothing, but the disabled color is saved in a label so that the user can easily reactivate that color. That's why I didn't implement a [None] swatch, but you're probably right that the user will expect such option.
> I realised that one could do that by applying a RGB triplet like that:
> [...] previewColor = [0,0,0];
> Instead of applying the color "Black" (RGB = 0,0,0), like what I would
> think in the first place, the previewColor is set back to "Nothing".
As I said in the article, assigning an RGB triplet to previewColor does not work at all, and IMHO we shouldn't make any assumption on how InDesign internally deals with such data type. The regular way to turn back the previewColor to nothing is:
myStyle.previewColor = NothingEnum.NOTHING;
@+
Marc
Et hop Marc a encore trouvé la solution qui nous manquait...!! Je me demandais la semaine passée s'il y avait un moyen d'identifier les modifs locales des styles... et puis, j'ai eu l'idée d'aller voir votre site, Marc... et j'en suis toujours aussi retourné...! ,-) Longue vie...
Nico
Awesome Marc. Thanks!
Thanks! I've been wishing for this functionality since at least CS2. I have been using this script on chapters in a book over the last few days and it has found a few improperly handled changes made by the editors. Changes that I probably would not have noticed otherwise.
I have a few questions. I am not a scripter, but I'm wondering if these are things that I could add or alter in the script without breaking it, or that could be options in future versions:
1. Is there a way to have "Activate the preview mode" checked by default the first time it is run in a given document? I'm only going to invoke the script if I want to see the overrides and styles.
2. Is there a way to tell it that a certain style should always be highlighted by default, in the current and any future document, instead of having to select it and choose a color every time I run the script in a new document? (For me this is the "Normal" paragraph style that is sometimes present after importing from Word, and any other styles that came in during import.)
3. On a related note, is there a way that it can tell which styles are imported (i.e., the ones that have the little floppy disk icon) and automatically highlight them anywhere they are used?
4. Finally, can the weight of the red line showing character style overrides be changed? I would like it to be much thicker so I can spot very small instances even if I'm zoomed out. It would also be cool to be able to assign it a different color if, for example, there is red text in the document.
Like I said: I love this script. I'm not a scripter, so I haven't opened it in an editor to see how it works, but I am tempted.
Tank you. Great script.
Thank you very much. I used to use an improvised paragraph rule to do this sort of thing sometimes, but not only is this much better, it also allows you to do it on the character level as well.
Very nice script! However, I noticed that if you create a Character Style or Paragraph Style that has a name that places it alphabetically before "<Style Overrides>" (such as "80% Text Size" or ".small") that this will bump <Style Overrides> out of its top spot on the list inside the dialog and <Style Overrides> will no longer have the lock icon next to it.
@ ashleymitchell
Thank you for 'highlighting' that bug!
Fixed in StyLighter 1.2b now available.
@+
Marc
Laurent Tournier — http://indigrep.com — me signale un biais inattendu de StyLighter quant au traitement des notes de bas de page :
« Comme tu peux le voir, précise Laurent, le style de paragraphe “note” prend la couleur du style de paragraphe “texte” [bien qu'ils n'aient pas de lien de parenté]. J'ai testé sur trois documents différents [InDesign CS4/Mac OS], même résultat. »
Le comportement du « Style Preview Mode » d'InDesign est tout à fait imprévisible dans certains cas, mais StyLighter n'y est pour rien ! Comme je le précise dans mon billet, si cette fonctionnalité n'a pas été « exposée » par les développeurs d'ID, c'est de toute évidence parce qu'elle n'était pas finalisée.
Le cas des notes de bas de page est symptomatique à cet égard. Affecter une couleur d'aperçu à un style de paragraphe appliqué aux notes conduit à des résultats volontiers surprenants. À première vue, les notes semblent « hériter » de la couleur d'aperçu du style de paragraphe parent (c.-à-d. le paragraphe qui contient l'appel de note) au mépris de la couleur d'aperçu spécifiquement dédié au style de note.
Mais j'ai observé lors de différents tests des choses plus amusantes. Sous certaines conditions — qui restent à élucider — InDesign peut aussi MIXER les couleurs d'aperçu du style appelant et du style de note. Par exemple, un vert pomme et un jaune vont donner une nuance chocolatée ! (Je n'ai pas pu identifier la loi qui régit exactement cette interpolation, mais je suspecte qu'elle est basée sur le système de coordonnées HSV…)
@+
Marc
Hello!
Thank you for this gem of a script! Just made my life 10 times easier.
One question:
Is there a way to disable the overriden highlight and enable just the custom styles highlight?
@ Vlad
Thanks for your support :)
> Is there a way to disable the overriden highlight and
> enable just the custom styles highlight?
Unfortunately, both features are inseparable as the "Style Preview Mode" automatically makes overrides visible.
@+
Marc
Petite note utile, je ne suis pas sûr qu'il soit fautif, mais j'avais placé le script dans le dossier startup script et il me réclamait d'ouvrir un document en boucle, au démarrage, paralysant inD…
@ Franck
StyLighter n'étant pas un script de démarrage, il est en effet mal avisé de l'installer comme tel ;-)
N. B. — N'oubliez pas que tout script déposé dans un dossier intitulé « startup scripts » — quel que soit au demeurant la position de ce dossier dans l'arborescence des scripts — sera automatiquement exécuté au démarrage d'InDesign. Ainsi, à moins que l'auteur vous y invite expressément, ne posez pas de scripts dans un lieu aussi virulent !
@+
Marc
Dear Marc,
I love working with Stylighter.
But in combination with the WorldReady Composer and bidirectional typesetting (e.g. english – hebrew) it sometimes (but not always) makes InDesign crash - in InDesign CS4 up to InDesign CS6.
Thank you
Martin
Does anyone know how to save settings of the stylighter?
Each time I open a new indd file (a lot of small files)to check it with the stylighter, I have to check the colours again which is teddious.
Some change in the code or usage?
TIA
@ Martin Fischer
Thanks for your feedback. Indeed, there are good reasons to conclude that the Style Preview Mode is not bidi-compliant!
@ Dane
> Each time I open a new indd file (a lot of small files)
> to check it with the stylighter, I have to check the
> colours again which is teddious.
The problem here is that Paragraph/Character Style names are document-dependent, so there is no obvious way to preset stylename-to-color relationships. Unless we implement a kind of database behind the scene…
@+
Marc
I am happy you answered that fast.
"The problem here is that Paragraph/Character Style names are document-dependent, so there is no obvious way to preset stylename-to-color relationships. Unless we implement a kind of database behind the scene…"
In my case or for my needs, the paragraph style names have always the same name, there never appear para stylenames that I do not have in my list. They are assigned to the text inhouse, but not always accuratelly (not all are always used in one file but that does not matter).
So to me that would be great if the name styles would always map to same colours.
Maybe a workaround would be if the script would paste at a defined place in the document a set of all styles (set of paraghaps) in a style list which would aways get the same colour? Afterwards delete all added paragraps...
Or a possibility to type in the code my style names and colours in the code?
Thanks again
I am missing this super script for CC. How to make it compatible?
Is there an update that works with Cloud? Crashes indd.
@ Camilo, Julie
Main CC issues should be solved in StyLighter 1.4 :)
@+
Marc
Je découvre, j'essaie, et effectivement quelques glissements de couleurs ont lieu : la première couleur verte apparait noire, le jaune apparait vert ;-)
Sinon, c'est super ! très utile !
bravo !!!
PS : un truc top serait qu'on puisse avoir encore la main sur le texte sans avoir à fermer et rouvrir le script pour voir nos corrections progresser
@ victor
> effectivement quelques glissements de couleurs ont lieu
Avez-vous essayé d'appliquer le patch (bouton « Corriger les couleurs… ») ?
@+
Marc