Make equations blue in powerpoint

Microsoft Powerpoint has a surprisingly powerful equation editor, which also allows to use latex macros such as \alpha to get \alpha.

I’ve blogged about the equation editor before but one pet peeve of mine was that I like to have my math in a different color, but never found a way to do this automatically. I finally decided to invest the time and find out how to do it. After a mere several years of investigation, I am happy to report that it is in fact possible to do so using Visual Basic for Applications (VBA).

You can view the developer tab by following these instructions, and then click on “macros”, type a name such as All_eqs and click on “create” at which point you can add the following code:

Sub All_eqs()

Dim oSld As Slide
Dim oShp As Shape
Dim oShapes As Shapes
 
For Each oSld In ActivePresentation.Slides
  Set oShapes = oSld.Shapes
  For Each oShp In oShapes
   If oShp.HasTextFrame Then
      If oShp.TextFrame.HasText Then
                With oShp.TextFrame.TextRange
                    For x = 1 To .Characters.Count
                        If .Characters(x).Font.Name = "Cambria Math" Then
                            .Characters(x).Font.Color.RGB = RGB(0, 112, 192)
                        End If
                    Next x
                End With

    End If
    End If
    Next oShp
 Next oSld
End Sub

You can change the line

If .Characters(x).Font.Name = "Cambria Math" Then

to

If .Characters(x).Font.Name = "Cambria Math"  And .Characters(x).Font.Color.RGB = RGB(0, 0, 0) Then

if you want to only recolor parts of equations that are black. This is useful when you use other colors to annotate parts of your equations and you don’t want to over-ride them.

You can also use the following macro to just recolor the equations in the current slide:

Sub All_eqs_slide()

Dim oSld As Slide
Dim oShp As Shape
Dim oShapes As Shapes
 
Set oSld = Application.ActiveWindow.View.Slide
  Set oShapes = oSld.Shapes
  For Each oShp In oShapes
   If oShp.HasTextFrame Then
      If oShp.TextFrame.HasText Then
                With oShp.TextFrame.TextRange
                    For x = 1 To .Characters.Count
                        If .Characters(x).Font.Name = "Cambria Math" Then
                            .Characters(x).Font.Color.RGB = RGB(0, 112, 192)
                        End If
                    Next x
                End With

    End If
    End If
    Next oShp

One more tip: Microsoft PowerPoint requires saving macro-enabled presentations as a .pptm file, which is somewhat annoying – it is not automatically recognized by slack and is also more cumbersome if you want to save it in OneDrive and open from your iPad (which is how I present slides these days). However, to use a macro, it does not have to exist in the current presentation. You can have a presentation file only for the macros, and as long as it is open, you will be able to run them on a different presentation through the developer tab.

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 )

Twitter picture

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

Facebook photo

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

Connecting to %s