is now part of!

PerfectPrepText: A smart way to style local formatting


One of the most popular free scripts for InDesign, preptext.jsx, was written by our own InDesignSecrets contributor Theunis DeJong, aka “Jongware.” He wrote it a few years ago, seemingly on the fly, in response to a plea for help from an InDesign user on the Adobe InDesign User-to-User forum. Preptext.jsx applies character styles to text with local formatting (bolds, italics, superscripts, and a few others) so you can retain the formatting when you apply your own paragraph styles or when you export to EPUB. It goes through the active story in just a few seconds, seeking out locally-styled text, creating the character styles (yes!) for you as needed and applying them throughout.

The problem is that preptext.jsx sometimes does too good of a job, creating and applying character styles to every instance of bold (or italic, or all-small caps, etc.) text, even if it’s not locally-formatted; that is, even if the formatting is part of the paragraph style applied to the text. Jongware says that’s because his script is designed to be run before you apply any InDesign styles, like when you first import a Word file and opt to delete styles but retain local formatting (you’ll find this option in the Word Import Options dialog box). But sometimes I forget, and need to run it after.

For example, I’ll often want to run Jongware’s script at this point, when I have some basic paragraph styles already applied – Headline and  Body – but haven’t yet built up any character styles. The italic and small caps etc. you see in the sample are all locally formatted.

After I run preptext.jsx, it looks the same, except now we have a bunch of character styles (yay!) that have been applied to the locally-formatted text (yay!)

BUT: Take a look at my insertion point in the headline in the second screen shot. Do you see how the script created and applied the Bold character style to it? Even though the bold text wasn’t locally formatted-the Head paragraph style uses a bold typeface- That’s a potential problem. What if you edit the Head style so it used a non-Bold typeface? This text would still be bold, because of the character style applied to it.

Even if you never need to edit the paragraph styles, this “double-hit” of style sheets makes editing EPUBs or HTML files exported from affected files very difficult. Look at how the headline text in this exported file has both paragraph style classes and span (character style) classes for the same bit of text, “An Introduction to”:

Just as in the live InDesign file, if you decide that you want your CSS for the Head style to not be bold, you’d have to remember to go back to the HTML file and strip out all the superfluous span classes affecting the Head paragraphs too.

I asked my friend and über-scripter Peter Kahrel if he could help me out. Peter’s no longer doing freelance scripting, but in his off-hours, over a period of a few days (and a few versions he sent over), he came up with a solution! I’m calling it PerfectPrepText. It doesn’t replace Jongware’s wonderful preptext.jsx, it’s more of a prologue and epilogue to it.

How PerfectPrepText Fixes the Problem

Peter’s add-on to Jongware’s script deconstructs the story temporarily; first removing (he calls it “neutralizing”) the paragraph styles, then runs preptext.jsx (you need to have the preptext.jsx script at the same level as Peter’s somewhere in your InDesign scripts folder), then reasserts the original paragraph styles. I asked Peter to give me two versions of his script, the first called PerfectPrepText_Ask.jsx that asks what step you want to do, like this:

The steps would be:

  1. Run PerfectPrepText_Ask.jsx to neutralise the styles
  2. Run preptext.jsx (or any other style mapper) to create and apply character styles, and optionally do other things to the text while in this weird limbo state
  3. Run PerfectPrepText_Ask.jsx again to restore the styles-it remembers what gets applied where, somehow

And then for the rest of us who would prefer not to have a heart attack seeing all our styling “neutralised” in Step 1, Peter made an “unattended mode” version called PerfectPrepText_Do.jsx that zips through all three steps on its own. It still requires that you have the preptext.jsx script in your scripts folder (at the same level) but you don’t need to run it yourself.

I ran PerfectPrepText, and here’s the “After” on the same bit of text I started with at the top. All the character styles were created and applied to the locally-formatted text only. Notice how the word “Introduction” in the headline (where my cursor is) has no character style applied to it.  Yay!

And the proper styling goes all the way through to EPUB/HTML export, too – no extraneous <span> classes in the <p> class:

Peter doesn’t have a Donate button on his web site, but he said he just wanted to help support InDesignSecrets. Thank you Peter!  And I have to mention that if you need more oomph, David’s PowerStyles plug-in does the same intelligent creation/application of character styles to locally-formatted text, plus it has many other useful text styling features. If you haven’t checked out the free trial yet, you really should – it’s pretty cool.

Meanwhile, you can download from our web site – it contains three files: The _Ask and _Do versions of PerfectPrepText, and preptext.jsx (Thank you Jongware!)

Anne-Marie “Her Geekness” Concepción is the co-founder (with David Blatner) and CEO of Creative Publishing Network, which produces InDesignSecrets, InDesign Magazine, and other resources for creative professionals. Through her cross-media design studio, Seneca Design & Training, Anne-Marie develops ebooks and trains and consults with companies who want to master the tools and workflows of digital publishing. She has authored over 20 courses on on these topics and others. Keep up with Anne-Marie by subscribing to her ezine, HerGeekness Gazette, and contact her by email at [email protected] or on Twitter @amarie
  • Frances says:

    Lovely, absolutely lovely. Thanks to you all.

  • Quentin says:

    That is utterly fantastic.

  • Jongware says:

    My thanks to the Dynamic Duo of Anne-Marie and Peter for coming up with this solution!

    I couldn’t think of anything to change in preptext itself, but maybe that’s because I’m positively neurotic about my document construction: I always make sure all formatting is done through character styles, and hence I usually do not need this.

    • Gunjan Kumar says:


      Hope you are doing fine. I am facing one formatting issue in my document, even if I am running Prep text, I am loosing Superscript.

      My problem is:

      After placing word file in InDesign, I am running the script “PerfectPrepText_Do.jsx” and all texts are appearing perfectly but if I am applying other style like Bold text to be Italic then superscript are getting normal (Highlighted in yellow). (See attached file for your reference) and try to fix this in Paragraph:

      Protokollerklärung zu Absatz 2:
      1Bei der Berechnung des durchschnittlich gezahlten monatlichen Entgelts werden die gezahlten Entgelte der drei Monate addiert und durch drei geteilt; dies gilt auch bei einer Änderung des Beschäftigungsumfangs. ²Ist im Bemessungszeitraum nicht für alle Kalendertage Entgelt gezahlt worden, werden die gezahlten Entgelte der drei Monate addiert, durch die Zahl der Kalendertage mit Entgelt geteilt und sodann mit 30,67 multipliziert. ³Zeiträume, für die Krankengeldzuschuss gezahlt worden ist, bleiben hierbei unberücksichtigt. 4Besteht während des Bemessungszeitraums an weniger als 30 Kalendertagen Anspruch auf Entgelt, ist der letzte Kalendermonat, in dem für alle Kalendertage Anspruch auf Entgelt bestand, maßgeblich.

      Looking forward to hear from you.


  • Eugene Tyson says:

    This is great. I’ve been wanting to ask for a fix for this for a long time. Thank you very much. But I’ll hold the champagne cork and party streamers for a moment; I’m getting an error :(

  • Eugene Tyson says:

    This script worked perfectly in CS3 – but wouldn’t work in CS5 and the “make it run script” doesn’t seem to work with it.

  • I’m using it PerfectPrepText in CS5.5 without an issue. Eugene I’m guessing you need to save your document?

  • Eugene says:

    Yeh I guess you do. But as I say, I only use a new document to place text into before copying to the main document. I don’t usually save these files first.

  • there are a few problems with align left/right and baseline.

    after using the _Do-script or the sequence of “_Ask, preptext, _Ask”, the following happens:
    – para-style: “justified”, locally formatted to “align left” -> looses its local formatting
    – para-style: “justified”, locally formatted to “align right” -> retains its local formatting

    similar to that are problems with the baseline:
    – para-style “align to baseline”, locally formatted to ignore the baseline -> looses its local formatting
    – para-style “don’t align to baseline”, locally formatted to align to the baseline -> retains its local formatting

    but these problems also happen, when you load the para-styles “manualy” in the para-styles-window (via “load para-styles”), so it’s no bug of this script.
    (using cs5/cs5.5 with newest updates on win7)

  • Erica Gamet says:

    I’m not sure if I’m missing something (and it’s quite possible I am), but I’ve been using Thomas Silkjær’s simple auto create p_c styles script to format imported text. I can run it directly after the import and it creates all paragraph and character styles for me. If I have any formatting already done, say a header with a bold font, it doesn’t create anything new for that text…I assume it sees it has a paragraph style and ignores it. It creates character styles for any locally formatted text.

    The only thing I need to fix afterwards is the fact that the created character styles include font info, which I usually don’t want…I keep my character styles simple, like “bold,” “italic,” “red,” etc.

  • Anne-Marie says:

    You’re not missing a thing, Erica! Sounds like a great script. Do you have a link?

  • Peter Hofmann says:

    This used to work fine for me in CS 5.5, but now in CS 6 it doesn’t work anymore.
    I get a JavaScript error when placing my cursor anywhere (roughly translated from German (from normal preptext): “errorstring: undefined is no object”, line: 3, source: if). When placing it in the textframe, it seems to do something, but in fact there are no character styles created and the overrides remain.

    The whole problem seems to occur only with preptext, since the wrapping around with your addition works fine, but the script itself does nothing.
    Anyone here with CS 6 having the same problem? It would be amazing to be able to keep using this handy script!

    Greetings from Germany,

  • Peter Hofmann says:

    okay, I guess I found the problem:
    The script only recognizes “bold”, “italic” and so on, but some fonts have other names like “medium italic”, “75 Bold” (Helvetica Neue) and so on.
    So preptext and also perfectpreptext works perfectly fine on CS 6, it just doesn’t recognize custom font names for “bold” and “italic”, which is a bit of a shame for people like me dealing with many different fonts, but nonetheless thank you for this amazing script and maybe I can customize it so it recognizes the font names I tell him to (shouldn’t be too difficult).

  • Jongware says:

    Peter, you’re right about the issue with non-standard “bold” and “italics” names. Unfortunately there is no real good solution! InDesign only knows a font is bold or italics because it checks some internal bits inside the font, and that information is not accessable through acripting.

    My own solution before running the script is to use Find Font to replace all non-standard fonts to a standard one. But that’s a pre-production solution, and it won’t work nicely on an otherwise done document.

    If you have a fairly limited set of fonts, your suggestion to add the oddball style names to the script ought to work just fine.

  • Peter Hofmann says:

    Thank you for the quick answer, Jongware. I had no idea it would be that difficult. But I think your “Find Font”-solution could at least make things a bit easier, since I work on books with more than 300 pages and many overrides that I need to export to epub, and I don’t want to embed fonts for that anyway (print fonts do not necessarily work on web/devices, and eReaders mostly forbid embedding).

  • profeivan says:

    Great script! very useful. My solution to include styles like “medium italic”is: before running the script, you can use find/change to apply a character style, in the character style options activate Export Tagging (CS6) and select a class for exporting, then run the script for the standard bold and italic text.

  • Thanks a lot for this, I’m using it frequently, saves a lot of work! But I have hundreds of files and one question: it’s possible to batch apply this script? Would be fantastic to have an “unattended mode”.

  • @Marcio: There is a batch tool available here: I don’t know if it works with this particular script, but it’s worth a try.

  • Hi David, thanks for the tip! I tried PerfecPrepText with the batcher script (fantastic idea, btw), but it didn’t work. I think it’s because preptext needs the cursor in a frame before execution.

  • In the following link (Adobe Foruns) you find detailed instructions by Jongware himself on how to adapt the preptext script to run with Batcher:

  • Duncan says:

    The link for Thomas Silkjær?s script is down. Would you please email me a copy of the scriptm or repost a live link for download?

  • Tori says:

    I downloaded and installed these scripts after watching AM’s tutorial video on but I can’t get it to work! All scripts are together in the same folder. I am using InDesign CS6 which seems to be the issue b/c I can install and run PerfectPrep Text on a diff computer which has CS5 (tried a diff comp. w/ CS6, same error). This is what the error says
    “JavaScript Error!
    Error Number: 21
    Error String: undefined is not an object
    Engine: main File: /Users/lisatudor/Library/Preferences/Adobe InDesign/Version 8.0/en_US/Scripts/Scripts Panel/ePub/PerfectPrepText_Do.jsx
    Line: 14
    Source: app.doScript (prepscript);”
    Thanks for any help!

    • Tori says:

      Problem solved. I noticed Marcio’s earlier post where he mentioned the cursor needed to be in the frame, doing so made this error go away.

  • Erik says:

    Great script, anyone run it on a book file or found a way to run it across all files in a book vs individually?

  • hari says:

    hi, im Hari. if we r trying to specially apply style while using GREP, there is an error in this script.please can some one help me.consider this pattern()(.+)() in GREP in find what and in change to im using $2,all the char style applied has changed in a different way. For Eg. In [Im Hari], consider hari should be in italics.after running the script if we use GREP to apply style. the word I(regular)m( has changed to italics) har(italics)i(has been changed to regular).

  • Heulwen says:

    These sound like fantastic scripts and I will download and try them : )

    My problem is a bit different though. Do you think Theunis, Peter, Thomas or David’s script will solve the following:

    All text in my InDesign files is already fully styled – both character and paragraph styles. Character styles are used heavily throughout the documents for special font sizing etc. However bold, italic and underline is applied through ‘local’ formatting and is often on top of an existing character style.

    So my question is will the script be smart enough to replace the underlying character style with a new style that includes all the formatting that was in the character style as well as the bold, italic or underline that is applied on top?

    Also, what would be really great, is if it kept the name that was used for the character style but just adds the word ‘bold’ or ‘italic’ or ‘underline’ to the new style name eg. char style ‘Quote All Cap’ might become ‘Quote All Cap Bold’ ????

    Many thanks. Heulwen

  • senthilkumar ayyavu says:

    Really needed script! Thanks

  • Adam ?akomy says:

    Is PerfectPrep still works in CC? I run it, it gave no error but local overrides still was there?

  • levonk says:

    Adam, I have the same problem in CS6. Nothing changes.

  • Richard Groff says:

    This works great in CS6 (except for the strike through function, but that’s so rarely used anyway). Now if it would only work through the whole document and not just the story that the cursor is in. We often have sidebars and photos with captions that are anchored and therefore the text in them is not part of the main text thread.

  • Roy Behymer says:

    Thanks for the scripts. I’ve been using them for a while and they are a great timesaver. I have recently started seeing a problem though. I’m running Mac OS 10.9. When I run PerfectPrepText_Do.jsx in CS6, it now launches CC and then says it can’t find preptext.jsx. If I use PerfectPrepText_Ask.jsx instead, it creates a copy of the active CS6 file then stops. No styles of any kind added to the active file or the copy file. I’ve been using this successfully in CS6 for a while and have had CC installed also without this happening, it’s just a recent development. I’m guessing a pref file or some other file changed and if I can only remove that file, things will work again. That may be a pipe dream though. I’ve deleted and reinstalled the perfectprep files and have updated the preptext with Jong’s latest version (30-Mar-2010). I’d hate to lose this functionality because a large part of my work is taking Word files and laying them out for book publishing. Manual is not the way to go. Thanks for any input.

  • I’ve run into the same vexing problem (opens wrong version) with PerfectPrepText, alas. A better solution is to just buy David’s Power Styles plugin ($59) for InDesign.

    It does an excellent job of creating and applying character styles and it can work through the entire document in one go. At this point though there is *still* no CC version. We’ve resorted to exporting to IDML, opening in CS6, running Power Styles, and then opening it up again in CC. Not ideal by a long shot but at least it does the job, and it’s a very well-done plug-in.

  • I should mention that having written the above, I just tested PerfectPrepText on a new doc in CC and it worked perfectly. ;-D And I have about 5 versions of ID installed.

    Two tips: Before you run the script, make sure you save the document (it won’t work on Untitled docs), and make sure your Text cursor is blinking inside the frame that you want it to run in.

    • I used both the copy of the scripts for PerfectPrepText from the EPUB training exercises and downloaded and tried the current ones from the link provided above. I tested under InDesign 2014 and the previous release.

      PrepText ran for me, but PerfectPrepText_Ask, PerfectPrepText_Do and the previous PerfectPrepText (from the EPUB exercises by Marie all hung and I had to End Task on InDesign. I am on Windows 8.1 and was careful to make sure I had a saved document and also that I was in the frame with all my text.

      Not sure if anyone else has had this problem or not.

  • Hi Steve, sorry that happened to you. My guess would be that it’s something in Windows 8.1? All other scripts run fine?


    • Anne-Marie,

      I was playing around with this trying to eliminate each possibility and then I found out the PerfectPrepText_Ask hangs when I have the cursor in the Text Frame, but not if it is outside the text frame. Then I run preptext with cursor in text frame (or I get error), and then run the PerfectTextPrep_Ask again to Restore (but cursor must be outside the text frame or it hangs). By doing it exactly like that it works, but if I have the cursor in the text frame, it hangs? I am not sure why it works that way under Windows 8.1 or if it is some other problem, but will research it in about a months time to ensure I know exactly what is going on.

      Since it works for now, I need to get back to formatting my book to get it published in next few weeks, and then I can get back to testing and figuring out what is happening in detail.

  • Tiffany says:

    Hi, I am working through your course on, InDesign CC: EPUB Fundamentals. In Chapter 04.04, I received the following error message when I tried to run PerfectPrepText_Do.jsx. Preptext.jsx seemed to run just fine.

    “JavaScript Error!
    Error Number: 21
    Error String: undefined is not an object

    Engine: main
    File:C:\Program Files\Adobe\Adobe Indesign CC 2014\Scripts\Scripts\Panel\PerfectPrepText_DO.jsx
    Line: 14
    Source: app.doScript (prepscript);

    • Tim says:

      Same here. Came looking for an update or similar script. I’m going to try to reach Theunis DeJong through social media and see if I can get a solution. If I find anything, I’ll try to post it here.

      • georgina artiga says:

        I have the newest version of Indesign and this script is giving me same error.. is it not updated? i want it to work soooooo bad

  • I haven’t tried it recently, but I know that in order for the script to run, make sure 1) you’re working in a named/saved document –it doesn’t work with Untitled documents; and 2) your text cursor is inside a story (text frame).

  • Doug Gibson says:

    Just want to say that I’m using perfectpreptext for about the tenth time since I came across this post, and still grateful that it exists and that you let folks know about it. What a huge saving of time and energy!

  • Taeja says:

    Wonder if anyone else had an error message,
    error number: 90938
    error string: unsaved documents have no full name.

    when running perfect prep text. And if so, how to fix it?

  • Taeja says:

    OOPS. Thought I had the file saved. Nevermind :( I didnt have the file saved!

  • David Laufer says:

    So, I just waded through this very informative convo, spanning 4 years and at least 287 versions of INDD(!), wondering if the best solution for INDD CC 2015 is still PerfectPrepText? I am just starting a long document with lots of italic, bold and some foreign accents. The styles in the word doc that I was given bear no relation to the paragraph styles I want to wind up with. Is there an InDesign Secrets or tutorial that goes into this in detail? I’m a bear of little brain and step by step is my MO.
    Thanks All…

  • Hi David! As far as I know PerfectPrepText still does the job.

    I show how to work w/the script in a few of my InDesign > EPUB video titles at, but essentially it’s just as I explained here.

    I think you might benefit more by watching some of my Using Word with InDesign title there, which could help you do a bit of cleanup to the Word file to make formatting it in InDesign easier.

    If you don’t have a subscription, some of videos in the title are free, or you can get a free 10-day trial (requires your entering a credit card number) here:

  • Derek says:

    Are there plans to update, or is it possible to edit the scripts to work in CC 2015?

  • Kelli Fleck says:

    This is amazing! Been using preptext for over a year now. Didn’t realize there was this new, improved one. I definitely had problems with the headers, but it was worth it because of so much else that it did.

  • Ginger Marks says:

    I used to use this all the time. But it seems it is no longer working.

  • >