[Solved] Ignoring line breaks in headings for the index?

Discuss the word processor
Post Reply
Jacques Hyn

[Solved] Ignoring line breaks in headings for the index?

Post by Jacques Hyn »

Hi,

I cannot seem to find a way to make OpenOffice 2.4.0 (on Gentoo Linux), to ignore line breaks, in an index.

I use line breaks, in my (long) headings, to break them at specific words.

In the index, the line breaks are taken into account, and the headings are cut, even though there would be enough room to fit them. I'd like them to be fitted, as the font is smaller, and they can fit easily, in this context.

There does not seem to be anything about it, in the issue tracker, or in this forum.

There does not seem to be any property I can apply, on the index, or on the entries («Contents 1», for the first level entries), to ignore line breaks.

If it is not possible, an option should be added to the «Text flow» tab, for paragraph styles, to ignore line breaks.


My current workaround, is to edit the index manually, and I can live with it, but it would be better if it was automatic. This option could also be quite useful, for other similar problems (a string used in multiple places, with more or less room -possibly, different font sizes-, which might require it to be cut, in some cases, but not in the others).


[Edit: Indeed, I would also use it for putting the current heading, in each page header (I'm editing a book). Currently, if I use Insert -> Fields -> Others... -> Document -> Chapter -> Chapter name, then the line break is not taken into account, but it does not convert it to a space, as you would expect. Not exactly the same problem, but it is related to the proper ignorance of line breaks -an option to replace line breaks with a single space character].


Thanks in advance,

Bye.
Last edited by Hagar Delest on Wed Dec 03, 2008 11:33 am, edited 1 time in total.
Reason: tagged [Solved].
User avatar
squenson
Volunteer
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: Ignoring line breaks in headings for the index?

Post by squenson »

Quite a sophisticated feature!

You can emulate what you want with the following not-so-simple approach:
1. In your favorite image editor, create an image with white background of 20 pixels width and 10 pixels high.
2. At the place where you want your header to line break, insert several of the images above. Insert the first image, right click on it and select Anchor > As character, then position it properly at the end of the last word of the first line, then copy it at this place as many times as needed to make the next word wrap to the second line.
3. Because the image is white on white, it will not print nor be visible.
4. Normally, as images are not copied in the index table, your index will look like a continuous line.
LibreOffice 4.2.3.3. on Ubuntu 14.04
User avatar
Hagar Delest
Moderator
Posts: 32668
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Ignoring line breaks in headings for the index?

Post by Hagar Delest »

Does it help also: [Tutorial] Work-around for a Two lines heading?

Thanks to add '[Solved]' at beginning of your first post title (edit button) if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Jacques Hyn

Re: Ignoring line breaks in headings for the index?

Post by Jacques Hyn »

squenson wrote:You can emulate what you want with the following not-so-simple approach:
1. In your favorite image editor, create an image with white background of 20 pixels width and 10 pixels high.
2. At the place where you want your header to line break, insert several of the images above. Insert the first image, right click on it and select Anchor > As character, then position it properly at the end of the last word of the first line, then copy it at this place as many times as needed to make the next word wrap to the second line.
3. Because the image is white on white, it will not print nor be visible.
4. Normally, as images are not copied in the index table, your index will look like a continuous line.
Thanks. This seems it would indeed work (although I would have to also insert images before the beginning of my heading, as I center them, so there will have to be the same number of images on both sides).

However, I would really feel shameful, about using a non-semantic approach, even as a workaround ^_^; If there is no other solution, I prefer editing the index manually, everytime I need to export/print it :) I guess it might be possible to script it, but I'm not too much into macros either... I'll just post the suggestion to the issue tracker, if I'm not missing any existing feature (or maybe it is already implemented in OOo-3, or projected to be? I didn't check).

This workaround could be useful to other people, though, before it gets implemented.
Hagar de l'Est wrote:Does it help also: [Tutorial] Work-around for a Two lines heading?
Thanks for your answer. However, if I understand correctly (and from having tested the odt document, and your code from May 07, 2008 11:41 am, in the second topic), this is to include a generic prefix, possibly numbered, on the preceding line.

In my case, I use line breaks, to split an heading, because it would be too long to fit nicely, on a single line, with a large font. For example: «On the hypothesis of reincarnation, and its possible use, in one's belief system». I insert a line break after the first comma.

However, in the index, with a normal-size font, it fits on a single line, without problem, so I'd like to get it on a single line (the index is more readable this way, notably if there are a number of such long titles), that is, to ignore the line break (to replace it with a single space).
User avatar
Hagar Delest
Moderator
Posts: 32668
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Ignoring line breaks in headings for the index?

Post by Hagar Delest »

You can modify the macro to remove the numbering and the prefix/suffix. See attachment and the macro I've put inside.

NB: does the macro work fine for you? I've strange results on my Linux box (white character style is not applied, fake chapter is before the Heading 1 instead of before :?
Attachments
Example.odt
(12.74 KiB) Downloaded 328 times
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Jacques Hyn

Re: Ignoring line breaks in headings for the index?

Post by Jacques Hyn »

Hagar de l'Est wrote:You can modify the macro to remove the numbering and the prefix/suffix. See attachment and the macro I've put inside.

NB: does the macro work fine for you? I've strange results on my Linux box (white character style is not applied, fake chapter is before the Heading 1 instead of before :?
Oh, sorry, I didn't read the text in the document from your first link ^_^; Indeed, I now understand how it works (setting the heading, without line breaks, in white on white, and using some other text, with the line breaks, to serve as the visible heading), and it sure does work, for my problem. Not semantic either, but easier than squenson's solution :) Thanks.

I'll wait a few more days, just in case someone knows about some existing feature to do this properly, and I'll post the problem to the issue tracker.

(There indeed does seem to be some problems with applying the macro, but I really don't know much about using macros, so I can't say for sure... anyway, it's just a matter of creating the two styles :))
User avatar
Hagar Delest
Moderator
Posts: 32668
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Ignoring line breaks in headings for the index?

Post by Hagar Delest »

Hagar de l'Est wrote:NB: does the macro work fine for you? I've strange results on my Linux box (white character style is not applied, fake chapter is before the Heading 1 instead of before :?
No, it works as designed in fact! I mixed that macro with the other one for in-line headings that does blank the real title this time.

So I made another macro for you: type your heading text and run the macro:
- Typed string is changed to Heading i (i to be set in the macro) and Heading i made white (becomes invisible) with small font
- A new paragraph is created with Fake Heading i style and a paragraph break is entered.
Then, you just have to customize the Fake Heading i style (for font size, ...) and add your line breaks.
I've added (but commented) the code to insert the chapter number in case you want to have it before (then, update is automatic).
Drawback to that code: we do not use the chapter name field here in order to allow the line breaks where you want. But it means that if you edit the heading (change words), you'll have to edit also the Heading i part (you can modify the Heading i style for a short while to see them, changing the font color).

Code: Select all

Option Explicit         	' http://user.services.openoffice.org/en/forum
Sub CustomTwoLinesHeadings	' Hagar Delest
Dim oDoc as Object      	' v1 - June 7, 2008
Dim oCharStyles as Object, oCharStyle as Object
Dim oParaStyles as Object, oParaStyle as Object
Dim oViewCursor as Object
Dim oCurText as Object
Dim oCursor as Object
Dim iLevel%   ' Faked heading level
Dim sHeading as String
Dim oChapField as object

'----------------------  User customization  ----------------------
iLevel = 1   ' Set to 2 if you want to fake Heading 2
' But you won't get the parent numbering
'------------------------------------------------------------------

oDoc = stardesktop.currentComponent

' Create the styles if they don't exist
oCharStyles = oDoc.styleFamilies.getByName("CharacterStyles")
If not oCharStyles.hasByName("WhiteChar") then
	oCharStyle = oDoc.createInstance("com.sun.star.style.CharacterStyle")
	oCharStyles.insertByName("WhiteChar", oCharStyle)
	oCharStyle.CharColor = RGB(255,255,255)
End If

oParaStyles = oDoc.styleFamilies.getByName("ParagraphStyles")
If not oParaStyles.hasByName("Fake Heading " & iLevel) then
	oParaStyle = oDoc.createInstance("com.sun.star.style.ParagraphStyle")
    oParaStyles.insertByName("Fake Heading " & iLevel, oParaStyle)
    oParaStyle.FollowStyle = "Default"
End If

' Apply Heading and make it invisible (white font)
oParaStyle = oParaStyles.getByName("Heading " & iLevel)
oParaStyle.ParaTopMargin = 0
oParaStyle.ParaBottomMargin = 0
oParaStyle.ParaKeepTogether = True
oParaStyle.CharColor = RGB(255, 255, 255)
oParaStyle.CharHeight = 8

' Apply the default formatting, then the Fake Heading paragraph style
oViewCursor =  oDoc.CurrentController.ViewCursor
oCurText = oViewCursor.Text
oCursor = oCurText.createTextCursorByRange(oViewCursor)
oCursor.gotoEndOfParagraph(False)
oCursor.gotoStartOfParagraph(True)
sHeading = oCursor.getString()
oCursor.CharStyleName = "Default"
oCursor.ParaStyleName = "Heading " & iLevel
oCursor.gotoEndOfParagraph(False)
oCurText.insertString(oCursor, chr$(13), False)
oCursor.ParaStyleName = "Fake Heading " & iLevel

' Insert Chapter number field (uncomment if needed)
'oChapField = oDoc.createInstance("com.sun.star.text.TextField.Chapter")
'oChapField.Level = iLevel - 1
'oChapField.ChapterFormat = com.sun.star.text.ChapterFormat.NUMBER
'oCurText.insertTextContent(oCursor, oChapField, False)
'oCurText.insertString(oCursor," ", False)

' Insert Fake Heading with its string
oCurText.insertString(oCursor,sHeading & chr$(13), False)

End Sub
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Jacques Hyn

Re: Ignoring line breaks in headings for the index?

Post by Jacques Hyn »

Hi,

I filled the following report: http://www.openoffice.org/issues/show_bug.cgi?id=90841.


Thanks for your workarounds,

Bye.
Post Reply