<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>In-Tools &#187; cookbook</title>
	<atom:link href="http://in-tools.com/wordpress/tag/cookbook/feed" rel="self" type="application/rss+xml" />
	<link>http://in-tools.com/wordpress</link>
	<description>Innovations in Automation</description>
	<lastBuildDate>Sun, 29 Aug 2010 05:49:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Composite Headers Never Before Possible!</title>
		<link>http://in-tools.com/wordpress/indesign/plugins/power-headers/composite-headers-never-before-possible</link>
		<comments>http://in-tools.com/wordpress/indesign/plugins/power-headers/composite-headers-never-before-possible#comments</comments>
		<pubDate>Thu, 17 Dec 2009 23:01:40 +0000</pubDate>
		<dc:creator>Harbs</dc:creator>
				<category><![CDATA[Power Headers]]></category>
		<category><![CDATA[cookbook]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://in-tools.com/wordpress/?p=233</guid>
		<description><![CDATA[In this &#8220;how-to&#8221; we are going to address a really difficult problem in creating headers which seems almost impossible to automate. We will show you how you can do the impossible with Power Headers! The example used is an actual Hebrew publication, but the concepts can be applied to any language or use.
Beware that this [...]]]></description>
			<content:encoded><![CDATA[<p>In this &#8220;how-to&#8221; we are going to address a really difficult problem in creating headers which seems almost impossible to automate. We will show you how you can do the impossible with Power Headers! The example used is an actual Hebrew publication, but the concepts can be applied to any language or use.</p>
<p><strong>Beware that this is an advanced topic and not for the faint of heart!</strong> It is a complicated setup, but it does a good job of demonstrating the deeply powerful capabilities of Power Headers.<br />
<span id="more-233"></span></p>
<h3>Here are the problems:</h3>
<p>1. The headers must contain the range of both the chapters and the verses which appear in the text. Because there a ranges for both chapers and verse, but the verses are contained in the chapters, the headers can appear in two forms:</p>
<p><img class="alignnone size-full wp-image-234" title="chapter_verse1" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapter_verse1.png" alt="chapter_verse1" width="165" height="85" /><img class="alignnone size-full wp-image-235" title="chapter_verse2" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapter_verse2.png" alt="chapter_verse2" width="140" height="72" /></p>
<p>The red arrows show the chapter numbers, while the green arrows show the verse numbers. When there is only one chapter on a page, the format is: 1. Chapter number-slash, 2. first verse &#8211; hyphen, 3. last verse.</p>
<p>When there are two chapters on the page, the format must be: 1. First Chapter number-slash, 2. first verse, 3. N-dash, 4. Last Chapter Number &#8211; slash, 5. last verse. Being that there are a minimum of at least four different variables which might or might not appear on the page, <em>this is a seemingly hopeless situation</em>!</p>
<p>2. To further complicate matters, there are sometimes one, and sometimes two verses per line. When there are two verses per line the verse numbers appear with a dash separating them like this:</p>
<p><img class="alignnone size-full wp-image-236" title="double_verse" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/double_verse.png" alt="double_verse" width="76" height="74" /></p>
<p>If we were to simply use a First and/or Last instance, we would sometimes end up with text that looks like [verse_a]-[verse_b]-[verse_c], so we need a way to pick up the first number if it&#8217;s the first instance, but the second number if it&#8217;s the last instance.</p>
<h3>Solutions:</h3>
<p>If not for problem #2, we could automate this with three variables, and even factoring in that problem it would probably be possible with four variables (or three with an additional variable-level GREP Processor), but for simplicity sake, we will use six variables to make each instance a separate variable. Since each variable adds time to the updating, you would normally want to do it with as few variables as possible, but we wanted to keep this how-to as simple as possible.</p>
<p><strong>Step #1: Create six different character styles</strong> &#8212; one for each variable:</p>
<p><img class="alignnone size-full wp-image-302" title="character_styles" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/character_styles.png" alt="character_styles" width="213" height="215" /></p>
<p><strong>Step #2: Right click on the header frame and give the header frame a label:</strong></p>
<p><img class="alignnone size-full wp-image-241" title="label_context_menu" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/label_context_menu.png" alt="label_context_menu" width="427" height="78" /></p>
<p><img class="alignnone size-full wp-image-242" title="label_header_frame" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/label_header_frame.png" alt="label_header_frame" width="338" height="188" /></p>
<p><strong>Step #3: Create the chapter variables.</strong></p>
<p>The first chapter variable should be a &#8220;Current Instance&#8221; variable which will display the previously found chapter unless the chapter number is at the start of the new page &#8212; in which case it will display the one appearing at the top of the page.</p>
<p>The chapter header adds text after which will act as a separator between the chapter number and the verse number:</p>
<p><img class="alignnone size-full wp-image-256" title="chaptera" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chaptera.png" alt="chaptera" width="491" height="480" /></p>
<p>The second chapter variable should be a &#8220;Last Instance&#8221; variable.</p>
<p>The chapter header adds text after which will act as a separator between the chapter number and the verse number, as well as a dash to act as the separator between the first chapter/verse and the second one:</p>
<p><img class="alignnone size-full wp-image-255" title="chapterb" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapterb_pre_edit.png" alt="chapterb" width="491" height="480" /></p>
<p><strong>Step #4: Create the four verse variables.</strong></p>
<p>Variable 1</p>
<p><img class="alignnone size-full wp-image-264" title="verse_a" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/versea.png" alt="verse_a" width="491" height="480" /></p>
<p>Variable #2</p>
<p><img class="alignnone size-full wp-image-263" title="verse_b" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/verseb.png" alt="verse_b" width="491" height="480" /></p>
<p>Variable #3</p>
<p><img class="alignnone size-full wp-image-262" title="verse_c" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/versec.png" alt="verse_c" width="491" height="480" /></p>
<p>Variable #4</p>
<p><img class="alignnone size-full wp-image-261" title="verse_d" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/versed.png" alt="verse_d" width="491" height="480" /></p>
<p>As you can see, we inserted a dash (Hebrew &#8220;makaf&#8221;) to serve as a separator between variables #1 and #2, and between variables #3 and #4.</p>
<p><strong>Step #5:We now have the basic setup for all our variables.</strong> We will insert the variables on the master page, and see what these variables produce:</p>
<p>To insert the variables, we put the text cursor in the header frame and right click:</p>
<p><img class="alignnone size-full wp-image-266" title="insertheaders" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/insertheaders.png" alt="insertheaders" width="534" height="143" /></p>
<p>Repeat the process for each of the headers in their correct order:</p>
<p><img class="alignnone size-full wp-image-265" title="inserted_variables" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/inserted_variables.png" alt="inserted_variables" width="407" height="94" /></p>
<p><strong>Step #6: Update the headers to see what they produce:</strong></p>
<div id="attachment_267" class="wp-caption alignnone" style="width: 287px"><img class="size-full wp-image-267" title="verse_range_result_1" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/verse_range_result_1.png" alt="verse_range_result_1" width="277" height="87" /><p class="wp-caption-text">Verse Range</p></div>
<div id="attachment_268" class="wp-caption alignnone" style="width: 275px"><img class="size-full wp-image-268" title="chapter_range_result_1" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapter_range_result_1.png" alt="chapter_range_result_1" width="265" height="80" /><p class="wp-caption-text">Chapter Range</p></div>
<p>As you see, all the information appears in the header, but it makes no sense in any context. When it&#8217;s a verse range, the entire second half of the header should be removed, and when it&#8217;s a chapter range, we need to do &#8220;surgery&#8221; to remove the third and fifth variables.</p>
<p><strong>Step #7: Add conditional text to variable &#8220;ChapterB&#8221;:</strong></p>
<p>To enable the removal of the last three variables on a page where we will have a &#8220;verse range&#8221;, we insert a &#8220;Conditional Text&#8221; of &#8220;Remove&#8221;. This text will be inserted on any page which does not contain a chapter number (which by definition means it will need a &#8220;verse range&#8221; as apposed to a &#8220;chapter range&#8221;.</p>
<p><img class="alignnone size-full wp-image-255" title="chapterb" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapterb.png" alt="chapterb" width="491" height="480" /></p>
<p><strong>Step #8: Create the first Global GREP Processor</strong></p>
<p>Global GREP Processors run after all the variables are updated, so we can use them to assess the general state of all the variables <em>as they interact with each other</em>.<strong> </strong>This Global GREP Processor is actually quite simple. It will remove all text from the word Remove until the end of the header frame text:</p>
<p><img class="alignnone size-full wp-image-272" title="remove_grep" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/remove_grep.png" alt="remove_grep" width="461" height="176" /></p>
<p>Now let&#8217;s check that it worked:</p>
<div id="attachment_267" class="wp-caption alignnone" style="width: 287px"><img class="size-full wp-image-267" title="verse_range_result_1" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/verse_range_result_1.png" alt="Before" width="277" height="87" /><p class="wp-caption-text">Before</p></div>
<div id="attachment_273" class="wp-caption alignnone" style="width: 198px"><img class="size-full wp-image-273" title="verse_range_after" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/verse_range_after.png" alt="After" width="188" height="76" /><p class="wp-caption-text">After</p></div>
<p><strong>Great!</strong></p>
<p><strong>Step #9: Create Global GREP Processors for chapter ranges.</strong></p>
<p>To fix up the &#8220;chapter range&#8221; headers shown above we will need two different Global GREP Porcessors. One will remove the third variable and the other will remove the fifth variable. Once those two variables are removed, our &#8220;chapter range&#8221; headers will appear as they should:</p>
<div id="attachment_278" class="wp-caption alignnone" style="width: 471px"><img class="size-full wp-image-278" title="rem_end_first_range" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/rem_end_first_range.png" alt="Remove Third Variable" width="461" height="176" /><p class="wp-caption-text">Remove Third Variable</p></div>
<div id="attachment_277" class="wp-caption alignnone" style="width: 471px"><img class="size-full wp-image-277" title="rem_beg_sec_range" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/rem_beg_sec_range.png" alt="Remove Fifth Variable" width="461" height="176" /><p class="wp-caption-text">Remove Fifth Variable</p></div>
<p>These GREP queries are actually a lot simpler than they appear. The fact that they are search right-to-left text make them much harder to read than they would be if they were in Latin letters.</p>
<p>The first GREP query is as follows:</p>
<p><code>([\x{05D0}-\x{05EA}]+)?[\x{05D0}-\x{05EA}]+(?= — )</code></p>
<p>Because of peculiarities of using GREP with right-to-left languages, we used the unicode notation of the GREP string instead of the actual characters. The unicode value of the first letter of the Hebrew alphabet is o5D0 and the last is 05EA. Basically this string searches for any number of Hebrew letters which it saves as a saved group. This is followed by a Hebrew makaf (dash) followed by any number of Hebrew characters with a positive look-ahead for a space, em-dash, space. A rough equivalent in English would be: <code>([a-z]+)-[a-z]+(?= — )</code></p>
<p>The GREP which removes the fifth variable is similar: <code>( — [\x{05D0}-\x{05EA}]+ / )[\x{05D0}-\x{05EA}]+?(?=[\x{05D0}-\x{05EA}])</code></p>
<p>After creating these two GREP Processors and updating the headers we get what we need for the &#8220;chapter ranges&#8221;:</p>
<div id="attachment_268" class="wp-caption alignnone" style="width: 275px"><img class="size-full wp-image-268" title="chapter_range_result_1" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapter_range_result_1.png" alt="Before" width="265" height="80" /><p class="wp-caption-text">Before</p></div>
<div id="attachment_282" class="wp-caption alignnone" style="width: 245px"><img class="size-full wp-image-282" title="chapter_range_after" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapter_range_after.png" alt="After" width="235" height="90" /><p class="wp-caption-text">After</p></div>
<p><strong>Step #10: Fix a hole in the logic:</strong></p>
<p>There is one problem with the logic we used to identify &#8220;chapter ranges&#8221; and &#8220;verse ranges&#8221;. When a page starts a new chapter, there is in fact only one chapter on the page, so it needs a verse range, but since ther was an instance of a chapter number on the page, the extra chapter variable was not correctly removed:</p>
<p><img class="alignnone size-full wp-image-283" title="page_start" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/page_start.png" alt="page_start" width="210" height="208" /><img class="alignnone size-full wp-image-284" title="chapter_start_result" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapter_start_result.png" alt="chapter_start_result" width="289" height="124" /></p>
<p>To fix this problem requires two more GREP Processors. The first one fixes the content, but a second one is required to fix the formatting. The second one is needed due to a peculiarity of InDesign&#8217;s GREP functionality: When you use GREP to remove content in text of mixed formatting, the formatting can get messed up under certain circumstances.</p>
<p>The first GREP Processor finds Chapter numbers which repeat themselves:</p>
<p><img class="alignnone size-full wp-image-286" title="fix_first_instance" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/fix_first_instance.png" alt="fix_first_instance" width="461" height="176" /></p>
<p>The GREP query for this is: <code>([\x{05D0}-\x{05EA}]+)( / [\x{05D0}-\x{05EA}]+) ~_ \1 / </code></p>
<p>The &#8220;\1&#8243; is used to locate the text found in the first group which will find chapter numbers which repeat themselves.</p>
<p>This will result in a header which looks like this (notice the bold letters in the first half of the verse range):</p>
<p><img class="alignnone size-full wp-image-289" title="chapter_start_2" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapter_start_2.png" alt="chapter_start_2" width="258" height="133" /></p>
<p>This requires this GREP Processor to fix up the formatting which searches for text strings unique to the verse headers and applies one of the verse header character styles:</p>
<p><img class="alignnone size-full wp-image-291" title="fix_styles" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/fix_styles.png" alt="fix_styles" width="461" height="176" /></p>
<p>We now end up with a correctly formatted &#8220;verse range&#8221;:</p>
<p><img class="alignnone size-full wp-image-292" title="chapter_start_end" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/chapter_start_end.png" alt="chapter_start_end" width="349" height="184" /></p>
<p><strong>Step #11: Fix Verse Ranges:</strong></p>
<p>The only step left to do is to fix the cases where we more than one verse per line,<img class="alignnone size-full wp-image-293" title="verse_range_in_source" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/verse_range_in_source.png" alt="verse_range_in_source" width="142" height="132" /></p>
<p>and by consequence, a source range in the source text which results in a header like this:</p>
<p><img class="alignnone size-full wp-image-294" title="bad_range_result" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/bad_range_result.png" alt="bad_range_result" width="276" height="109" /></p>
<p>If we were not using the Hebrew makaf to separate the ranges, this would not be a problem, because we could just use &#8220;First Word&#8221; and &#8220;Last Word&#8221; variables. The problem is that Hebrew makafs are identified as regular word characters.</p>
<p>To fix this, we need to create variable-specific GREP Processors. The difference between variable specific GREP Processors, and Global GREP Processors is that the variable-specific ones are run on only the text specific to that variable, while the global ones are run on the entire header frame after all the headers are updated.</p>
<p>We will create one for variable VerseA:</p>
<p><img class="alignnone size-full wp-image-296" title="remove_range_end" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/remove_range_end.png" alt="remove_range_end" width="461" height="176" /></p>
<p>and another one for variable VerseB:</p>
<p><img class="alignnone size-full wp-image-295" title="remove_range_beginning" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/remove_range_beginning.png" alt="remove_range_beginning" width="461" height="176" /></p>
<p>Now after updating, the headers are all correct:</p>
<p><img class="alignnone size-full wp-image-297" title="good_range_result" src="http://in-tools.com/wordpress/wp-content/uploads/2009/12/good_range_result.png" alt="good_range_result" width="296" height="123" /></p>
<p><strong>There you have it! Simple as pi! <img src='http://in-tools.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://in-tools.com/wordpress/indesign/plugins/power-headers/composite-headers-never-before-possible/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
