I have found an alternative solution using a LibreOffice Writer extension.
Install the extension
Install the Alternative Find & Replace for Writer (AltSearch) extension for Libre Office (compatible with version 3.3+). Download the extension then in Writer go to Tools
> Extension Manager
then click Add
and select the file for the extension you downloaded.
The extension is accessible via Edit
> Alt. Find & Replace
or by clicking on this icon in the toolbar:
Perform the replacement
Using the example in the original post, let's say we have set a cross-reference named reference1
with the value test
which we want to rename to reference5
. Let's say we also have also inserted one or more cross-references in the document referring to the set cross-reference. Open the alternative find & replace and carry out the following steps:
In Search for
:
- Alternative 1: type
[::ReferenceMark::]\\Reference1
in the box.
- Alternative 2: select
Cross-ref. marker (text)
from the Extended
drop down menu and add \\Reference1
manually to the search box).
In Replace
:
- Alternative 1: type
\B{Reference5|\o}
in the box.
- Alternative 2: select
Insert marker+text for cross-reference
from the Replace
drop down menu. In the box, replace ref1
with Reference5
and replace text
with \o
.
- Note: if you want to change the value of the set cross-reference at the same time, replace
\o
with the new value.
Click replace all
to perform the replacement.
At this point, all we've done is change the set cross-reference. Any inserted cross-references in the document will now point to a set cross-reference which no longer exists, so we have to change those too. These steps assume that the inserted cross-references display the value of the set cross-reference (as opposed to e.g. the page number or some other attribute). See breakdown further below if you need to update other types of cross-references.
In Search for
:
- Alternative 1: type
[::Reference::]\\Reference1
in the box.
- Alternative 2: select
Cross-reference (text)
from the Extended
drop down menu and add \\Reference1
manually to the search box).
In Replace
:
- Alternative 1: type
\L{2,0,Reference5}
in the box.
- Alternative 2: select
Insert cross-reference to marker
from the Replace
drop down menu. In the box, replace 0,0
with 2,0
and replace ref1
with Reference5
.
Click replace all
to perform the replacement.
Breakdown
In [::ReferenceMark::]\\Reference1
:
[::ReferenceMark::]
means we are searching for a set cross-reference.
\\
means we want to find the reference by its name.
Reference1
is the name of the reference we are searching for.
In \B{Reference5|\o}
:
\B
means we will replace the found reference with a new one.
Reference5
is the name for the new reference.
\o
means the value of the new reference will be the value of the old reference that was found.
In [::Reference::]\\Reference1
:
[[:Reference:]]
means we are searching for an inserted cross-reference.
\\
means we want to find the reference by the name that it refers to.
Reference1
is the name of the reference that we are searching for.
In \L{2,0,Reference5}
:
\L
means we will replace the inserted cross-reference with a new inserted cross-reference.
2
means that the new inserted-cross reference will be of type "reference" i.e. it will display the value of the set cross-reference.
0
means the type of the reference is a set cross-reference (as opposed to a numbered paragraph etc.).
Reference5
is the name that the new inserted cross-reference will refer to.
To do replacements of other types of cross-references (e.g. to page numbers) the 2
will need to be modified to one of the following (extracted from the documentation):
0 - page number in Arabic numerals, 1 - chapter number, 2 - the
reference text , 3 - above/below , 4 - page number using the numbering
type defined in the page style, 5 - category and number of a caption,
6 - caption text, 7 - number of a sequence field (caption)
Other uses
On a separate note, the extension provides all kinds of other useful functionality which is missing in the standard find and replace. For example you can replace all instances of a style with another style (this being the original reason I installed it), and almost anything else you can think of. Refer to the extension's homepage for detailed (if somewhat hard to parse) instructions.