Reply to topic  [ 3 posts ] 
How to change relative font size with a macro 
Author Message

Joined: 2007-07-23 14:24:06
Posts: 1
Hi,

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!


2007-08-07 06:43:12
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
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:
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'
End

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:
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.


2007-08-07 12:38:13
Profile WWW

Joined: 2008-05-17 04:02:32
Posts: 400
Post Re:
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... ;-)
http://listserv.dartmouth.edu/scripts/wa.exe?A2=ind9906&L=NISUS&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:
$subScript = ':Format:Baseline:Subscript'
$appLang = Application Property 'localization'

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

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
   end
end

If you want to shorten no-break space before "!" only, change the Find All command to
Code:
$numFound = Find All '\xA0(?=!)', 'E'


2008-10-03 09:14:19
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: Baidu [Spider], Yahoo [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software