Highlight bookmarks

Hi!
I am using Zotero as a reference manager in Writer. To make my documents compatible with Word, Zotero offers the option to insert citations as bookmarks instead of fields. The problem I have is, I am working on a large document with contributions from many people, using different ref managers etc. when integrating these contributions the reference links normally break but the citation is still in the text. So I have now text with the citations I inserted properly linked to my Zotero and those of others just being text or fields with no connection anymore. It would be really helpful if writer would highlight bookmarked text so I could immediately see which citations will show up in the Bibliography and which are broken.

I know that you can navigate manually through bookmarks, but with hundreds of bookmarks this is not an option.

Please tell me that you can highlight bookmarks the same way you can highlight fields… PLEASEEEEE.

Cheers, T.

1 Like

Enhancement request already filed : https://bugs.documentfoundation.org/show_bug.cgi?id=45589
You can comment this bug report to add your own proposition how to make bookmarks visible.

You should try this extension: https://extensions.libreoffice.org/extensions/bookmark-toggle

Hey, thanks a lot. It looked good at the beginning but then it started to show 20 or more comment windows per bookmark making writer so slow that I already thought it had crashed. So this tool is only an option if there is really nothing else available. Still at least some kind of help, better than nothing.

Hello @Tass,

please try if the following macro works in your case:

Sub HighlightAllBookmarks( lHighLightColor As Long )
REM Highlights all Bookmarked text strings from the current document.
REM Example:  HighlightAllBookmarks( RGB(19,240,55) )
	If HasUnoInterfaces( ThisComponent, "com.sun.star.text.XBookmarksSupplier" ) Then
		Dim oBookmarks As Object
		oBookmarks = ThisComponent.getBookmarks()
		
		Dim sBookMarkNames() As String
		sBookMarkNames = oBookmarks.getElementNames()
		
		Dim i As Integer
		For i = 0 To Ubound( sBookMarkNames )
			oBookmarks.getByName( sBookMarkNames( i ) ).getAnchor().CharBackColor = lHighLightColor
		Next
	End If
End Sub

Sub HighlightAllBookmarks_Green()
    HighlightAllBookmarks( RGB(19,240,55) )
End Sub

Hi, thanks a lot, wow, what a service!
I tried it, opened the document in Writer, then the macro editor, copied all in, saved, ran it, got the following message:
BASIC runtime error.
Argument is not optional.
and highlights this line:
oBookmarks.getByName( sBookMarkNames( i ) ).getAnchor().CharBackColor = lHighLightColor

I have no clues about macros, last time I programmed something lies decades back, so sorry if I behave a bit dumb.

When I run it outside the editor I get this message:
A Scripting Framework error occurred while running the Basic script Standard.Module1.HighlightAllBookmarks.
Message: wrong number of parameters!

1 Like

To call the above macro without argument:

Sub HighlightAllBookmarks_Green()
    HighlightAllBookmarks( RGB(19,240,55) )
End Sub

Hey, thanks! Returns now: BASIC runtime error.
Sub-procedure or function procedure not defined.
And it marks: HighlightAllBookmarks( RGB(19,240,55) )
But I also don’t know if I copied it well, I made it to replace the first line of what you send me first.

The second Sub does not replace the first Sub that i posted, but you need to have both Subs for this to work. ( both HighlightAllBookmarks and HighlightAllBookmarks_Green ).

I updated my answer to show them both together.

I had to modify the code be Tass in order to get it working in LibreOffice 6.4.3.2. I have also added another Sub to change the colour back to white. You can then assign the “grey” sub to a keystroke i.e ALT+1 and the “white” sub to ALT+2. This enables you to toggle between highlighting and not highlighting a bookmark. It works really well for Zotero bookmarks. See code in next comment:

Sub HighlightAllBookmarks( lHighLightColor As Long )
REM Highlights all Bookmarked text strings from the current document.
REM Example: HighlightAllBookmarks( RGB(19,240,55) )
If HasUnoInterfaces( ThisComponent, “com.sun.star.text.XBookmarksSupplier” ) Then
Dim oBookmarks As Object
oBookmarks = ThisComponent.getBookmarks()

    Dim sBookMarkNames() As String
    sBookMarkNames = oBookmarks.getElementNames()

    Dim i As Integer
    For i = 0 To Ubound( sBookMarkNames )
       REM oBookmarks.getByName( sBookMarkNames( i ) ).getAnchor().CharBackColor = lHighLightColor
        oBookmarks.getByName( sBookMarkNames( i ) ).Anchor().CharBackColor = lHighLightColor
    Next
End If

End Sub

Sub HighlightAllBookmarks_Grey()
REM HighlightAllBookmarks( RGB(204,204,204) )
HighlightAllBookmarks( RGB(204,204,204) )
End Sub

Sub HighlightAllBookmarks_White()
HighlightAllBookmarks( RGB(255,255,255) )
End Sub