How to change relative font size with a macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
Posts: 1
Joined: 2007-07-23 14:24:06

How to change relative font size with a macro

Post by marshman » 2007-08-07 06:43:12


I have trying Nisus Writer Pro and I would like to create a macro that switch from English typographic rules to the French ones. For example, I would like to find all instances of "!" in an text and add a non-breaking space before it AND change the size of this space to be half of the one use for the "!". Is it possible to do such things? If so, could someone give me some clues on how to do it.

Thank you!

User avatar
Official Nisus Person
Posts: 4251
Joined: 2002-07-11 17:14:10
Location: San Diego, CA

Post by martin » 2007-08-07 12:38:13

Unfortunately there's no way to inspect the current font size of text in a document, so you will not be able to change the size of the non-breaking space based on the following punctuation. However, if you can decide on fixed font size in advance then this macro should do:

Code: Select all

Set Selection 1, 0	# move to start of doc
While Find '\M!', 'E'
	Select Start	# place caret before exclamation
	Insert Text ' '
	Menu ':Format:Size:9'
You could also ask the user what font size they want to use at the start of the macro. One caveat: you are limited to the predefined font sizes that appear on the menu.

Also, another way to accomplish the same thing much more efficiently:

Code: Select all

Find and Replace '\M(!)', ' \1', 'aEU'
This code makes use of the attribute sensitive replacement option 'U' so you will need to make sure that only attributes you desire are applied to the macro document. One way to do that is to use the menu Remove Attributes and Styles on the macro and then apply the font size you want to the non-breaking space.

Posts: 400
Joined: 2008-05-17 04:02:32


Post by Kino » 2008-10-03 09:14:19

I have written a NW Classic macro for a similar purpose for a French journalist. Oh, it was my very first macro posted to the Dartmouth list — near the end of the last century. Nostalgy... ;-) ... US&P=R4590
According to a book I received from him as a cadeau, it would be convenient to shorten no-break spaces not only before "!" but also before ";" and "?". However, this rule is not always observed, it seems. That's a problem of personal taste, after all. Anyway, to get something close to "quart de cadratin insécable" (shorter no-break space), I think it would be convenient to apply Subscript (or Superscript) style on those no-break spaces. Then, the relative font size will be kept even if you change the font size.

In the Nisus Writer Pro Macro language, the macro (with some revisions) would be...

Code: Select all

$subScript = ':Format:Baseline:Subscript'
$appLang = Application Property 'localization'

if $appLang == 'French'
	$subScript = ':Format:Ligne de base:Indice'

Replace All '(?<=«)\x20*(?![\xA0\x20])|(?<![\xA0\x20])\x20*(?=[:;!?»])', '\xA0', 'E'
# Insert no-break spaces after "«" or replace ordinary spaces after "«" with no-break spaces.
# Insert no-break spaces before ":;!?»" or replace ordinary spaces after ":;!?»" with no-break spaces.

$numFound = Find All '\xA0(?=[;!?])', 'E'  # Find all no-break spaces before ";!?"

if $numFound > 0
	$isSubScript = Menu State $subScript
	if $isSubScript != 1  # Unless all selections are in Subscript style...
		Menu $subScript
If you want to shorten no-break space before "!" only, change the Find All command to

Code: Select all

$numFound = Find All '\xA0(?=!)', 'E'

Post Reply