Tuesday, December 6, 2011

More help with GREP needed

I have been attempting to create some nested styles.



So far, I am getting the hang of it.



I have created a grep style that will make all text after the word ''NOTE: '' into italic. Also, I have grep style that makes all text that is ''FIGURE +\d+\d'' into bold text.



The problem I have is that if the word ''FIGURE '' etc. is in the italicized note text, then it will not become bold.



For example: ''Operate the switch to begin the process (FIGURE 3-3). Make sure guards are closed (refer to FIGURE 3-1).''



That works fine, and ''FIGURE '' is bold. However, when I change the sentence by adding ''NOTE: Make sure guards... '' it all becomes italic, and I loose the bold on ''FIGURE 3-1''



So, is there a way to augment my italic grep with some kind of inclusion... as if I were saying ''if ''FIGURE +\d+\d'' make that is bold italic''



sorry for the long-winded attempt to describe what I want to do.



Thanks in advance for help.



RPP
More help with GREP needed
(Trying to work it out in my head:) Alas -- I see no way of doing it with a GREP style

i alone.



It is possible to find ''FIGURE'' in any paragraph somewhere after ''NOTE'' (a simple ''NOTE.*FIGURE\s\d+'') but you cannot isolate just the ''FIGURE'' text to specify bold italic.



(Tried it.) wait a minute ... No, you cannot specify ''the text FIGURE in italics'', as you can in regular GREP Find.
More help with GREP needed
I'm still fairly new and clueless with GREP and particularly with GREP styles. Could this be done with TWO GREP styles in the proper order, i.e. do the italics first, then do the bold?



Peter

No. There seems no way to distinguish between occurrances of ''FIGURE''

i before

and

i after

the text ''NOTE''.



The 'after' case can be found with Find using ''NOTE.*FIGURE'', but you cannot use this in the GREP style -- it would apply the style to the entire found string. You cannot use Look Behind (i.e., 'finding FIGURE with preceding NOTE') because you need wildcards inbetween, and those do not work in combination with Look Behind. And if you

i could

somehow evade these problems, the search ''NOTE (anything) FIGURE'' will only find one single occurrance of 'FIGURE'.



I did some quick tests, the only way I found is to insert an invisible unique character in the 2nd FIGURE texts. So I inserted a No-Joiner ('no joy') after the 'F', and the GREP style



%26gt;F~qIGURE\w\d+(-\d+)*



picked it up for the 2nd round of styling. Then again, if you are adjusting by hand, you might as well apply the formatting by hand.

what if you duplicate your FIGURE grep rule and set it to work on italicized text only ?



so you will have 3 GREP rules:

1) FIGURE_bold - should be run first

2) NOTE - will set to italic

3) FIGURE_bold_italic - set to work only on italicized text and set bold+italic



robin



--

www.adobescripts.com

Sorry, Robin,



%26gt;wait a minute ... No, you cannot specify ''the text FIGURE in italics'', as you can in regular GREP Find.



-- you can specify just a GREP rule and a character style to use. No formatting in the GREP rule allowed.

so ... your InDesign is broken ;)

because when I run GREP rule - in ID CS3 and ID CS4 - with option to replace only on italicized - as local formatting - texts ... it works fine :)



EDIT1: and works fine on texts modified by NestedStyles

EDIT2: and you can save this rule for later use ...



robin



--

www.adobescripts.com

You probably want the note to be italic only when the paragraph starts with NOTE: -- correct? If that is so, apply your italic style to

%26gt;^NOTE:.+



(The ^ means ''beginning of paragraph.)



Robin: you're talking about the Find?Change dialog, R. Pollack and Jongware talk about nested GREP styles, in which you cannot specify formats for searching.



Peter

thanks Peter, my fault, sorry :(



I need to read more about CS4 ;)



robin



--

www.adobescripts.com

Robin,



%26gt;GREP rule - in ID CS3 and ID CS4



is where you got sidetracked ;-)



Peter, it's a bit more complicated than that. The OP wants everything

i after

a ''NOTE'' italicized until the end of paragraph. That's what the GREP rule



%26gt;NOTE.*$



does (anywhere, not just at the start of a paragraph). However, both before and after the NOTE, there might be ''FIGURE xx'', and he wants these bold in the regular text and bold italic after the NOTE text. I can see no way of isolating FIGURE 'somewhere after a NOTE', neither a single one nor all of them. The GREP rules apply to

i all

occurrences of ''FIGURE''.

I want to thank those who responded to my question.



I am just learning, attempting, to create some nested styles.



I can see that to have one style over-ride another is not possible in this fashion.



I am fine with the ''Note: '' part being italic and having to manually bold the ''FIGURE XX'' if it should fall within a noted sentence. That will require a manual over-ride. I am now only concerned with whether or not over-rides of any type are maintained as long as the over-ride is not cleared. Or will the GREP clear all over-rides when I build a book and synchronize styles.



I will have to test this in all my nested styles.



Thanks again to all who responded.



RPP

jong,



You're right, I misread RPP's post.



RPP,



I think that what you want can be done as follows. Given this paragraph:

%26gt;Operate the switch to begin the process (FIGURE 3-3). NOTE: Make sure guards are closed (refer to FIGURE 3-1).



and two character styles, ''bold'' and ''italic'', add two nested GREP styles:



Apply ''italic'' to (?%26lt;=NOTE:\s).+

Apply ''bold'' to FIGURE\s[-\d]+



Italic is applied to everything following NOTE: (but NOTE: is not italicised), bold is applied to FIGURE followed by any sequence of digits and hyphens.



It is important that the GREP styles are applied in this order. Reverse the order in this example and it won't work. Also note that character styles applied by GREP styles don't cancel each other out, as they do when applied straight from the character style panel.



Peter

Which is what I thought I was suggesting in post 2. :)



Peter S

So you did!

I'd love to say ''great minds think alike,'' but I doubt mine's in the same class as yours. Must be the name. :)

Granted, it solves one half of the problem. But I see no way to achieve the OP's request of making them bold italic.

Ah yes, Bold and Italic at the same time. Can one search for styles in a grep style? Then you could search for italics, a bold figure, followed by italics, and change that to a third, bold italic character style.



Perhaps this could be done at the end with a regular find/change?

Hello folks,



I got close! I couldn't make GREP do it. But, what do you think of this nested-style-only solution?



None through 1 (

Bold up to 1 )

None up to 1 N(

Italic up to 1 (

Italic through 1 (

Italic through 2 Words

BoldItalic up to 1 )

Italic through 1 )

None through 1 Forced Line Break



Mike Witherell in Maryland

PostScript: GREP styles seem to trump nested styles? Would that be a valid observation?

Um, perhaps I should have said Nested styles appear to trump GREP styles!

Here is a GREP style solution that appears to work:



Apply Style: Bold

To Text: negative lookbehind=to\s(FIGURE\s[-\d]+)



Apply Style: BoldItalic

To Text: positive lookbehind=to\s(FIGURE\s[-\d]+)



Apply Style: Italic

To Text: (positive lookbehind=:).+(positive lookahead=\()



Mike Witherell in Maryland

Oops! This one is better!



Here is a GREP style solution that appears to work better:



Apply Style: Bold

To Text: negative lookbehind=to\s(FIGURE\s[-\d]+)



Apply Style: Italic

To Text: (positive lookbehind=:).+(positive lookahead=\F)



Apply Style: BoldItalic

To Text: positive lookbehind=to\s(FIGURE\s[-\d]+)



Apply Style: Italic

To Text: \)(?=\.\r



Perfect!!

(Man, this is addictive!!)



Mike Witherell in Maryland

Mike, I'm having a hard time getting

i any

results at all. Perhaps that's because copying



%26gt;negative lookbehind=to\s(FIGURE\s[-\d]+)



into the To Text field does nothing. I tried with the Negative lookbehind marker



%26gt;(?%26lt;!to\s(FIGURE\s[-\d]+))



(and adding an extra parenthesis), but no luck. Same goes for the other expressions.

Jongware,



I wrote negative lookbehind and positive lookahead so it wouldn't foul up on display in this forum. Maybe if I use html special characters as I type this, it will display.



Looks to me like you should move the parenthesis to write this way:



(?%26lt;!to\s)(FIGURE\s[-\d]+)



Best to you,



Mike Witherell in Alexandria, VA

OK, using html special character codes allow me to write complex GREP stuff into the Message window!



Mike

Wow, Thanks for all the responsed.



I will give this a try tonight and let you all know how it works out.



Thanks again.



RPP

Mike,



I am just learning and trying to get the hang of this ''magic.''



Here is what I have right now:



Apply Style: BOLD UPPER

To Text: figure \d+~~+\d



Apply Style: BOLD UPPER

To Text: FIGURE \d+~~+\d



Apply Style: ITALIC

To Text: NOTE:.*$



This works ok, except when the ''FIGURE 3-2X'' falls inside of the noted text. I do not quite understand the ''positive lookbehind'' and ''negative lookahead''



It seems like what I need is something like:



Apply Style: BOLD ITALIC UPPER

To Text: (ok, here's where I'm stuck)



as if to say... when you get to the end of the paragraph, work backwards, and if you get to ''FIGURE 3-24'' and it is italic, make it BOLD ITALIC UPPER.



Suppose I have a paragraph that reads something like this:



''Look at FIGURE 3-24 (BOLD UPPER). NOTE: Refer to FIGURE 3-27 for additional information'' [where ''NOTE:... is italic, and FIGURE 3-27 contained within the italic sentence is italic but needs to be (BOLD ITALIC UPPER)].



Thanks for you info. And by the way, I have downloaded your GREP list info from your web site and it is extremely helpful in trying to learn this ''magic.''



RPP

RPP,



The trouble is that in GREP style you can find text but not formatting, so you can't say something like ''find FIGURE only when it's italic''. In the Find/Change dialog you can, but in GREP styles you can't.



You also can't say ''look for FIGURE if it's preceded by NOTE: and any characters in between''. Unfortunately, lookbehind can't cope with variable-length text. So if you always have ''NOTE: Refer to FIGURE ...'', then you can use lookbehind and you set-up would be this:



apply italic to FIGURE [-\d]+

apply bold to NOTE:.+

apply bold-italic to (?%26lt;=NOTE: Refer to )FIGURE [-\d]+



The first parenthetical is a lookbehind: in this case, FIGURE looks behind, meaning you find FIGURE only when it's preceded by ''Note: Refer to'', which is not matched itself. So bold italics would be applied only to FIGURE [-\d]+, and only when preceded by ...



But you're not likely to have such fixed text. When you have just a few alternatives, you can list them as alternatives, so if you always have ''Note: Refer to '' or ''NOTE: See '' you could salvage your set-up, but with more than let's say three alternatives it gets messy.



(?%26lt;=NOTE:.+? )FIGURE [-\d]+ , which you would hope would match any text from NOTE: to FIGURE, doesn't work as a lookbehind.



Peter

Hey RPollack,



I would like to take the occasion to beg you to not overdress the text. I am a big fan of minimal seasoning on the typesetting. Keep that in mind, won't you? Sometimes a change of one's mind is the answer.



Mike Witherell in Alexandria, VA

MIke,



I understand what you mean. We write operator manuals for equipment. We use very little variations: Body, Bullets. FIGURE numbers bold-upper. Notes italic. That's pretty much it.



It is rare that we would have ''FIGURE'' inside a ''notes'' sentence. And even more rare that I would have a paragraph with FIGURE in the first sentence of the paragraph, with a follow up FIGURE reference in a ''Note:'' sentence at the end of the paragraph.



I was just trying to cover those instances, if it is possible. If not, I can override those few instances.



I have noticed that I set up my grep style for ''FIGURE'' numbers differently than you and Peter (in previous post). I have to study the differences. Did I do it wrong? It seems to work.



Thanks so much for all the suggestions.



RPP

RPP,



Your GREP FIGURE +\d+\d works (or seems to work) in that it finds FIGURE followed by one or more spaces ( +) followed by one or more digits (\d+) followed by one digit (\d). It would therefore not match FIGURE 2-3, but it would match FIGURE 2. Your GREP style would therefore apply the character style to only part of what you were hoing to match.



The GREP that Mike gave, FIGURE [-\d]+ , matches FIGURE followed by any sequence of digits and hyphens -- so it would match FIGURE 2-3.



Peter

No comments:

Post a Comment