Skip navigation
Currently Being Moderated

Preserve Local Formatting script and CS4

May 7, 2009 7:41 AM

Unfortunately, Dave Saunders' amazing PreserveLocalFormatting.jsx script (that changes local formatting to character styles) doesn't work under InDesign CS4. I've tried running it both as-is and in the compatibility mode (putting it in a folder marked Version 4.0 scripts), and it seems to star to run, but doesn't actually do anything. Anyone more versed in scripts know what might be the trouble?

 

http://indesignsecrets.com/downloads/PreserveLocalFormatting.jsx

 
Replies 1 2 Previous Next
  • Currently Being Moderated
    May 7, 2009 8:14 AM   in reply to mpvrana

    Perhaps even better: my amazing preptext.jsx (http://www.jongware.com/binaries/preptext.zip).

    It runs under CS4 and has a plethora of other formatting combo's that it checks. It also has a progress bar

     
    |
    Mark as:
  • Currently Being Moderated
    May 7, 2009 1:26 PM   in reply to mpvrana

    ad a. You got me there. The script forcibly creates new styles with the exact attributes it should -- i.e., if not "Italic" or "Bold", well, then ... it's "Regular". It's a pain to edit these styles afterwards, and in fact the version I use (daily) doesn't do that any more. Remind me to upload that one instead.

     

    ad b. You got me there. Small scripts can be copied-and-pasted into forum messages, but larger ones cannot be attached to messages. So if I write a larger script, I zip it (to prevent download issues), dump it on my site and post the link here.

    Every now and then I visit Peter Kahrel's scripting pages and think, "When I have the time ..."

     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2009 3:56 AM   in reply to mpvrana

    http://www.jongware.com/binaries/preptext.zip is refreshed to the new version that does not forces every attribute to be set or clear.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 1:23 AM   in reply to mpvrana

    Can you tell me what the script exactly do and how to use it ?

    I suspect i need it but there it lacks some infos…

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 2:38 AM   in reply to alexgodlex

    The script searches for text formatted with Bold, Italic, Underline, Superscript, Subscript and Small Capitals and replaces it with a character style with an appropriate name. Replacing manual formatting with a character style has significant advantages, the most important ones are that you no longer can accidently remove them (when overriding paragraph attributes), and afterwards, you can change the styles at will.

     

    There are a few points you must keep in mind:

    1. The script searches for font styles named "Bold" and "Italic". If you happen to use a font where these are called "Semibold", "Black" or "65 Bold" or "Slanted", "Oblique" or "46 Light Italic" it will not find these. If you need styles applied to these attributes, do so by hand.
    2. The script searches for attributes such as "superscript", "subscript", "small capitals". If small caps are faked in the document with capitals in a smaller font, the script will not find them. If superscript or subscript are faked in the document with a smaller font size and some baseline shift, the script will not find them.
    3. Word has a lot of different underline styles; InDesign only has one. It is possible to search specifically for 'double underline', 'dotted underline', etc. but you have to do this by hand. The script picks up any and all kinds of underline as one and the same -- Underline. (See also #5 below.)
    4. The script creates new character styles as needed; these are all independent, not based-upon eachother. If you have 3 styles with 'Bold' in them and you want to change the bold font to semi-bold, you will have to do that for each separate style that contains Bold.
    5. Any formatting other than those mentioned is not preserved or changed by this script. If you suspect your document has other types of formatting you want to preserve, replace these by hand with character styles. The script is hardcoded to ignore text that already has a character style,  something you can use in your advantage (when done properly).

     

    Read the ID Help or http://indesignsecrets.com/how-to-install-scripts-in-indesign.php for instructions on how to install and use scripts.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 2:44 AM   in reply to [Jongware]

    Ok Thanks, it works very well. Now let me ask a dumb question : Why i would want to do that ?

     

    I mean if i don't so that i will loose the italics for exemple ?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 2:52 AM   in reply to alexgodlex

    Ever seen a paragraph style name with a '+' added to it? That's an indication the paragraph contains 'local formatting' somewhere -- a manual override of the formatting in the paragraph style. If you select some text and apply "Italic", well, that's a manual override -- the font in the paragraph style specifies "Regular".

     

    The problem with manual overrides is that they can disappear without warning. Try this: select some text in your document and underline it -- the paragraph style name will gain a '+'. Alt+click the paragraph style ("Apply Removing Overrides") -- the underline disappears. Or: change the paragraph style, adding 'underlined' to it. Press "OK" (all paragraphs in that style will be underlined), then change the style back, removing the Underline. Your manually applied underline will be gone.

     

    If you never had any of these problems -- or you don't think of it as a problem -- you don't really need this script...

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 3:26 AM   in reply to alexgodlex

    I have another question : if i use 2 fonts and they don't use the same name for italics :

    — italic

    — book italic

     

    It seems the script is lost with it, what can i do about it ?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 3:27 AM   in reply to alexgodlex

    That was #1 of my 5-point "Watchit" list.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 3:35 AM   in reply to [Jongware]

    Yes sorry…

     

    So it's not possible to update the script and make it create 2 styles i guess ?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 3:52 AM   in reply to alexgodlex

    The main point is that the script cannot know in advance what the italic fonts are called.

     

    I usually use 'Find Font' on new documents, and if I see quirky bold or italics, I just replace them immediately with a regular "Times New Roman Bold" and "Italic" so I'm sure the script will pick them up.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 3:56 AM   in reply to [Jongware]

    Maybe is should try that…

     

    Another way to do that would be to change the name of the font 'book italic' to 'italic' but i don't know how to do that, should be possible… ?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 4:46 AM   in reply to alexgodlex

    Yes, that's exactly what I do with "Find Font".

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 5:08 AM   in reply to [Jongware]

    No i mean change something in the font file that would change the name of the italics.

    But i don't know where is that code and how to change that…

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 5:10 AM   in reply to [Jongware]

    + all the Book Italics are used in notes here in my document, and it seems you can't search in notes…

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 5:47 AM   in reply to alexgodlex

    You lost me there. You don't change the font itself, you change the font used in your document. Then you run the script. It tags all italicized text with one unique character style for "Italics". If you don't have a regular italic in the font used, all you have to do is change the character style.

     

    It sounds as if the text you work on has already been formatted. Running scripts that mess with texts over "almost finished" texts may have been an invitation to disaster ...

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 6:26 AM   in reply to [Jongware]

    Let be clear.

     

    I have a final text, with styles, in a word document.

    In indesign i use one font for the main text, it have a real italic, called italic.

    I use another font for footnotes, the font have italics too but its called 'book italic'.

     

    So i run you your script, it works for the main text.

    But for the footnotes i doesn't work, tried to apply an 'italic' style when the italic is called 'book italic'…

     

    I can't fixe that seaching for italics on a specific font and change it for book italic for 1 reason :

    — you can't seach in footnotes (it seems)

     

    So i thought if i change the name 'book italic' for 'italic' in the OTF file, it would work.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 6:52 AM   in reply to alexgodlex

    Aha -- your footnote font differs! Yes -- sometimes I have to mix two fonts that apply different naming schedules, and in that case the script straightens things out that should stay crooked

     

    You can make a new character style named "Book Italic" (with its style set to the correct italic font). Then do a search and replace; search for "Formatting" -> Character Style "Italic" and Paragraph Style "(your footnote paragraph style). Replace with Character Style "Book Italic".

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 7:07 AM   in reply to [Jongware]

    Thanks for the tip i'm gonna try that.

     

    PS. Offtopic but… do you know any word count script for Indesign ?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 7:45 AM   in reply to alexgodlex

    That, unfortunately, depends on your definition of a word

     

    If you click your text cursor in a text frame, InDesign shows you the number of "Words" (and Characters, Lines and Paragraphs as well) in the Info panel.

    This thread http://forums.adobe.com/message/2151036#2151036 shows an alternative way of counting.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 5, 2009 7:47 AM   in reply to [Jongware]

    I made the search thing and it worked very well, thanks a lot for your help !

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2009 1:46 AM   in reply to alexgodlex

    It only occurred to me this morning -- there is no problem at all with 'other italics'!

     

    Simply first replace "Book Italic" with a custom character style, and then run the script. The script is smart enough to leave existing character styles alone.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2009 1:58 AM   in reply to [Jongware]

    Sorry but what do you mean by "replace "Book Italic" with a custom character style"

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2009 3:15 AM   in reply to neuelex
    #5. Any formatting other than those mentioned is not preserved or changed by this script. If you suspect your document has other types of formatting you want to preserve, replace these by hand with character styles. The script is hardcoded to ignore text that already has a character style,  something you can use in your advantage (when done properly).

     

    So, in a fresh document (that has no character styles!), you can safely apply a custom character style to the text in the "Book Italic" font.

     

    • Create a new character style for the Book Italic font -- you should not call this style "Italic", obviously!
    • Call up the Find/Change box
    • In Find Formatting, enter the name of your font and "Book Italic" as the font style
    • In Change Formatting, set the character style to the one you created.
    • Check if "Include Footnotes" is on
    • Hit "Replace All"

     

    Then run my script -- it will not change existing character styles.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2009 3:30 AM   in reply to [Jongware]

    Ok i got it

     

    But this is the same as doin what i've done for my document, wich is : doing that AFTER running the script…

    Same results, right ?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2009 5:45 AM   in reply to neuelex

    Yes, but that's because the script did not pick up the 'book italic' in the first place ...

     

    Suppose you have a document with Times Italic and Helvetica Italic, and you want both to be preserved in their own font. Then you would have to change at least one of them to another style before you run the script -- to prevent both fonts get tagged as "Italic".

     

    I have to do this almost every day, so for me it's becoming 2nd nature ...

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 8, 2009 7:03 AM   in reply to [Jongware]

    A super script. How to use it also in foonotes?

     

    A good idea is to apply colours to the character styles. With this the document is very fast tested and subject to other exercises.

     

    Thank you.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 8, 2009 7:46 AM   in reply to mariana pineda

    mariana pineda wrote:


    A super script. How to use it also in foonotes?

     

    Super-script -- also known as "superior"!

     

    It needs nothing special, it already should work just fine in footnotes, as well as in tables. The script searches the entire story. (An important note is that anchored objects contain "their own story" -- it does not work through to these as well.)

     

    Ehm, the 'color' part is not entirely clear. Do you mean you want to see your italics (etc.) also in another color? When the script is finished, you can change the automatically created character styles and add some color to them.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 6, 2010 2:10 PM   in reply to mpvrana

    Jongware's free script is wonderful and a great help to many people. You might also look at the Create Basic Character Styles and Create All Character Styles features in the Blatner Tools plug-in (dtptools.com/bt), along with the Create Paragraph Styles (which can create paragraph styles for you throughout an unstyled document).

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 9:51 AM   in reply to mpvrana

    Is there any possibility to adapt preptext to run on a bunch of files, without first putting the cursor in a text frame? I was thinking in using it with Peter Kahrel's batch script, but this manual step prevents it to work in batch. Thanks for any light you can share on this.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 12:15 PM   in reply to PageLab

    That batch script lets you run a script against documents: check the "Run a script" box and select a script from the dropdown. Use "InDesign" for source and target format. Zip up your files (or copy them to a safe place) before you do anything.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 12:34 PM   in reply to Peter Kahrel

    Thanks for the hint Peter, but I received an error message at the end of script execution for each file I tried to process:

     

    "undefined is not an object (at line 74)"

     

    I tried using preptext with other batch script (Batcher, from Rorohiko), but it didn't work either.

     

    I think it's because preptext needs the cursor inserted in a text frame before execution. Is there any way to automate this manual step?

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 2:43 PM   in reply to PageLab

    If it's true that the script needs some selection, then it could be changed. Jongware would be the one to do that, let's see if he feels like it.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 3:04 PM   in reply to PageLab

    Peter Kahrel wrote:

    If it's true that the script needs some selection, then it could be changed. Jongware would be the one to do that, let's see if he feels like it.`

    Sure.

     

    PageLab wrote:

    I think it's because preptext needs the cursor inserted in a text frame before execution. Is there any way to automate this manual step?

     

    Yep. Follow the next steps carefully.

     

    1. Remove the top braced statement, from "if (app.activeDocument.selection .." to "exit(0); .. }" -- the entire 5 lines. These are the lines that check if the cursor is inside a text frame.

     

    2. Scroll all the way to the bottom of the script. The other line to change is the very final statement (excluding the last two braces; leave those alone, please).

     

    3. Change the line

     

    app.activeDocument.selection[0].parent.changeText (false);
    

     

    to

     

    app.activeDocument.changeText (false);
    

     

    -- i.e., remove "selection[0].parent."

     

    4. Save the script, preferably under a new name.

    5. Run it as usual, through the Script Panel, to see if it does work (you don't need to click the text cursor inside a text frame anymore), and if it does, try it with one of the script batchers.

    6. Sit back with the warm feeling of a job well done.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 3:29 PM   in reply to [Jongware]

    This script has a funny follow-up story. (It's just past the midnite hour here, so gather round for a True story.)

     

    It works by brute force; it searches for every possible combination of font style, underline, and position and some else -- all in all, something like 64 different combinations. And the largest portion of those are bogus. I mean, come on! What was the last time you found a bold italicized, superscripted, underlined text? ... Unfortunately, there always are authors that like everything to stand out as much as possible (in my opinion, completely reversing the intended effect) and so it's not safe to check for any less combo's.

     

    Now InDesign is a strange beast, internally. Text formatting is not implemented, as it was in WordPerfect and still is in HTML, by inserting 'formatting codes' inside running text; rather, text consists of multiple "runs". One run holds just the plain ASCII text. (More precise, 16-bit Unicode text.) Another run holds lengths of paragraph styles -- "the first 10 characters have paragraph style X, the next 24 characters have style Y"; and yet another one per-character formatting: "the first 5 characters are nothing special, then 10 characters are bold, italic, and underlined, then 19 more without anything".

     

    Using scripting, you can easily get access to paragraph styles and individual characters, but also to these so-called Text Style Ranges, and it occurred to me I could use those to build up the list of required New Character Styles. So I wrote a script to loop over each of them, checking if each already had a character style applied to them, and if not, checking if there is an existing style for its extra attributes and creating it if not. Much to my surprise, it's way faster than this version of PrepText. Alas ... it's also way more complete -- too complete, in fact!

     

    There seems to be some internal dispute inside InDesign on whether plain text is called "Regular" or "Roman", something that infrequently is visible in the Paragraph or Character style panel. You may see a certain text has an override, and its style gets a "+". But when you hover your mouse over the style name, it says 'Plain text + "Regular"' -- and that text style already is 'regular'. Alt+clicking clears this 'override', and you see the '+' disappear, but nothing really changes, because, well, the text was Regular and now it's Regular again.

     

    I think (without having any real evidence for that) it's because ID's default font has been "Times Roman" for years, which is internally stored as "family: Times, style: Roman". Apparently, sometimes the affix "Roman" gets replaced in your text with "Regular", and sometimes it does not. For one, I've never seen "Minion Pro Roman"; it seems you always get to see the 'correct' style name after all. Or at least, that's what gets shown in the interface.

     

    Back to the super-complete FastPrepText: it also picks up this nigh-on invisible difference between "Roman" (even if it's visibly called "Regular"!) and "Regular", and much to my dismay, I not only get character styles such as "Superscript" but also "Regular + Superscript", and even "Regular" on its own! The weirdest thing is, you might think a smart fella like me would be able to test the name of the font style before declaring it to be "local formatting". I did check, and in all cases all scripts are confident the style name is, in fact, "Regular" -- right before it seems to decide 'wait it's local formatting anyway', and then it still creates the "Regular" character styles!

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 23, 2013 3:50 AM   in reply to [Jongware]

    Thank a bunch sir, nice and easy! I just had to remove "selection[0].parent." on line 96 too, and it worked great with no cursor inserted!

     

    Now, the batch part worked fine with Rorohiko's Batcher, but it didn't worked with Peter's excellent batch script (it keeps processing the doc over and over, with no error message).

     

    This is really a time saver. Here's the complete adapted preptext script with the code to run flawlessly with Batcher:

     

    //DESCRIPTION: Jongware's PrepText (adapted to run with Batcher, by Rorohiko)
    
    var myMaximumValue = 63;
    var myProgressBarWidth = 384;
    var myIncrement = myMaximumValue/myProgressBarWidth;
    myCreateProgressPanel(myMaximumValue, myProgressBarWidth);
    
    myProgressPanel.myProgressBar.value = 0;
    myCreateProgressPanel(100, 400);
    myProgressPanel.show();
    
    for (b=0; b<2; b++)
    {
         for (i=0; i<2; i++)
         {
              for (s=0; s<2; s++)
              {
                   for (u=0; u<2; u++)
                   {
                   //     Don't process strikeout
                        for (k=0; k<1; k++)
                        {
                             for (c=0; c<3; c++)
                             {
                                  if (b+i+s+u+k+c)
                                  {
                                       myProgressPanel.myProgressBar.value = 32*b+16*i+8*s+4*u+2*k+c;
                                       findAttr (b, i, s, false, u, /*k*/false, c, "");
                                       if (s)
                                            findAttr (b, i, false, s, u, /*k*/false, c, "");
                                  }
                             }
                        }
                   }
              }
         }
    }
    myProgressPanel.hide();
    
    exit(0);
    
    function myCreateProgressPanel(myMaximumValue, myProgressBarWidth)
    {
         myProgressPanel = new Window('window', 'Prepping text');
         with(myProgressPanel)
         {
              myProgressPanel.myProgressBar = add('progressbar', [12, 12, myProgressBarWidth, 24], 0, myMaximumValue);
         }
    }
    
    function findAttr (bold, italic, superscript, subscript, underline, strikeout, small_all_caps, StyleName)
    {
         app.findTextPreferences = NothingEnum.nothing;
         app.changeTextPreferences = NothingEnum.nothing;
         app.findTextPreferences.appliedCharacterStyle = app.activeDocument.characterStyles[0];     // "[None]"
    
         app.findTextPreferences.fontStyle = "Regular";
         app.findTextPreferences.position = Position.NORMAL;
         app.findTextPreferences.capitalization = Capitalization.NORMAL;
         app.findTextPreferences.underline = false;
         app.findTextPreferences.strikeThru = false;
    
         if (bold)
         {
              if (italic)
                   app.findTextPreferences.fontStyle = "Bold Italic";
              else
                   app.findTextPreferences.fontStyle = "Bold";
         } else
         {
              if (italic)
                   app.findTextPreferences.fontStyle = "Italic";
         }
         if (superscript)
              app.findTextPreferences.position = Position.SUPERSCRIPT;
    
         if (subscript)
              app.findTextPreferences.position = Position.SUBSCRIPT;
    
         if (underline)
              app.findTextPreferences.underline = true;
         if (strikeout)
              app.findTextPreferences.strikeThru = true;
    
         if (small_all_caps == 1)
              app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;
         if (small_all_caps == 2)
              app.findTextPreferences.capitalization = Capitalization.ALL_CAPS;
    
         foundItems = app.activeDocument.findText();
    
         if (foundItems.length > 0)
         {
              if (StyleName == "")
              {
              //     Make up a name
                   if (bold)
                        StyleName = "Bold";
                   if (italic)
                   {
                        if (bold)
                             StyleName = "Bold Italic";
                        else
                             StyleName = "Italic";
                   }
                   if (superscript)
                   {
                        if (StyleName) StyleName += " + ";
                        StyleName += "Super";
                   }
                   if (subscript)
                   {
                        if (StyleName) StyleName += " + ";
                        StyleName += "Sub";
                   }
                   if (underline)
                   {
                        if (StyleName) StyleName += " + ";
                        StyleName += "Underline";
                   }
                   if (strikeout)
                   {
                        if (StyleName) StyleName += " + ";
                        StyleName += "Stkout";
                   }
                   if (small_all_caps == 1)
                   {
                        if (StyleName) StyleName += " + ";
                        StyleName += "Scaps";
                   }
                   if (small_all_caps == 2)
                   {
                        if (StyleName) StyleName += " + ";
                        StyleName += "Caps";
                   }
                   try
                   {
                        cstyle = app.activeDocument.characterStyles.add({name:StyleName}); // , fontStyle:app.findTextPreferences.fontStyle, underline:app.findTextPreferences.underline, strikeThru:app.findTextPreferences.strikeThru, position:app.findTextPreferences.position, capitalization:app.findTextPreferences.capitalization});
                        if (bold || italic) cstyle.fontStyle = app.findTextPreferences.fontStyle;
                        if (superscript || subscript) cstyle.position = app.findTextPreferences.position;
                        if (underline) cstyle.underline = app.findTextPreferences.underline;
                        if (strikeout) cstyle.strikeThru = app.findTextPreferences.strikeThru;
                        if (small_all_caps) cstyle.capitalization = app.findTextPreferences.capitalization;
                   } catch (e)
                   {
                   }
              }
              app.changeTextPreferences.appliedCharacterStyle = StyleName;
              app.activeDocument.changeText (false);
         }
    }
    
    
     
    |
    Mark as:
1 2 Previous Next

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points