?SPAM? - [texhax] superscripts and spacing problem

Philip TAYLOR P.Taylor at Rhul.Ac.Uk
Mon Nov 28 18:11:15 CET 2005

Joey Coyle wrote:

> Hi,
> I am printing out musical chords like C7 or A7 with the 7  
> superscripted...  It looks fine with the C7, but with the A7, with  the 
> inward slope of the A, the 7 should be moved closer to the A...,  I know 
> I can do this manually with \hspace, but I have a macro   \DomSev{C}  or 
> \DomSev{A} that prints the chord and the macro doesn't  know what note 
> it will take as an argument...
> I thought the beauty of Tex was that it handled this kind of thing  
> automatically?

Only within the limits of the TeX paradigm, which is to treat
everything as if it were a rectangular box.  Once you want to
start looking /inside/ the box (in your case, to differentiate
between the kerning needed for A^7 v. C^7), things are a lot
harder, which is why kerning information such as this comes
from the font designer via the TFM file rather than being
left to TeX to work out for itself.  In your case, one
possible solution would be to compare the two widths

(1)	\wd \hbox {#1V}


(2)	\wd \hbox {#1{}V}

(These aren't real TeX constructs : you'd need a couple
  of intermediate steps to get at these widths -- I can
  deal with that later if you don't know how to proceed)

Then you could use the difference (1) - (2) to compute
the correction needed between $\hbox {A}^\hbox {7}$
w.r.t. that needed for $\hbox {C}^\hbox {7}$.

Sample code (compare the results visually)

         \def \domsev #1%
             {\setbox 0 = \hbox {#1{}V}%
              \setbox 2 = \hbox {#1V}
              \dimen 0 = \wd 0
              \advance \dimen 0 by -\wd 2
              \dimen 0 = 0 pt %%% pretend we did none of the above
              $\hbox {#1}\kern -\dimen 0 ^7$

         \def \DomSev #1%
             {\setbox 0 = \hbox {#1{}V}%
              \setbox 2 = \hbox {#1V}
              \dimen 0 = \wd 0
              \advance \dimen 0 by -\wd 2
              $\hbox {#1}\kern -\dimen 0 ^7$

         \domsev {A}
         \domsev {C}

         \DomSev {A}
         \DomSev {C}


Philip Taylor

More information about the texhax mailing list