Change the size or font of all formulas

From The Document Foundation Wiki
< Macros‎ | Math
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
English • ‎français


When you want to modify an attribute in all the formulas you are going to write, just follow the procedure described in Faq/Math/008. If you want to change "after the fact", you have to reopen all the formulas and make the modifications. If the number of formulas is large, this can quickly become tedious.

This macro shown below solves the issue i#5092.


In LibreOffice Basic:

Sub ChangeFormulaSizeAndFont()
    '''Change the size or font of all Math formulas in document'''

    embeddedObjects = ThisComponent.getEmbeddedObjects()
    elementNames = embeddedObjects.getElementNames()

    For i = 0 To UBound(elementNames)

        element = embeddedObjects.getByName(elementNames(i)).Model

        If (not isNull(element)) Then
            If (element.supportsService("")) Then
                ' force the update
                realElem = embeddedObjects.getByName(elementNames(i)).EmbeddedObject
                realElem.updateMode =
                element.BaseFontHeight = 14
                element.FontNameVariables = "Arial"
                element.FontNameFunctions = "Arial"
                element.FontNameNumbers = "Arial"
                element.FontNameText = "Arial"
            End If
        End If
    Next i

End Sub ' ChangeFormulaSizeAndFont


  • Consult this help page on FormulaProperties to explore other properties that can be altered.