12 Replies Latest reply on Jan 27, 2012 8:07 AM by Peter Spier

    Grep & fractions

    dawhyman

      Hi All

       

      I searched everywhere to solve this one, but can't get the answer to my specific needs - I'm close to solving it but now I'm lost.

       

      I want a grep to style a fraction within a paragraph style, the font I use is Swiss, and it's not open opentype and I'd rather not use a script or use find/replace with grep.

       

      The text comes into me typically in this format : 11/2

      I've put a hair space in after the first digit and set grep to know not to format it. I've set up two character styles one for the upper fraction and one for lower. The grep pane looks as follows:

       

      Apply style: None

      To Text: ~|

       

      Apply style: Upper

      To Text: \d+/

       

      Apply style: Lower

      To Text: /\d+

       

      What I get kind of works,  see below, except the fraction slash is being styled as the lower fraction number-I need it to revert to normal text.

       

      If anyone has crackedPicture 1.png this or can help I'd appreiciate it.

       

      Many thanks

      D

        • 1. Re: Grep & fractions
          Peter Spier Most Valuable Participant (Moderator)

          I think there's an old thread about this someplace, but here's where I think you are going wrong.

           

          You don't need to apply any style to the space, so there's no need to find it at all. Nor do you want to apply a style to the slash. Instead you want to use look behind and lookahead.

           

          For the numerator find (?>=\|)\d+(?=/)  You don't really need both the lookahead and the look behind, but you need at least one of them, and without the lookbehind you could be formatting dates.

           

          For the denominator (?>=/)d+ Unfortunately I can't think of a way that this won't affect dates, so the lookbehind above may be moot, and you need to be careful that you don't actually have any dates in the paragraphs that have this style.

           

          I suppose you could add one more GREP style /\d+/\d+ to find any three-part dates and apply character style none to fix them, but it won't help for dates with only one slash. Maybe one of the real GREP experts has a better idea.

          • 2. Re: Grep & fractions
            Eugene Tyson Adobe Community Professional & MVP

            Will find fractions, but not dates.

             

            ((?<!\d)(?<!/)\d+)(/)((?!11)(?!0)(?!9)\d{1,3}(?!/)(?!\d))

            • 3. Re: Grep & fractions
              dawhyman Level 1

              yes, I've searched everywhere,but couldn't find. I've played with the look behind/forward but couldn't quite get it to work.

              So I copied & pasted (?>=\|)\d+(?=/) against my Numerator character style and (?>=/)d+ for my denominator style and I got no changes-am I missing something?

              • 4. Re: Grep & fractions
                dawhyman Level 1

                Eugene

                 

                Thanks for this, it does successfully find the unformatted fractions in the find/grep dialogue box. This will be handy to run at the end of a document - do you not know of a way to build it into a paragraph style?

                 

                regards

                D

                • 5. Re: Grep & fractions
                  Eugene Tyson Adobe Community Professional & MVP

                  Jeepers ??

                   

                  Hmm having a hard time imagining what it is you're tyring to do?

                   

                  Can you simplify the process..

                  • 6. Re: Grep & fractions
                    dawhyman Level 1

                    I know - it's difficult to explain, hope this helps.

                     

                    Picture 3.png

                    The correct formatting of the quotation mark would be a bonus, but I'd happily settle with just the fraction bit....:-)

                     

                    Picture 4.png

                    • 7. Re: Grep & fractions
                      Peter Spier Most Valuable Participant (Moderator)

                      Eugene, the problem is that the font in question does not have a Fractions alternate, so you can't find numereator and denominator at the same time and make the change.

                       

                      dawhyman,

                       

                      Sorry, I posted without testing and used the wrong metacharacter for the lookbehind. That expression should be (?<=~< )\d+(?=/) if you are looking for a thin space.

                      Seems I also left out a backslash in the expression for denominators, which should be (?<=/)\d+

                       

                      The date-finder expression works, though.

                      • 8. Re: Grep & fractions
                        Eugene Tyson Adobe Community Professional & MVP

                        Just need another one for the dates

                         

                        *edit sub "roman" char style for "no script" in Character Style name

                        Set the Position to "Normal" in the dates "no script" character style.

                         

                        (i called it roman in mine but technically this should only be for text with roman style, i.e., no bold or italics)

                        roman.jpg

                        • 9. Re: Grep & fractions
                          Peter Spier Most Valuable Participant (Moderator)

                          dawhyman wrote:

                          The correct formatting of the quotation mark would be a bonus, but I'd happily settle with just the fraction bit....:-)

                          How did you want the quotation mark formatted? If you mean to use a doouble straight quote instead of curly typographers quote, I don't think that can be done with a style so you'd need to run a find/change.

                          • 10. Re: Grep & fractions
                            Peter Spier Most Valuable Participant (Moderator)

                            Eugene Tyson wrote:

                             

                            Just need another one for the dates

                             

                            *edit sub "roman" char style for "no script" in Character Style name

                            Set the Position to "Normal" in the dates "no script" character style.

                             

                            (i called it roman in mine but technically this should only be for text with roman style, i.e., no bold or italics)

                            roman.jpg

                            I think here you really want to apply [None] so the text in the date takes on the underlying basic formatting defined in the paragraph style. And as I said this only works for month/day/year or day/month/year constructs. I can't think of a way to differentiate a day/month or month/day from a legitimate fraction, except perhaps with a negative lookbehind for that thin space, which would mean that all fractions would need to have thin spaces, even if they have no integer component, and you'd need one more grep style, and as it turns out in my just now attempted test it doesn't seem to work anyway. I can't get it to not find fractions if they have more than one digit in the numerator...

                            • 11. Re: Grep & fractions
                              Eugene Tyson Adobe Community Professional & MVP

                              Perhaps - in that case change the date naming convention to something else lol.

                               

                              There's only so much a GREP search can do.

                              • 12. Re: Grep & fractions
                                Peter Spier Most Valuable Participant (Moderator)

                                Exactly.

                                 

                                Sometimes users expect the unreasonable, and it's important to point out, I think, that when you are using GREP you are looking for a pattern, and that pattern mightnot be restricted to just the text you want to change, so you might be building in som unwanted changes at the same time. Computers are a lot dumber than they seem, but very cooperative. They just do what they are told.