Once again, I am working on a file that will be used in InDesign. The manuscript is set in Pages, using styles throughout. I export out of Pages into RTF and then into Nisus. The macro that I would like to have help creating would look at each paragraph, recognize the applied style, extract that style name and insert it before the paragraph in the InDesign tagged text format.

Example:
The first paragraph style name is "Heading 1".
The second paragraph style name is "Body".

Individual Study
This participant’s guide also works well for personal or individual study. Simply move at your own pace through the lessons and use the discussion questions as prompters for note taking, journaling, and personal reflection.

Would become:

<pstyle:Heading 1>Individual Study
<pstyle:Body>This participant’s guide also works well for personal or individual study. Simply move at your own pace through the lessons and use the discussion questions as prompters for note taking, journaling, and personal reflection.

Kino,
I did find one problem. When the InDesign Tagged Text code and the Style name are inserted, they take on the style of that paragraph. This causes a problem when the style is all caps or small caps as InDesign needs to see the code in lowercase. What code would I use to make the inserted text no style or forced to lowercase?

Martin,
I should think these things out before I post. The new macro works, but now I find that I will need to ensure that the InDesign code doesn't take on any of the formatting of the paragraph (bold, italic, etc). My second macro searches for these formats and inserts a code for the character styles. If this is a pain, I can run the character style macro first but I have a reason for not wanting to do that which has escaped me at this moment.

Ahh okay, well here's one question: do you really need the InDesign tags to be devoid of all formatting (eg: bold, italics, color, etc) or just proper named Character Styles (eg: Emphatic, Default Font, etc)? The latter is much easier to accomplish.

Martin,
I need both. A paragraph style to set the indents, space before and after, drop cap, first line, font, leading etc. Within the paragraph we then use character styles to modify, bold, italic, small caps, superscript etc. If we have the style name come in with the same format as the text then the codes can be swapped around and wont work.

An example,
Original text:To Vanderbilt Medical Center, thank you for your concern, loving care, and patience with the hundreds

So what you want is all InDesign tags at the start of each paragraph formatted as "plain" text, without any attributes. The trouble is that one cannot apply Normal or some other default style to just the tags, as that would supplant the style from the rest of your paragraph as well. The only way you can achieve your goal is to override the paragraph style's formatting, one attribute at a time. Here's a macro that does such a thing:

The trouble with this approach is one must list all menus that need to be at some "plain" state. In the macro above I've covered the attributes you mentioned (eg: bold, italic, superscript, and case change), but likely you have others. For every attribute your other macros care about, you'll need to add a relevant entry to the $menuStates hash.

As an example, let's say you also need to ensure the text coloring is black. You'd want to add this line to the macro: