Macros/Math/001

From The Document Foundation Wiki
< Macros‎ | Math
Jump to: navigation, search

Template:TopMenu/en Template:Menu/en Template:Menu.Macros/en

Other languages:

Description

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.

Code

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("com.sun.star.formula.FormulaProperties")) Then
                ' force the update
                realElem = embeddedObjects.getByName(elementNames(i)).EmbeddedObject
                realElem.updateMode = com.sun.star.embed.EmbedUpdateModes.ALWAYS_UPDATE
                element.BaseFontHeight = 14
                element.FontNameVariables = "Arial"
                element.FontNameFunctions = "Arial"
                element.FontNameNumbers = "Arial"
                element.FontNameText = "Arial"
            End If
        End If
    Next i
 
    ThisComponent.reformat()

End Sub ' ChangeFormulaSizeAndFont

Notes

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