PARAGRAPH STYLES ON STEROIDS

One of the advantages of using paragraph styles is that you can link them together using the Next style designation. For instance, the following story begins with a headline, followed by a byline, then a first paragraph with a drop cap. The rest of the story is styled using a style named “Body”.

…Text having consistent style pattern

To set this up you will want to set the font, size, and leading for “[Basic Paragraph]” to be the same as “Body” style without a first line indent. With this in place, create a paragraph style for “Body” based on “[Basic Paragraph]” with a first line indent (or space before if no indent). Since there will be any number of “Body” paragraphs following, set Next Style to [Same style].

..Next Style setting for Body style

For the first paragraph (with a drop cap) you will most likely need a character style for the drop cap. The name for this paragraph could be “First” or “Dropcap” and be based on “[Basic Paragraph]” with its next style “Body”.

..Next Style setting for First style

The paragraph style for the byline would be named “Byline”, based on “[Basic Paragraph]”, and with justification set to Left or Center as appropriate. Its Next Style would be “First”.

To finish out the paragraph chain of styles, a style named “Headline” is created. Even though it will be at a much larger size than the Body or Byline styles, you would base it on “[Basic Paragraph]” if it uses the same font. Set Span to Span all columns and select Byline as its Next Style.

You get the idea. I refer to this as a “Chained Style Pattern.”

USING A CHAINED STYLE PATTERN

When text is entered into a text frame that has the paragraph style for its first paragraph established with a Chained Style Pattern, a line return starts the next paragraph with its styling the designated Next Style.

But what happens when text is placed from a file?

PLACED TEXT

Plain text

When a plain text file is placed, the text comes in styled with the “[Basic Paragraph]” style. If this style is set up the same as for body text, at least some of the styling is taken care of. Using Quick Apply can help style the rest.

Microsoft Word

If the Microsoft Word document has been styled properly, the styles can be mapped to InDesign’s paragraph styles as part of the import process. The problem is, even at best your InDesign document may end up with a lot of text overrides. At worst, everything may be styled “Normal”. Map “Normal” to your “Body” style and, again, use Quick Apply.

Excel Files

Many firms are relying on Excel to act like a database for organizing data. This has its place, but .csv files don’t retain character formatting, and tables have their own unique set of problems.

A SIMPLE SCRIPT TO THE RESCUE

For text that will have a uniform paragraph style pattern such as our example above, a simple script can use the Next Style designation to style paragraphs automatically. Here is one example:

Typical Newsletter

Assuming you have a document where styling has been set up as a Chained Style Pattern with the first paragraph style of the pattern being Headline, the following script can be used to import and style a chosen text file. It requires that a text frame be selected prior to running the script.

Hint: Place the script in InDesign’s Scripts panel and run it from there (double click). Optionally, assign it a keyboard shortcut for even more trouble-free execution.

set firstStyle to "Headline"
try
	set insertRef to getSelectedInsert()
	set fileRef to getTextFile()
	placeAndStyle(firstStyle, insertRef, fileRef)
on error errStr
	activate
	display alert "Error: " & errStr
end try
(*Assumes paragraph styling is based on Next Style starting with name of style passed*)
on placeAndStyle(styleName, insertRef, fileRef)
   tell application "Adobe InDesign CC 2019"
	tell text import preferences
	   set use typographers quotes to true
	end tell
	set headStyle to paragraph style styleName of document 1
	set bodyStyle to paragraph style "[Basic Paragraph]" of document 1
	set applied paragraph style of insertRef to bodyStyle
	set thisStyle to headStyle
	tell insertRef
		place fileRef
	end tell
	tell parent story of insertRef
		set paraRef to a reference to paragraphs
		repeat with eachParagraph in paraRef
		    set applied paragraph style of eachParagraph to thisStyle
		    set nextStyle to next style of thisStyle
		    set thisStyle to nextStyle
		end repeat
	end tell
   end tell
end placeAndStyle
(*Has user select plain text file; verifies using kind or name extension; returns alias reference*)
on getTextFile()
   set fileRef to choose file with prompt "Select text file for placing"
   set theInfo to info for fileRef
   if kind of theInfo is "Plain Text Document" or name extension of theInfo is "txt" then
	return fileRef
   else
	error "Requires plain text file to be chosen"
   end if
end getTextFile
(*Returns frame for placing file using class of selection for text frame or insertion point*)
on getSelectedInsert()
   tell application "Adobe InDesign CC 2019"
	set selList to selection
	if selList is not {} and class of item 1 of selList is in {text frame, insertion point} then
	    set selItem to item 1 of selList
	else
	    error "Requires text frame selection"
	end if
	if class of selItem is text frame then
	    set insertRef to insertion point 1 of selItem
	else
	    set insertRef to selItem
	end if
    end tell
    return insertRef
end getSelectedInsert

To just place and style a single text file this script doesn’t save a lot of time. On the other hand, considering the number of text files over a series of newsletters, the savings in time can add up. Start the newsletter document with a template that has the styles predefined, and you can start planning for a vacation with the time saved.

ONWARD AND UPWARD

But wait, there’s more! The same functionality can be applied to any number of documents. Think of other ways this automation could be applied. Maybe a car ad like the following that has “Make”, “Model”, and “Price” set up as a Linked Style Pattern. The style for “Price” takes advantage of nested styles and uses the first style (“Make”) for its Next Style. Just change the value for the variable firstStyle in the script above to “Make.”

Sample car ad items

Or maybe use this for a grocery ad having a pattern similar to the car ad only with “Item”, “Description”,”Weight”, and “Price”. Set Start Paragraph (in Keep Options) for the “Item” style defined as “in Next Frame”.

…Sample grocery ad items

To make the script user friendly, add a choose from list dialog to the script above so user can choose the value for the first style. Change the top of the script to read as follows:

try
   set insertRef to getSelectedInsert()
   set fileRef to getTextFile()
   set firstStyle to getFirstStyle()
   placeAndStyle(firstStyle, insertRef, fileRef)
on error errStr
   activate
   display alert "Error: " & errStr
end try

Then add the following handler:

(*Returns user choice for paragraph style by name*)
on getFirstStyle()
   set stylePrompt to "Select style for first paragraph in Chained Style Patter"
   tell application "Adobe InDesign CC 2019"
      set styleList to name of paragraph styles of document 1
      set userChoice to choose from list styleList with prompt stylePrompt
      if userChoice is false then
         error "Requires selection to continue"
      end if
   end tell
   return item 1 of userChoice
end getFirstStyle

Now the script can be used for any number of documents that take advantage of Chained Paragraph styles.

Disclaimer:
Scripts provided are for demonstration and educational purposes. No representation is made as to their accuracy or completeness. Readers are advised to use the code at their own risk.