12 Replies Latest reply on Aug 27, 2016 6:30 PM by Cari Jansen

    Character styles shifting with replace all

    office-goth

      I've found what appears to be a bug and I haven't been able to find any discussion about it.

       

      When I use the "change all" function, and paragraphs that have character styles applied to the first letter of a paragraph are affected by the change, my character styles in the entire paragraph shift to the right by one character. For example, In a paragraph where an italic character style has been applied:

       

      Felis catus and Felis silvestris are two species within the genus Felis.

       

      would turn into:

       

      Felis catus and Felis silvestris are two species within the genus Felis.

       

      Today I was using the GREP search window to search for paragraphs that had multiple hard returns above them, indicating that a client wanted some space there. I replaced what I found with the same paragraph, no hard returns, changing the paragraph style to a style that had a space before value. I'm kind of a freestyle GREP hack and I forget exactly what I was doing and  but my search was something like: (\r)\r+(.+) and I replaced with $1$2 plus changed the paragraph style.

       

      Has this happened to anyone else? Does anyone have any ideas about how to shift my styles back over by one without manually going through every single character style in my document?

        • 1. Re: Character styles shifting with replace all
          Cari Jansen Adobe Community Professional

          hi office-goth,

           

          It's difficult to give you a conclusive answer on the behaviour you are seeing, without some additional screenshots and information.

           

          But there's is an alternate way to remove blank paragraph returns:

          • In the Find/Change dialog box, select Multiple Return to Single Return from the Query menu.
          • What you'll see is that you don't need find all the text in the paragraph (.+) in your query and then 're-insert' it again.
            grep-multi-return.png

          I'd recommend you use that query to remove blank lines and it will likely fix some of the issues you are seeing.

           

          Also: how are you setting the character style to the first letter of the paragraph? Easiest way to do this is probably using a Nested style (Paragraph Style Options:

          1. Select style in Paragraph Styles panel, and select Style Options from the panel menu.
          2. Click Drop Caps and Nested Styles in the list on the left
          3. Then click New Nested Style, and set as follows:
            dropcap-nested-style.png

          Hope this helps,

           

          Cari

          1 person found this helpful
          • 2. Re: Character styles shifting with replace all
            office-goth Level 1

            Thanks Cari!

             

            I appreciate your response.

             

            This solution doesn't completely address my conundrum because I'm not really having a problem figuring out how to remove extra hard returns, I'm having a problem with character styles shifting. Removing the extra hard returns isn't the primary aim of my query; they are placeholders that identify where I need to apply a different paragraph style and the variables I used to target my paragraph.

             

            Now that I think about it, I think my client put a space before the second hard return and that I was searching for ^\s\r(.+), not (\r)\r+(.+), because I definitely didn't want to apply the new paragraph style to the previous paragraph, and the query I described above would have done so. Whoops! I do a tremendous amount of document cleanup of this nature using GREP on the daily so it is hard to keep track of exactly what I used when!

             

            I need to make sure that the paragraph following the hard returns is restyled with a new style. The ^\s\r indicated a scene change in the body text of a book. I need to identify where this pattern occurs, remove the clutter, and style the paragraph following (removing an indent and adding space before) in one fell swoop. Or even in multiple stages, it doesn't matter, but one way or another, the paragraph after the returns needs to be found and restyled, and I'd prefer to do that with a change-all rather than going through the document change-by-change.

             

            As I mentioned, the character styles do not shift when I go through change-by-change. I think this is a bug!

             

            Using a nested style to italicize text is a great suggestion but unfortunately not a solution in this case, because these are not paragraphs that uniformly need to have italics at the beginning line. I'm not making a decorative paragraph start, I'm just styling regular old body copy that happens to have a lot of italics, and happens to sometimes begin a paragraph with italics, so it's important that the character styles remain in use. The italics are used to italicize latin words in the paragraph. Sometimes the first word of the paragraph is italicized, sometimes the first five words, and there are italics elsewhere in the paragraph, too. ALL the italics in the paragraph shift over by one character when I use a global find and replace command.

             

            At this point, the damage is done, and I'm most interested in figuring out an efficient way of shifting the character styles back by one character, into their original position, and secondarily in discovering whether there's a way of avoiding the shift in the first place. Like maybe if the entire paragraph weren't selected? How should I target the paragraph instead? I haven't found anyone else with this problem, but I encounter it regularly, it seems like anytime I target an entire paragraph with a replace-all command (and never when I go through the document change-by-change).

            • 3. Re: Character styles shifting with replace all
              Cari Jansen Adobe Community Professional

              Fixing the issue is not so easy I think. (I'm at work at the moment (9am here), so apologies for not being able to respond until after work today to any replies you might have, hopefully some other forum-helpers can step in in the meantime.).

               

              I don't think you are necessarily seeing a bug, it's more likely one of the GREP that caused the issue (not that knowing that helps you fix the current document, right now - sorry!). Difficult to replicate for me, as can't see what the sequence of steps is that let to the issue.

              It could be that you  might have had 'Italics' option (Character Style) selected in the Find Format (More Options in Find/Change dialog box) when you performed the find.  If you want some help reviewing why the issue happens can you:

              • tell us the sequence of steps used for formatting the text.
              • e.g. apply paragraph style, apply character style to all latin terms, then
              • apply the following GREP to remove the blank paragraphs (and share a screenshot of the full dialog box, with the More Options visible.

               

              You can try using the following GREP to find all the Italic strings throughout your text and then fix that first character issue manually (still painful process I know) :

              1. Find What:  .+
              2. Find Format: Character Style: Italic (or the style name you used).
              3. Only click on Find Next to highlights the Italic strings in your text, you can then select the character in front, and if you  apply a keyboard shortcut to 'applying Italics' character style, you can then fix the first character.

               

              Cari

              • 4. Re: Character styles shifting with replace all
                Laubender Adobe Community Professional & MVP

                Hi office-goth,

                every time you work with $1$2 in the replace field and something was between the two groups you have this problem.

                Formatting will shift.

                 

                Example working with replacement groups:

                 

                Find:
                (a)b(c)

                 

                Replace:
                $1$2

                WorkingWithReplacementGroups-GREP.png

                 

                The problem is not the first replacement group here. You could go on and replace it with itself.
                The problem is the second replacement group.

                 

                GREP will always move the unformatted content of the second replacement group in place of the formatted "slot".

                So it would be always better not to touch the second group at all by using a "Positive Lookahead" that works like an if.
                In my case: If a c would come after the b, then remove the b.

                 

                Search for:

                (a)b(?=c)

                 

                Replace with:

                $1

                 

                Or you could even not touch the first group and work with a "Positive Lookbehind" and a "Positive Lookahead" to get a positive "lookaround":

                 

                Search for:
                (?<=a)b(?=c)

                 

                Replace with nothing (field is empty)

                 

                WorkingWithPosLookbehindPosLokkahead.png

                 

                 

                 

                 

                 

                The problem with that could be, that you want to find a flexible number of things before a desired thing you want to work with.
                A Positive Lookbehind cannot find anything with a flexible pattern in InDesign's implementation for GREP. A Positive Lookahead would be ok in this regards.

                 

                That would find nothing at all:

                (?<=a+)b(?=c+)

                 

                Fortunately an undocumented GREP feature, implemented since InDesign CS6, comes to the rescue:

                \K

                 

                Here \K is working as a flexible Positive Lookbehind for find:

                a+\Kb(?=c+)

                 

                Replace with nothing (field is empty)

                 

                Example for working with a flexible "positive lookbehind" using \K and two text frames in one go:

                 

                UsingKAsPositiveLookbehind-1.png

                // EDIT: Sorry. I had to replace my screenshot with a flexible pattern. Instead using a I now used a+

                 

                Regards,
                Uwe

                2 people found this helpful
                • 5. Re: Character styles shifting with replace all
                  Laubender Adobe Community Professional & MVP

                  office-goth wrote:

                  At this point, the damage is done, and I'm most interested in figuring out an efficient way of shifting the character styles back by one character, into their original position

                  That's a tougher question, if you have no backup with the old version of the text where the replacement was not done.

                  Without seeing the whole document I have no answer for that. And it will require a lot of work.

                   

                  Regards,
                  Uwe

                  • 6. Re: Character styles shifting with replace all
                    office-goth Level 1

                    I definitely wasn't searching for italics. Again, I am not having a problem figuring out how to remove the blank paragraphs.

                    Unfortunately I didn't document the process and I've moved ahead with the file so I'll have to let this one go this time! Really appreciate your engagement!

                     

                    Definitely looks like I'll have to search for all the italics character styles and manually apply the italics to the first character, and remove it from the last character that picked up the style.

                    • 7. Re: Character styles shifting with replace all
                      office-goth Level 1

                      Hey Laubender

                       

                      This discussion is definitely getting somewhere and I'm learning some new things. Thanks so much!

                       

                      I do think a positive lookbehind would probably have helped me avoid the shift nonetheless, and that going forward I'll take two sweeps when tackling this kind of cleanup: first replacing the paragraph styles and then cleaning up the clutter. I didn't know about \K! Excited for my next chance to put it into use!

                       

                      In my reply to Cari Jansen above, I noted that I had made a mistake relaying the GREP that I used in my original post—I'm troubleshooting after the fact because I didn't notice the error right away. I thought I had been replacing with $1$2 but I was actually just deleting ungrouped content previous to one group: I was searching for ^\s\r(.+), not (\r)\r+(.+), and replacing with $1. So I'm trying to delete ungrouped content and apply a new paragraph style to a group.

                       

                      I think it does have something to do with what you're talking about, the formatting applied to deleted content getting picked up by the group (in this case the group losing formatting because the previous paragraph had no character style), and I guess I can accept that this is just the way GREP is but I have trouble understanding why I would not see the same behaviour when going the the document change-by-change. It only shows up when I change all.

                       

                      I also have trouble understanding why my character styles would shift over by one. It's not only a matter of the italic character style being dropped on the first letter of the paragraph, all the italics in the entire paragraph are basically "misaligned". I'll show you what's happening here using bold because it's easier to see:

                       

                      Bolded paragraph start with bold elsewhere in the paragraph

                       

                      becomes

                       

                      Bolded paragraph start with bold elsewhere in the paragraph

                       

                      I wish I had some screenshots of the process to share so it would be easier for you guys to understand what's going on, but this is an issue I discovered after the fact so now I'm just trying to avoid the same problem in the future.

                       

                      I think you're right that manual is the only way to go with fixing it up! Oh well.

                       

                      Thanks so much for all your help!

                       

                      • 8. Re: Character styles shifting with replace all
                        Laubender Adobe Community Professional & MVP

                        Sorry. Had to delete my answer. Wrong example…

                        I'll come back.

                         

                        Uwe

                        • 9. Re: Character styles shifting with replace all
                          Laubender Adobe Community Professional & MVP

                          Here we go:

                           

                          GREP-not-using-vs-using-PositiveLookahead.png

                           

                          In this one the added text on the left side is in italics.
                          Using a Positive Lookahead on the right side results in not-italic text.

                           

                          Now this is a puzzle, isn't it?

                           

                          Best,
                          Uwe

                          • 10. Re: Character styles shifting with replace all
                            office-goth Level 1

                            @Laubender

                             

                            Ha, mysterious.

                             

                            Well, it doesn't make my problem go away, but at least now I know that's just the way it is.

                             

                            Thank you for the illumination!

                            • 11. Re: Character styles shifting with replace all
                              Obi-wan Kenobi Adobe Community Professional

                              [Just for comment // Week-End!]

                               

                              A long time ago [ … and I know what you think: … "in a galaxy far, far away" !  ], I asked myself how it inverse cooly some chars groups with different applied char styles like here (above, the beginning; below, the result):

                               

                              Capture d’écran 2016-08-26 à 22.32.41.png

                              Capture d’écran 2016-08-26 à 22.34.16.png

                               

                              Just one and same click!

                               

                              (^/)

                              • 12. Re: Character styles shifting with replace all
                                Cari Jansen Adobe Community Professional

                                If you want to learn more about Lookaheads and Lookbehinds, I wrote a series of tutorials about it some time ago:

                                 

                                There's also a PDF you can download that has GREP basics in it, that I created for InDesign user group at some point.

                                 

                                Cari

                                1 person found this helpful