[Solved] Changing default spacing (Borders) around formula

Discuss the formula editor
Post Reply
martenjan
Posts: 7
Joined: Wed Jan 12, 2011 10:39 am

[Solved] Changing default spacing (Borders) around formula

Post by martenjan »

The spacing for a formula consists of spacing around the math object, and spacing (borders) inside the math object. Changing this is documented at
http://wiki.services.openoffice.org/wik ... formula%3F

Now, I want to remove the superfluous spacing from numerous formulae in a writer document. It seems to me that I'll have to adjust the spacing(borders) of all these formulae one by one by hand, but I have the nagging feeling I could be able to set some style parameter somewhere which avoids this chore. Am I overlooking something? But if I have to, is it possible to `paint' these properties to reduce this click-fest?
Last edited by martenjan on Thu Jan 13, 2011 10:57 am, edited 2 times in total.
OpenOffice 3.2.1 on Windows Vista
OpenOffice 3.2.1 on Ubuntu
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Changing default spacing (Borders) around formula

Post by floris v »

Which superfluous spacing? According to that Wiki, you can reduce the external spacing for all formulas in one fell swoop, but it's very likely that if you want to adjust the internal spacing, you will have to do it for each formula (but when you have set the new spacing settings, maybe you only have to double click each formula for the new settings to take effect).
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
martenjan
Posts: 7
Joined: Wed Jan 12, 2011 10:39 am

Re: Changing default spacing (Borders) around formula

Post by martenjan »

Both. I did reduce the external spacing with one fell swoop, and the internal spacing for all new formulae. But I did not know how to apply this automatically for the formulae I already have. By the way, with zero borders,

Code: Select all

K u = f
results in a math box that clips part of the f. I worked around this by using

Code: Select all

K u = f {}
. I think it is a bug, but this requires me to check whether the formula is rendered correctly after applying the zero border.

A double click does not apply the new settings, so the documentation is correct in saying that it only applies to new formulae.
OpenOffice 3.2.1 on Windows Vista
OpenOffice 3.2.1 on Ubuntu
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Changing default spacing (Borders) around formula

Post by floris v »

I suppose that a macro can do it - select each formula, get the formula code from it, delete the formula, insert a new one with the saved formula code. You can ask for help in the Macro and API forum
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Changing default spacing (Borders) around formula

Post by acknak »

I believe someone (Hagar, IIRC) has already posted just such a macro. Try a search.

Hmm... maybe it was a macro to change all the formula font sizes. Sorry, I'm not 100% sure.
AOO4/LO5 • Linux • Fedora 23
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Changing default spacing (Borders) around formula

Post by floris v »

acknak wrote:I believe someone (Hagar, IIRC) has already posted just such a macro. Try a search.

Hmm... maybe it was a macro to change all the formula font sizes. Sorry, I'm not 100% sure.
That wouldn't matter. A macro with a body to traverse through all formulas requiring only editing the action to be taken would be great.

It's my lucky day. Found the macro. This one is it.
Last edited by floris v on Wed Jan 12, 2011 7:05 pm, edited 2 times in total.
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
Hagar Delest
Moderator
Posts: 32662
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Changing default spacing (Borders) around formula

Post by Hagar Delest »

acknak wrote:Hmm... maybe it was a macro to change all the formula font sizes. Sorry, I'm not 100% sure.
Yes, someone has made a macro here but for the font.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Changing default spacing (Borders) around formula

Post by floris v »

Instead of the font specs you have to set the LeftMargin, Rightmargin, TopMargin and BottomMargin (Wiki)

Code: Select all

Sub mathmargins
   dim embeddedObjects, elementNames, i, element
   
   embeddedObjects = ThisComponent.getEmbeddedObjects()
   elementNames = embeddedObjects.getElementNames()
   for i=0 to UBOUND(elementNames)
      element = embeddedObjects.getByName(elementNames(i)).Model
      if (element.supportsService("com.sun.star.formula.FormulaProperties")) then
         element.TopMargin = 30 : sets to 0.30 mm
         element.BottomMargin = 30
         element.LeftMargin = 30 
         element.RightMargin = 30
      endif
   next i
   ThisComponent.reformat()   
End Sub
Edited after debugging :crazy:
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
martenjan
Posts: 7
Joined: Wed Jan 12, 2011 10:39 am

Re: Changing default spacing (Borders) around formula

Post by martenjan »

This looks promising. After insertion of rem to correct the syntax error in the line with TopMargin, the macro runs as intended (although I used zero margins instead of 30). Thanks!

Code: Select all

Sub MathMargin
dim embeddedObjects, elementNames, i, element
   
   embeddedObjects = ThisComponent.getEmbeddedObjects()
   elementNames = embeddedObjects.getElementNames()
   for i=0 to UBOUND(elementNames)
      element = embeddedObjects.getByName(elementNames(i)).Model
      if (element.supportsService("com.sun.star.formula.FormulaProperties")) then
         element.TopMargin = 30 : rem sets to 0.30 mm
         element.BottomMargin = 30
         element.LeftMargin = 30
         element.RightMargin = 30
      endif
   next i
   ThisComponent.reformat()   
End Sub
OpenOffice 3.2.1 on Windows Vista
OpenOffice 3.2.1 on Ubuntu
martenjan
Posts: 7
Joined: Wed Jan 12, 2011 10:39 am

Re: Changing default spacing (Borders) around formula

Post by martenjan »

To preserve this for the next fellow running into this, I added this to http://wiki.services.openoffice.org/wik ... formula%3F. With that I consider my question solved.
OpenOffice 3.2.1 on Windows Vista
OpenOffice 3.2.1 on Ubuntu
Post Reply