Bold only for First word in the Paragraph

Hello everyone,

is it possible to set the formatting of only the first word in a Paragraph to Bold. Use case is a simple dictionary formatting.

This would have been possible using the Drop Caps feature if the number of lines setting could be set to 1. This would also allow formatting initials.
Here is a link explaining the difference between drop caps and Initials Drop Caps and Initial Letters | Magazine Designing

Is there any other way to do this?

–Nithin

Any way? Not by ready-made means, I’m afraid, in specific not by settings implemented with the paragraph style concept as it is. You need to do it by “hard” assignment of an appropriate characzter style.

You can define a named pragraph style (may otherwise be identical with Default e.g.) and a named character style you want to apply to the initial word s of paragraphs haveing the mentioned style assigned.

Then you only need a little “macro” for the task. Resorting to “macros” always comes with disadvantages, however.

See the example FirstWordAsInitial.

Code:

Sub setCharStyleFirstWord(Optional pDoc As Object, Optional pText As Object, _
Optional pParaStyleN As String, Optional pCharStyleN As String)
REM This way to use a missing optional parameter as a local variable is 
REM not supported in very old versions of LibO and in AOO.
If IsMissing(pDoc) Then pDoc = ThisComponent
If NOT pDoc.supportsService("com.sun.star.text.TextDocument") Then Exit Sub
If IsMissing(pText) Then pText = ThisComponent.Text
If IsMissing(pParaStyleN) Then pParaStyleN = "paraInitialWord"
If IsMissing(pCharStyleN) Then pCharStyleN = "charInitialWord"
oldSel = pDoc.CurrentSelection
cur = pText.createTextCursorByRange(pText.Start)
REM Now the WORKING code:  

Do While pText.compareRegionEnds(cur, pText.End)>0
 If cur.ParaStyleName=pParaStyleN Then
  cur.gotoEndOfWord(True)
  cur.CharStyleName = pCharStyleN
 End If
 cur.gotoNextParagraph(False)
Loop

REM Done!
ThisComponent.CurrentController.select(oldSel)
End Sub

Hello Lupp,
Thanks a lot for the solution. This exactly what i was looking for. Thanks again for investing so much time and effort. I guess i will also create a enhancement request for the same.

It’s tdf#70180