replace the short minus sign, raise the superscripts and lower the subscripts

If you write the formula for the nitrate ion in Arial you get this:

The minus sign is too small and the subscript and superscript look wrong. There is a better minus sign than the one on the keyboard, called the n-dash since it takes up the same space as a letter n. Use the table here to find its Unicode value. The subscripts look better if they are lowered by 2 points and the superscripts look better if they are raised by 2 points. This makes the nitrate ion look like this:

The macro below replaces all the minus signs in the document and alters the subscripts and superscripts accordingly:

Sub ReplaceMinus()

'replace minus
Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "-"
        .Replacement.Text = "–"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    'superscript and subscript
    'lower and raise subscripts and superscripts
   Selection.WholeStory
    Selection.Find.ClearFormatting
    With Selection.Find.Font
        .Superscript = False
        .Subscript = True
    End With
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Superscript = False
        .Subscript = True
        .Position = -2
    End With
    With Selection.Find
        .Text = "([A-Za-z0-9+-])"
        .Replacement.Text = "\1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    With Selection.Find.Font
        .Superscript = True
        .Subscript = False
    End With
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Superscript = True
        .Subscript = False
        .Position = 2
    End With
    With Selection.Find
        .Text = "([A-Za-z0-9+–])"
        .Replacement.Text = "\1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
  Selection.WholeStory
    Selection.Find.ClearFormatting
    With Selection.Find.Font
        .Superscript = True
        .Subscript = False
    End With
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Superscript = True
        .Subscript = False
        .Position = 2
    End With
    With Selection.Find
        .Text = "(–)"
        .Replacement.Text = "\1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll    
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: