Show Local Formatting in InDesign CS4
May 10, 2010 | Snippets | en | fr

The Document Object Model of the InDesign CS4 scripting layer provides an obscure property, TextPreference.enableStylePreviewMode, which allows to show “style overrides” as red strikeouts or paragraph vertical bars in normal screen mode (as illustrated above). After hours of investigation, I have not figured out how to access this feature from the InDesign user interface. Maybe I'm wrong, but it looks like this way of reporting local formatting is only available through scripting. (Please add a comment if I missed the obvious!)
Anyway this is a great feature. Usually we detect an override by selecting a target text range and checking the style name in the Paragraph Styles and/or Character Styles panel(s). A plus sign (+) next to the style name indicates that a local formatting overrides the style's attributes. (See “Override character and paragraph styles” in the InDesign online help.) But that approach is useless if you need a global overview of the style gaps after importing from Word, or similar operations.
(Note: you can define a Preflight Profile to report style overrides.)
Now to the script
ShowHideLocalFormatting.js is the shortest script I've ever written. It simply toggles between the normal view mode and our special “display style overrides” mode:
if ( app.documents.length && app.activeDocument.textPreferences.enableStylePreviewMode^= 1 && app.layoutWindows.length && app.activeWindow.constructor==LayoutWindow ) { app.activeWindow.screenMode = ScreenModeOptions.previewOff; // UPDATE 05/25/10 - Thanks to ptruskier app.activeWindow.overprintPreview = false; }
The above code contains extra stuff to prevent the script from contextual errors, anyway the only important instruction is:
app.activeDocument.textPreferences.enableStylePreviewMode^= 1;
which switches the enableStylePreviewMode flag.
Here is a typical result:
If it turns out that this display feature is not available natively in InDesign CS4, I strongly encourage you to attach a keyboard shortcut to the script!

Comments
Bonjour Marc,
Il est "marrant" ce script ! En tout cas, je le vois déjà parmi mes scripts utilisés au quotidien.
Bref "Un petit script pour Marc, un grand pas pour les indesigners" !
Merci
Merci Laurent.
Le plus étonnant de l'histoire, c'est qu'apparemment on ne trouve pas ce truc directement dans ID ! (Mais j'attends les autres commentaires pour confirmer.) La seule chose dont je sois sûr, c'est que l'attribut utilisé dans mon script n'existait pas avant CS4.
@+
Marc
Pas mal du tout !!!!!
Ben alors, mes commentaires se barrent maintenant ! J'ai pas dû appuyer sur envoyer :-\
Bref, je disais bravo pour le script, son utilité, la concision de l'écriture et la belle exploration du DOM.
Je te questionnais aussi sur la signification du ^= .
A+ Loic
Merci à tous deux.
@Loic
Le ^ (accent circonflexe) correspond à l'opérateur XOR. Quand tu fais un "XOR 1" sur un booléen, en JavaScript, cela commute la valeur. Plus exactement, JS transtype TRUE en 1 (ou FALSE en 0) et fait l'opération, c-à-d que l'on a respectivement :
TRUE ^ 1 === 0
FALSE ^ 1 === 1
Ensuite, l'écriture ^= est un code condensé qui fonctionne de la même façon que +=. Autrement dit, une instruction de la forme :
X ^= Y;
signifie:
X = X ^ Y;
Par conséquent, si B est un booléen, le code :
B ^= 1;
revient à affecter à B son complémentaire logique exprimé sous la forme 0 ou 1.
Par chance, la propriété "enableStylePreviewMode" que j'ai besoin de switcher accepte de recevoir 0 ou 1 (en lieu de FALSE ou TRUE), donc l'opération :
(...).enableStylePreviewMode ^= 1;
inverse effectivement la valeur de la propriété.
Pourquoi un détour si compliqué ? Pour éviter d'écrire :
(...).enableStylePreviewMode = !(...).enableStylePreviewMode;
ce qui solliciterait deux fois le DOM en parcourant à deux reprises la chaîne prototypée app.activeDocument.textPreferences.enableStylePreviewMode.
Il faut garder à l'esprit que chaque fois qu'on navigue dans le proto d'un objet, on perd du temps. Accessoirement, l'écriture obtenue est beaucoup plus compacte, sans réclamer l'introduction d'une variable.
@+
Marc
what a lovely Script Marc!
I have just tested it in CS5 as well, and it seems to work OK in that version too.
I've added a blog-post to my website about your script. Thank you so much for another great script!
Je te remercie Marc pour l'explication.
Mes collègues ingénieurs m'ont expliqué cela aussi :-)
Deux fois, Marc, pas deux foix :-)
C'est la seule chose que je pige dans tes explications… cela ne va pas loin, je te le concède :-)
@ Cari
Thanks a lot, this is good news for CS5 users. The link: http://carijansen.com/2010/05/10/st...
@ Jean-Christophe
> C'est la seule chose que je pige dans tes explications [...]
Ouix! Maix qu'est-ce que je feraix sans ton oeil de lynx? (Coquille corrigée, merci.)
Très pratique au quotidien.
Merci pour ce script.
Marc,
Nice discovery. It's not unusual for script methods or properties not to have a UI equivalent. There are even keyboard shortcuts that don't have menu entries: recompose all stories (Ctrl+Alt+/) close all documents (Shift+Ctrl+Alt+W), save all documents (Shift+Ctrl+Alt+S), and probably some more.
Thanks also for the ^ exposé -- didn't know about that one and it looks very useful.
Peter
Wow! Awesome script. Just what I need! Thank you so much!
Thanks all.
@Peter
Wow, cool shortcuts! I never knew you could close all documents with the keyboard.
> It's not unusual for script methods or properties
> not to have a UI equivalent.
Yes. In this chapter we also could mention the “InDesign script for Balance Ragged Lines” by Keith Gilbert: http://bit.ly/6TwhKE
I would like to make a compilation of these "under the hood" features...
And all the right-to-left stuff of course.
>I would like to make a compilation of these "under the hood" features...
Don't let anybody stop you ;)
@Marc: very cool!
One additional feature "under the hood": different column gap widths on one single page by manipulating the marginPreferences.columnsPositions-array.
Thanks! This is a terrific finding. I only wish it also worked in CS3. Note that in addition to turning preview mode off, you must also ensure that Overprint Preview is turned off.
Hi Mark how are you doing?
It is a very useful script thanks a lot.
I'll mention it in my blog, if you don't mind?
@ ptruskier
> you must also ensure that Overprint Preview
> is turned off.
You are perfectly right! I've updated the code. Thanks for your comment.
@ Mohammed
> I'll mention it in my blog...
Thank you too ;-)
Direct link to the thread: http://indesignyat.webatu.com/?p=20...
very cool finding!
maybe there is no ui equivalent because of some bugs in the feature? probably only adobe knows.
anyway my first testing worked perfect.
Marc,
Here is another unknown feature: watermarks:
http://www.indesign-faq.de/de/wasse...
Peter
Salut Marc
très pratique en effet,
Peux-tu dire si il est possible de changer la couleur de biffure que ton script active ? ou est-ce encore un mystère des ingénieur d'Adobe ?
++
Pas possible à ma connaissance. Les voies de l'ingénieur (Adobe) sont impénétrables ;-)
Thank you so much.
it´s just the one I was looking for.
works perfect in CS5