Macro for French typography?

Get help using and writing Nisus Writer Pro macros.
Post Reply
MathiasG
Posts: 7
Joined: 2021-05-13 03:45:23

Macro for French typography?

Post by MathiasG »

Dear All
I would like to build a macro to cleanup my text, especially when I've imported some paragraphs where the typography isn't right in French. There might be one on this forum, but in that case I have missed it and would be grateful for any suggestion.

Basically, in order to avoid creating double spaces or spaces+non breakable spaces, etc, since I will have some "good" paragraphs and some defective ones, I think the macro would need to
-- remove all kinds of spaces, simple and/or non-breakable, before "double" punctuations (;:!?) + inside guillemets.
-- add such unbreakable spaces before such signs and inside guillemets.
I'm well aware that this must be ridiculously simple for some of you (judging from the cleanup punctuation macro) but if you had an example it would help! Thanks in advance!

EDIT: I see that in Find and Replace, Powerfind REGEX, I can find all positions just before double punctuations, then insert a non-breaking space just there, and add a round where I replace all double non-breaking spaces by a single one. Then a third round where I replace all sequences of simple space+non-breaking space (resulting from punctuations where a simple space was mistakenly inserted). The command is the following in the search box:

Code: Select all

(?=([;:!?])) 
There should be a ridiculously simple way to do that in a macro + the same thing for guillemets, but I am too much of a newbie :(

credneb
Posts: 179
Joined: 2007-03-28 07:30:34

Re: Macro for French typography?

Post by credneb »

Nisus let's you create macros in many ways. If what you want to do is basically create a macro with three consecutive find-replace operations, you can let Nisus do most of the work for you.

Under the Replace with: gear wheel in the F/R dialog, you will find a Macroize... item at the bottom.

Select Macroize... and a dialog will pop up asking what to do. Under the pulldown menu at the top, presumably you will select Replace All. Then Save as Macro. Name the macro.

For each additional F/R operation, simply Copy to Clipboard from the same menu. Then open your new cleanup macro and paste the clipboard onto a new line. (or simply copy that first line onto a new line, and edit the Find expression there.)

When the macro runs, it will step through each operation. You can also assign a command key combination to your macro. Handy if you you it often.

HTH.

Cliff

MathiasG
Posts: 7
Joined: 2021-05-13 03:45:23

Re: Macro for French typography?

Post by MathiasG »

Thanks Cliff! Most helpful.
I have made a new macro re-using the clean punctuation macro (and removing the lines that introduce some errors, eg remove spaces before any punctuation), and adding incrementally my Find and Replace. In fact, it's extremely useful to understand the syntax (for new users, beware: you don't end up with the same code if the PowerFind Regex menu is activated)
I'll post my codes here when it is ready. It might not be elegant in terms of code sobriety, but at that stage perhaps I'll ask advice from the community!

MathiasG
Posts: 7
Joined: 2021-05-13 03:45:23

Re: Macro for French typography?

Post by MathiasG »

I know it might sound too basic for some users but I decided to check the present state of the macro. It's not pretty but it does the required work, if you see some way to make it more compact, don't hesitate. When we work on texts where a part is in good shape and some other part contains errors, I see no other way of making sure that the process does not introduce more errors.
I insert the screenshot since non-breaking spaces disappear when I paste in code. My plan is to implement other very common fixes and to share the macro, if others are interested of course.
Capture d’écran 2021-06-02 à 22.28.19.png
Capture d’écran 2021-06-02 à 22.28.19.png (249.91 KiB) Viewed 3488 times
Out of curiosity, if power users read this: the fix for the "p." (pages) before page numbers is not good. I might end up with words ending with a "p" and followed by a non-breakable space. I would need to find all occurrences of "p. " which are just before any number and just replace the with p.+non breaking space without selecting the said number. I can find no way of achieving that with the Powerfind...

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

Re: Macro for French typography?

Post by phspaelti »

MathiasG wrote:
2021-06-02 12:29:09
Out of curiosity, if power users read this: the fix for the "p." (pages) before page numbers is not good. I might end up with words ending with a "p" and followed by a non-breakable space. I would need to find all occurrences of "p. " which are just before any number and just replace the with p.+non breaking space without selecting the said number. I can find no way of achieving that with the Powerfind...
"Find before" is where you started in this thread. The relevant construct is found in the "Match" menu as "FollowedBy()". So followed by a number would look like this in PowerFind Pro:

Code: Select all

(?=\d)
For your "p" problem you might also want to put a limit on the left side. That is you only want to find the letter "p" when it forms its own word.
So an improved expression will look like this:

Code: Select all

Find and Replace '\<p\. (?=\d)', 'p. ', 'Ea-i'
Obviously with the correct types of spaces.
philip

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

Re: Macro for French typography?

Post by phspaelti »

And further on the original point. The "two-step" of inserting the non-breaking space and then looking for and simplifying "simple space + non-breaking space" isn't really necessary. You can do this in one step:

Code: Select all

Find and Replace ' *(?=[;:?!]»)', ' ', 'Ea'
Again, with the appropriate space characters.

NB: Note that I have added a "»" for guillemet. I have been a bit confused by your discussion from the beginning. Note that when you posted the original expression, you talked about "double punctuation" and "inside guillemet". But the original expression merely looks for single punctuation. So your original expression will insert non-breaking spaces before all instances of those punctuation marks, not just double-punctuation.
However I am not on current on the standards for French here.
philip

MathiasG
Posts: 7
Joined: 2021-05-13 03:45:23

Re: Macro for French typography?

Post by MathiasG »

Thanks Philip!
-- Sorry, the term was not idiomatic. "Ponctuation double" in French means any punctuation made out of 2 elements (;:!?) and there should be a non-breaking space before that.
-- I"ll try your command for the "p. "
-- For the two steps, this was to clean things, since in the original I might have three cases: (a) punctuations preceded with non-breaking spaces, (b) punctuations preceded with normal spaces, ( c) ones with no space before. If I had only (a) and (b), a simple change would be OK, but this would leave ( c) unchanged.
Thanks again

MathiasG
Posts: 7
Joined: 2021-05-13 03:45:23

Re: Macro for French typography?

Post by MathiasG »

Just to confirm it works perfectly, thanks Philip!
So an improved expression will look like this:
CODE: SELECT ALL

Code: Select all

Find and Replace '\<p\. (?=\d)', 'p. ', 'Ea-i'
Obviously with the correct types of spaces.

Post Reply