Find and replace spaces around Endnote References

Everything related to our flagship word processor.
Post Reply
peterwgallagher
Posts: 5
Joined: 2014-07-01 00:32:58
Location: Melbourne, Australia

Find and replace spaces around Endnote References

Post by peterwgallagher »

I have a file in NWP that has spaces around the endnote references like this (assuming '10' is the superscripted reference):
...end of a sentence. 10 Start of the next sentence...
Using 'find and replace' I would like to eliminate the space following the period at the end of the first sentence but leave the space between the reference and the start of the next sentence.

I have tried all flavors of find and macros using the 'n' option to treat the reference as a digit (works for FIND but I can't REPLACE the reference as a reference, only as a digit!) and I have tried searching instead for the style ("Note reference"). But nothing I do seems to work.

Given the depth of the macro language, I'm sure I'm missing some trick. Can anyone advise me on a fix?

Thank you,

P
User avatar
Hamid
Posts: 777
Joined: 2007-01-17 03:25:42

Re: Find and replace spaces around Endnote References

Post by Hamid »

One way to find note references (excluding normal digits) to make any changes around them in a document is to use the following expression as a macro (with .nwm extension):

Code: Select all

Select Next Note Reference
You can assign a shortcut to the macro.
After first running the macro, you can also use the Repeat command from the Edit menu to get to the next note reference (as long as you don't use any other command, like Save, in between).
peterwgallagher
Posts: 5
Joined: 2014-07-01 00:32:58
Location: Melbourne, Australia

Re: Find and replace spaces around Endnote References

Post by peterwgallagher »

Thank you for that idea, Hamid. I'll try that. But there are 450+ references in the document. It would be really laborious to edit each one :-)

P
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Find and replace spaces around Endnote References

Post by phspaelti »

The following type of code will select the character before any note reference, if it is a space. I am appending the code as a macro below.

Code: Select all

$doc = Document.active
$notes = $doc.allNotes
$spaceBefore = Array.new
foreach $note in $notes
	$range = Range.new ($note.documentTextRange.location - 1 , 1)
	$sel = TextSelection.new($note.documentText, $range)
	if $sel.substring == ' '
		$spaceBefore.push $sel
	end
end
$doc.setSelection $spaceBefore
Attachments
Select Space Before Note Reference.nwm
(3.6 KiB) Downloaded 332 times
philip
peterwgallagher
Posts: 5
Joined: 2014-07-01 00:32:58
Location: Melbourne, Australia

Re: Find and replace spaces around Endnote References

Post by peterwgallagher »

Philip,

What can I say? Brilliant!

I was experimenting with incorporating Hamid's selection idea when you posted this. But your solution is far superior. Finding the index of all chars preceding a note (in one line) & then creating an array of selection indices for 'space' chars so you can display all selections at once is the sort of solution that betrays experience!

I tried running the selection macro, pressed 'delete' and ... the whole file seems to have been fixed. 450+ corrections in one blow!

Hooray!

P
Post Reply