8 Replies Latest reply on Sep 26, 2014 7:01 PM by Colin Flashman

    How to fix faux subscripts/superscripts made with baseline shifts

    Colin Flashman Adobe Community Professional

      Hello all.

       

      There is a script on the forums used to convert locally formatted styles to character styles – Preserve Local Formatting script and CS4

       

      It is a brilliant script, but as I have unexpectedly found out (and would have found out if I read the post in more detail) is that any "faked" sub/superscripts created with baseline shifts won't work. To quote the other thread:

       

      The script searches for attributes such as "superscript", "subscript", "small capitals". If small caps are faked in the document with capitals in a smaller font, the script will not find them. If superscript or subscript are faked in the document with a smaller font size and some baseline shift, the script will not find them.

       

      Initially I didn't think this would ever be a problem... I thought "who the hell would make a subscript or superscript like that? wouldn't they just click the subscript or superscript buttons?"... unfortunately, no!

       

      I thought a solution would be to make a GREP that could be added to a findchangebylist script that ships with InDesign. First thing to do would be to create a GREP to look for any positive baseline shift and change it to superscript; and a GREP to search for any negative baseline shift and change it to a subscript. Sounds simple... until I tried to implement it, as the dialog won't take a + or - by itself... it has to be a proper value.

       

      Has anyone else faced this issue, and if so, what was the solution/outcome?

       

      Colin

        • 1. Re: How to fix faux subscripts/superscripts made with baseline shifts
          Peter Spier Most Valuable Participant (Moderator)

          Interesting problem, and I don't have the answer, but I would attack it by scripting (which I don't do) and look for baseline shift > 0 to make superscript and baseline shift < 0 for subscript. this will of course have it's own set of problems if there is other text that's been shifted.

          • 2. Re: How to fix faux subscripts/superscripts made with baseline shifts
            Colin Flashman Adobe Community Professional

            I found this on the InDesign scripting forum and I believe it will yield the answer. As I am at work while writing this I can't confirm as answered as I have to determine what parts of the script will be needed to create the solution.

             

            [JS] [CS2] removing baseline shift - Performance problem

             

            Colin

            • 3. Re: Re: How to fix faux subscripts/superscripts made with baseline shifts
              Colin Flashman Adobe Community Professional

              OK, that last forum link I referred to did have the trick... kind of. Just had to modify the script that was used.

               

              The script below will find any baseline shift greater than 0 and apply a local superscript format; and any baseline shift less than 0 and apply a local subscript format.

               

              for (var j = app.activeDocument.stories.length - 1; j >= 0; j--) {
              myCharacters=app.activeDocument.stories[j].characters.everyItem().getElements()
              var color = myCharacters[j].fillColor.name;
              for (var h = myCharacters.length- 1; h >= 0; h--) {
                if (myCharacters[h].pageItems.length < 1){
                    if (myCharacters[h].baselineShift > 0){
                         myCharacters[h].baselineShift = 0;
                         myCharacters[h].position=Position.SUPERSCRIPT
                         }
                    if (myCharacters[h].baselineShift < 0){
                         myCharacters[h].baselineShift = 0;
                         myCharacters[h].position=Position.SUBSCRIPT
                         }
                    }
                 }
              }
              
              

               

              From here, the good ol "preptext" script can then be used to hunt down the sub/supers and apply appropriate character styles to them.

               

              Hope others find this useful.

               

              Colin

              • 4. Re: Re: How to fix faux subscripts/superscripts made with baseline shifts
                Peter Spier Most Valuable Participant (Moderator)

                So just the approach I suggested. But it still has that nasty problem of false positives when you've applied baseline shift for purposes other than making subscript or superscript.

                • 5. Re: How to fix faux subscripts/superscripts made with baseline shifts
                  rob day Adobe Community Professional & MVP

                  But it still has that nasty problem of false positives when you've applied baseline shift for purposes other than making subscript or superscript.

                   

                  A script could check for a point size change from the previous character, which would make a false positive less likely.

                   

                   

                  Something like this?

                  if (myCharacters[h].baselineShift < 0 && myCharacters[h].size<=myCharacters[h-1].size){ 

                  • 6. Re: How to fix faux subscripts/superscripts made with baseline shifts
                    rob day Adobe Community Professional & MVP

                    I thought "who the hell would make a subscript or superscript like that? wouldn't they just click the subscript or superscript buttons?"... unfortunately, no!

                     

                    If you were being very fussy about the type setting and the font wasn't open type maybe. The problem with Character>Superscript is similar to Character>Small Caps in both cases the effect is faked the characters aren't real superscript or small cap glyphs. Most Open Type fonts include the real glyphs via Character>Open Type. So the difference is in the glyph weights, the open type glyph looks better:

                     

                    opentype.png

                     

                    Without an open type font you might be able to compensate via a different weight and baseline shift. Here I've set the superscript as bold baseline shifted 10/5.5:

                     

                    Screen Shot 2014-09-26 at 9.37.47 AM.png

                    • 7. Re: How to fix faux subscripts/superscripts made with baseline shifts
                      Peter Spier Most Valuable Participant (Moderator)

                      I try to avoid baseline shift, as a rule, but I find I do it from time to time with the @ symbol in some fonts, and I might change the size as well. And of course that raises the question of what about cases where the the shifted glyph has scaling applied rather than an actual size change.

                       

                      I don't think there is a perfect solution here, so once converted I think it would be wise to do a run through Find/Change using Find Next to check every instance for unwanted conversions.

                      • 8. Re: Re: How to fix faux subscripts/superscripts made with baseline shifts
                        Colin Flashman Adobe Community Professional

                        @Rob: Perhaps I should have given some background for what I was trying to do.

                        I have a client who is importing dozens of pages of simple chemical equations from microsoft word and it is in the word file that the baseline shift method of creating subs/supers was done. What my client wanted to do was import the text without losing important appearance details such as this, and bolds/italics, but then be able to assign his own paragraph styles without faux sub/supers returning to a regular style. My procedure to the client was to:

                        1. Import said word file into indesign file that contains appropriate paragraph/character styles to be applied;
                        2. Run the default "findchangebylist.jsx" to remove any double spaces, tabs etc.
                        3. Run a modification of Jongware's "preptext" script that will apply to all text frames rather than the current text frame.

                        This was working well until we both noticed H2SO4 did not have the numbers as subs, even though the word file clearly did. Closer inspection on the word file showed that the subscript button was not toggled, but the baseline shift had been, hence why the preptext script had missed a key piece of formatting.

                        With the preptext script, items that had subscript and superscript locally applied to the text would now be assigned "Sub" and "Super" character styles, and from there I agree - the more discerning typesetter could to into the character style and make the apperance of the said subs/supers more appealing. I believe a way of using the opentype subs/supers would be to replace the words SUBSCRIPT and SUPERSCRIPT in the said script to be OT_SUBSCRIPT or OT_SUPERSCRIPT respectively, provided an opentype font was being used for the formatting.

                        So in this instance, this script serves a rather specific purpose of fixing this particular document, rather than being applicable on a wider scale.

                        It is also important for anyone working with epubs to note that subs/supers made with baseline shifts (whether applied as character styles or not) will not appear in the resulting epub. Subs/supers made with the subscript/superscript buttons (again, whether applied as a character style or not) will appear in a resulting epub, so this is another consideration (I don't know if this is true if a customised CSS has been applied, but for straight export to epub from InDesign, it appears to be the case). This can be said for other forms of faux styles, such as skewing type to make a faux italic.

                        @Peter: I agree, there isn't a perfect solution, but for the situation that I have, the script does what it is intended to do.

                        It should be noted for readers of this post that this script is specifically purpose-driven, and that I would not use this script if a document contained:

                        • fractions made using baseline shifts;
                        • character or paragraph formatting that used baseline shifts;