Add space after numbers without duplicate spaces

Everything related to our flagship word processor.
Post Reply
seraphim
Posts: 3
Joined: 2019-06-04 11:09:51

Add space after numbers without duplicate spaces

Post by seraphim » 2019-06-04 11:18:21

I have a scriptural text that starts each verse with a number, followed by no space (e.g. "1And"). I want to add a space after the number ("1 And").

It's easy enough to Find 1 and Replace it with 1-space. But this becomes a problem once we get to numbers 10-19 (which would turn into "1 9And"),

I want to add a space after any numeral that's followed by a letter. Any ideas? This applies to all 10 possible numbers (0-9).

Thanks.

Þorvarður
Posts: 281
Joined: 2012-12-19 05:02:52

Re: Add space after numbers without duplicate spaces

Post by Þorvarður » 2019-06-05 07:36:04

1.png
1.png (65.32 KiB) Viewed 4073 times

seraphim
Posts: 3
Joined: 2019-06-04 11:09:51

Re: Add space after numbers without duplicate spaces

Post by seraphim » 2019-06-05 14:07:01

Thank you for this very helpful information. This worked fine.

Can you tell me how I could create a macro for this? We need to apply it to about 50 different documents.

Þorvarður
Posts: 281
Joined: 2012-12-19 05:02:52

Re: Add space after numbers without duplicate spaces

Post by Þorvarður » 2019-06-05 15:15:01

1. Click on the gear "Find what:"
2. Choose "Macroize"
3. Choose "Replace All" and press the button "Save as Macro…"

If you have more questions, then don't hesitate to ask. We are here to help. :–)

adryan
Posts: 311
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Add space after numbers without duplicate spaces

Post by adryan » 2019-06-05 18:33:45

G’day, seraphim, Þorvarður et al

When performing Replace operations on multiple instances of an expression, it is crucial to know your document well, lest you end up replacing things inadvertently.

In the present case, for example, Þorvarður’s solution will insert unwanted spaces in expressions such as “25th” (whether or not the ordinal suffix is superscripted) or “Figure 21C”. Mathematical expressions and chemical formulae would also be vulnerable, but I suspect that would not be a problem here. So it depends on whether your document contains things like this that will also be scooped up by the Find operation.

Another possibility here is as follows:–

Space after leading numbers.png
Space after leading numbers.png (293.68 KiB) Viewed 4021 times

This one assumes that each verse number occurs at the beginning of a paragraph and that all occurrences of numbers at the beginning of paragraphs are of this verse number variety. Again, it is important to be aware of the contents of your document.

Given that there are 50-odd files to be modified here, note that the Find & Replace window allows you to operate on All Open Files. You probably don’t want to open all files at once, so you might open them in batches of ten, say. In line with the foregoing, be very careful that only the files you intend to modify in this way are open at the time you perform the operation. It should be possible to get a macro to modify all the files at once without opening the lot. Another approach when attacking a large slew of documents, possibly located in nested folders, is to use BBEdit.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

seraphim
Posts: 3
Joined: 2019-06-04 11:09:51

Re: Add space after numbers without duplicate spaces

Post by seraphim » 2019-06-06 03:01:24

Thanks for continuing to be so helpful -- I appreciate it.

I'm a little new to macros. I want to use this in about 50 different documents. Once I create the macro, ow do I copy or export to another document?

adryan
Posts: 311
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Add space after numbers without duplicate spaces

Post by adryan » 2019-06-06 04:42:39

G’day, seraphim et al

A macro is a chunk of code that is executed like any other command in NWP’s hierarchical menu system. You generally call a macro from the Macro menu in the top menu bar of Nisus Writer Pro. Macros are available application-wide and not properties of individual documents per se. Unless the code in the chosen macro dictates otherwise, the macro operates on the frontmost NWP document.

If you wish to view or modify the code in a macro, use Macro > Show Macros Folder in Finder, and then navigate to and open the desired macro file.

There are various ways to create macros. One is via Macro > New Macro. Another is to duplicate an existing macro file (as found above), rename the duplicate to something different, and modify it as desired. There are other ways as well. When you save a document as a macro file, you furnish it with a .nwm file extension and save it in an appropriate location within the Macros folder.

I will just add here that the Copy to Clipboard option in the Macroize feature of the Find & Replace dialog box is often useful in construction of more complicated macros. First test your Find/Replace expressions directly on a test document, then Macroize > Copy to Clipboard and paste the contents of the Clipboard into the appropriate place in your macro file.

Many macros can be constructed using only such Find/Replace expressions and/or commands from the NWP hierarchical menu structure. There exists also an extensive macro language for more complicated technical work: see the Macro Language Reference in the Help menu.

Macros can range from a single line to many screenfuls of code. (They can also call other macros.) Whether or not it’s worthwhile creating a macro depends on various things, such as how important it is to record a sequence of commands for future use (lest you forget how to reconstruct it), how frequently you expect to use that sequence, and your own level of expertise.

It is always a good idea to test a new macro on a copy of a document rather than on an original. This precaution applies also to any but the simplest Replace operation.

In the present case, you would open each file in turn and call your macro to operate on it. As I suggested in my previous posting, the macro could be designed in such a way as to save you doing all the opening and closing manually. However, I myself haven’t used NWP macros for such multi-file operations. The multi-file replacement operations I need to perform involve a large number of files distributed amongst a large number of folders; in such a situation, BBEdit is my tool of choice.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Mojave 10.14.6
Nisus Writer user since 1996

martin
Official Nisus Person
Posts: 4610
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Add space after numbers without duplicate spaces

Post by martin » 2019-06-11 13:49:01

Thanks for the detailed explainer on macros Adrian!
seraphim wrote:
2019-06-06 03:01:24
I'm a little new to macros. I want to use this in about 50 different documents. Once I create the macro, ow do I copy or export to another document?
As Adrian said, macros aren't normally bound to a single document. Rather you just need to save your new macro to the Macros folder, so you can run the macro on the active (frontmost) document. The "Macroize" command in the Find panel will let you save a macro to the Macros folder directly. Once your macro is saved just open the document you want to run the macro on, and then choose the macro from the Macros menu.

Post Reply