8 Replies Latest reply on Dec 13, 2012 12:54 PM by Peter Spier

    How to find digits preceded and/or followed by character style sheet

    polifilo Level 1

      Hello everybody, I need help with a GREP search.

       

      I have to format all digits of a book in a small caps style. The style changes whether the digits are italic or not.

      I need to find all the digits surrounded by italic already formatted in the regular-digit style, and set them in the correct italic-digit style.

       

      Is it possible to find digits:

       

      - preceded by italic

      - followed by italic

      - preceded and followed by italic?

       

      Thank you!!!

        • 1. Re: How to find digits preceded and/or followed by character style sheet
          Peter Spier Most Valuable Participant (Moderator)

          I doubt that you really mean small caps for digits, but perhaps you do. Old Style Figures, if available in the font, are designed for use in running text.

           

          It's not really clear whether the digits themselves are also already italic or whether you want to format all digits, or only those that are preceded or followed by italic text (and would the spaces, if there are any also be italic?) It may be enough to just find digits, but I think we need more information.

          • 2. Re: How to find digits preceded and/or followed by character style sheet
            polifilo Level 1

            Hello Peter, yes, "small caps" is the "old style figures" style.

             

            In a first step I formatted all the italic digits with the "italic old style" character style, then I formatted automatically all the other digits in the "regular old style figures" character style. I don't know why, but some digits that I want in italic are still in regular style, so I need to search the whole book to correct this strange mistake.  

            Unfortunately the digits I have to set in "italic old style" are not formatted within an italic paragraph style, so I can't do a normal text search.

            The question is: in order to do that rapidly and automatically, can I use the GREP search?

            • 3. Re: How to find digits preceded and/or followed by character style sheet
              Peter Spier Most Valuable Participant (Moderator)

              Yes, but not easily. It would make more sense to do it with styles.

               

              Does your font have old style figures? Is it an OpenType font? If so, add the figure style to the paragraph style. How are you aplying the italics? Is that a new paragraph style, or a character style? If it's a paragraph style, specifying the OSF in the definition should also work, and if OSF is specified inthe underlying style applying an Italic character style (same one you would apply to any other text) should switch to the italic font style and preserve the figures as oldstyle.

               

              I think you're overthinking this...

              • 4. Re: How to find digits preceded and/or followed by character style sheet
                Peter Spier Most Valuable Participant (Moderator)

                You might find this other thread helpful: http://forums.adobe.com/message/4894867#4894867

                1 person found this helpful
                • 5. Re: How to find digits preceded and/or followed by character style sheet
                  polifilo Level 1

                  Thank you for the reply Peter...

                   

                  Actually, I'm using three different fonts: one for the regular and italic text, one only for the italic digits and one only for the regular digits... No Open Type. 

                  The italic is applied with a character style... (The wrong figures within the italic paragraph style were easy to find and resolve, and I have already done it).

                   

                  Yes, maybe it's a little bit "overthinking", but I'm interested in learning the GREP searches, so I'd like to find here a solution with the GREP search...

                   

                  Can you suggest the steps to follow? I don't know the code yet...

                   

                  Thank you!

                  • 6. Re: How to find digits preceded and/or followed by character style sheet
                    Peter Spier Most Valuable Participant (Moderator)

                    If you read the other thread I suggested you'll see the basic method of finding text that is preceded or followed by text that carries a particular format. Jongware's solution is very elegant, but I don't believe it will work in this case becasue you are trying to find digits that do not carry the same formatting  as the surrounding text. To me that means what you need to do is find the last italic character followed by a digit, or the first one preceded by a digit, and mark these in some way so that you can then find the digits in between.

                     

                    .(?=\d) finds the last character befor a digit, and (?<=\d). finds the first character after one, but these are not necessarily the expressions you want to use sin the . (dot) matches everything, including other digits, punctuation, and whitespace. You would want to make sure, too, that the find formatting is set to Italic.

                     

                    [\u\l[:punct:]](?<=\d) and  (?=\d)[\u\l[:punct:]] would limit the found characters to upper and lower case, and puctuation, but would not find any white space. That's why I asked in my first reponse about whether there was space before or after the digits. I think you can see that making this work for all the cases you might encounter, but not find things you don't want to find, is getting to be pretty complex, and that's only the first part.

                     

                    So far you're finding the text surrounding the digits, not the digits themselves, and you need to create a tag of some sort to mark these locations then, if <tag> stands for the tag you've added you would replace with $0<tag> or <tag>$0 as appropriate for the tag befor or after the digits. Now you can look for (<tag>)(\d+)(<tag>), set the change formatting to your italics, and replace with $2, or if you have cases where the italics are only before or after the digits you can leave off one of the (<tag) sub-expressions and adjust the change expression to remove the remaining tag.

                    1 person found this helpful
                    • 7. Re: How to find digits preceded and/or followed by character style sheet
                      polifilo Level 1

                      Sorry Peter, I didn't see the link before...

                       

                      I think this is the best solution:

                       

                      Find (?<=[\u\l\d[:punct:]]) (?=[\u\l\d[:punct:]]) in italic and change (for example) with a red X. Then find remaining italic white spaces (which are just before and after elements formatted with different character styles)... You can easily isolate and correct wrong figures. This procedure is not completely automatic but it is the best one to save time... What do you think?

                       

                      In your last reply perhaps you made a mistake (I'll tell you just to know if I'm learning well). I think that (?<=\d)[\u\l[:punct:]] and [\u\l[:punct:]](?=\d) are correct, aren't they?

                       

                      Thank you very much for your help

                      • 8. Re: How to find digits preceded and/or followed by character style sheet
                        Peter Spier Most Valuable Participant (Moderator)

                        You're right, I flipped the order on the look-ahead and look-behind.

                         

                        Find (?<=[\u\l\d[:punct:]]) (?=[\u\l\d[:punct:]]) is going to find practically all regular word spaces (give it a try and see), and I don't think that's waht you were tryig to do....