3

Is there a way to quickly change the font of all equations in a document? Maybe there's a built-in style for them or something...

I don't want to set a default style for new ones, but to change existing one's.

2

I don't believe there is a built-in style for the formulas. However, you can have a macro iterate over all formulas and change the style. The French OpenOffice.org FAQ has an example of such a macro:

Sub Main
    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
                element.BaseFontHeight = 14
                element.FontNameVariables= "Arial"
                element.FontNameFunctions = "Arial"     
                element.FontNameNumbers= "Arial"        
                element.FontNameText= "Arial"       
            endif
        endif
    next i
    ThisComponent.reformat()
End Sub
2
  • This doesn't work, because after the first iteration it cannot determine the model of the element. I use LibreOffice 3.4.4. – KovBal Dec 17 '11 at 13:06
  • There must be a special kind of object in your document. I've added a check to see if the object has the Model property, hoping this might fix that problem. – Brecht Machiels Dec 18 '11 at 22:44
3

For LibreOffice, I had to make some changes in the macro in order to get an automatic update of the formula. I took a look at this topic in the OpenOffice forums next to the present one.

Here is the macro I have used:

REM  *****  BASIC  *****
Sub ReformatFormules
    embeddedObjects = ThisComponent.getEmbeddedObjects()
    elementNames = embeddedObjects.getElementNames()
    for i=0 to UBOUND(elementNames)
        element = embeddedObjects.getByName(elementNames(i)).Model
        oXEO = embeddedObjects.getByName(elementNames(i)).ExtendedControlOverEmbeddedObject
        iCurrentState = oXEO.currentState
        oXEO.changeState(com.sun.star.embed.EmbedStates.UI_ACTIVE)
        if (not isNull(element)) then
            if (element.supportsService("com.sun.star.formula.FormulaProperties")) then
                element.BaseFontHeight = 10
                element.FontNameVariables= "Times New Roman"
                element.FontVariablesIsItalic=1
                element.FontNameFunctions = "Times New Roman"     
                element.FontNameNumbers= "Times New Roman"        
                element.FontNameText= "Times New Roman"       
            endif
        endif
    next i
End Sub
1
  • I found that this one works better, since it will "click" into the object and resize the object. – Allen Aug 15 '13 at 8:28
1

I tried to simplify this as much as possible and make it run as fast as possible (changing the state, or "clicking in to it" was really really slow for me), and I came up with this solution:

Sub FormulaFontSizeChanger
    f = InputBox("New font size:", "BaseFontHeight", 9)
    o = ThisComponent.getEmbeddedObjects()
    For i = 0 to o.count-1
        if (not IsNull(o(i))) and (not IsNull(o(i).Model)) then
            o(i).Model.BaseFontHeight = f
            o(i).Component.BaseFontHeight = f
            o(i).ExtendedControlOverEmbeddedObject.update()
        endif
    Next i
End Sub

The secret sauce here is the o(i).ExtendedControlOverEmbeddedObject.update(). That tells libreoffice to update / redraw the embedded object internally, so we don't have to "trick" it in to updating.

It appears that it's probably not necessary to update both the component and the model, but I feel it's better to be thorough.

Btw, I'm using LibreOffice v4.3.4.1 YMMV.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.