Numbering paragraphs: possible?

Everything related to our flagship word processor.
Anne Cuneo
Posts: 164
Joined: 2004-09-23 02:15:46
Location: Switzerland
Contact:

Numbering paragraphs: possible?

Post by Anne Cuneo »

I am sure someone asked this before, but I can't find it and I need it; is there a way of numbering paragraphs? I am doing the translation of film dialogues, and it sure would help me, because it would alert me if I missed a paragraph, which, I notice, is so easy to do.
Thanks to the helpful friends…
Anne

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

Number List

Post by Hamid »

It seems the only way now is to use 'Number List' style from Lists from the Format menu or the Formatting palette group.

Anne Cuneo
Posts: 164
Joined: 2004-09-23 02:15:46
Location: Switzerland
Contact:

Post by Anne Cuneo »

Thanks for the suggestion, Hamid. Unfortunately, it does not really work, as the source (the original script) is a given, and the paragraph number is fixed, it's quicker to number them by hand…
I looked through the macros and realized then the isn't one for line numbering - in fact I cannot find line numbering anywhere. Didn't someone create one? I seem to remember vaguely something of the kind in the Nisus list. Please remember, if you answer this, that I am strictly a macro USER, I have never written one. Thanks again!
Anne

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

Line numbering

Post by Hamid »

Line numbering is a built-in feature which you can access from the View menu. If you want to number paragraphs only, you can use the following macro. Copy the macro below and save it with .pl extension, and run it on a copy of your file.

#Nisus Macro Block
#source front
#destination new
#End Nisus Macro Block
my $count = 1;
while (my $line = <STDIN>) {
print "$count\t$line";
$count++;
}

Anne Cuneo
Posts: 164
Joined: 2004-09-23 02:15:46
Location: Switzerland
Contact:

Post by Anne Cuneo »

It worked, thanks. I'm grateful.
Unfortunately, it creates a new document in which all styles are lost. It does not matter for the original, but it does matter for the translation I'm working on!
I suppose I'll give up for this time. I should have thought of this earlier. But I keep the macro for a next time. I'll number the original then (it does not matter if styles are lost there…), and number my version as I go.
In Nisus Classic there was a trick to have the numbering in the margin rather than in the text. I don't remember what we did, I just remember using it. Is there a possibility here?
Anne

Dirk_Barends
Posts: 42
Joined: 2006-12-14 09:09:51

Number Renumber Lines

Post by Dirk_Barends »

I happen to have this Number Renumber Lines macro:

Code: Select all

#Nisus Macro Block
#source front selection
#destination front selection
#End Nisus Macro Block
use strict;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");

my $count = 1;
my $start = 1;
while (my $line = <STDIN>) {
	$line =~ s/[\r\n]+//g;
	if ($line !~ /^(\d+)/) {
		print "$count$line\n";
	} else {
		if ($start) {
			$count = $1;
			$start = 0;
			print "$line\n";
		} else {
			$line =~ s/^(\d+)/$count/;
			print "$line\n";
		}
	}
	$count++;
}
Thought it was standard with Nisus, but perhaps I got it somewhere else.

Dirk Barends

Anne Cuneo
Posts: 164
Joined: 2004-09-23 02:15:46
Location: Switzerland
Contact:

Post by Anne Cuneo »

Thanks, Dirk Barends.
Before I use it: what is this “number renumber” section?
In between I have noticed line numbering is part of Nisus: I just never needed to use it until now.
Anne

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

Post by martin »

The macro Dirk quoted will also remove the formatting in your document. This macro should however do the trick:

Code: Select all

Set Selection 1, 0   # move to start of document 

$count = 0 
While Find ‘^(?:\d+\.?\s*)?’, ‘E-W’ 
   Type Text “$count. ” 
   $count += 1 
End
Last edited by martin on 2008-03-28 00:34:02, edited 1 time in total.

Dirk_Barends
Posts: 42
Joined: 2006-12-14 09:09:51

line numbering

Post by Dirk_Barends »

Anne Cuneo wrote:[...]
Before I use it: what is this “number renumber” section?
This macro renumbers line too, if they are already numbered.
Should be saved as a Nisus Perl macro, and yes it can affect formatting of the text.
But it works, for me (the other one from Martin doesn't work well.)

Dirk Barends

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

Post by martin »

Sorry, the macro I gave had a tendency to go into an infinite loop. I've edited it to avoid the problem.

Anne Cuneo
Posts: 164
Joined: 2004-09-23 02:15:46
Location: Switzerland
Contact:

Post by Anne Cuneo »

Thanks Martin, but I think there still is a problem, when I want to apply the Macro, il tells me there is an error in the first line. Am I missing something here?
I am using what I found in your message, I just did a copy-paste. Like this:

Set Selection 1, 0   # move to start of document

$count = 0
While Find ‘^(?:\d+\.?\s*)?’, ‘E-W’
   Type Text “$count. ”
   $count += 1
End

Cheers.
Anne

Dirk_Barends
Posts: 42
Joined: 2006-12-14 09:09:51

Post by Dirk_Barends »

Anne Cuneo wrote:Thanks Martin, but I think there still is a problem, when I want to apply the Macro, il tells me there is an error in the first line. Am I missing something here?
Did you save it as a Nisus Macro? As for example:
Number Lines.nwm
Saved as a Perl Macro it gave that error with me too.

Now if I could make this macro to work on selected text only, it would be a good replacement for the old Number Renumber Lines (Perl) macro.
Perhaps Martin knows how to do that?

Dirk Barends

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

Bug

Post by Hamid »

Anne Cuneo wrote:Thanks Martin, but I think there still is a problem, when I want to apply the Macro, il tells me there is an error in the first line. Am I missing something here?
Nisus Macros are supposed to treat straight quotes the same as curly quotes, but it seems not to be the case when you run this macro. This must be filed as a bug.
If you change all the curly quotes in the macro to straight quotes, the macro will work. However, there will be a problem if any paragraph already starts with a number.

Anne Cuneo
Posts: 164
Joined: 2004-09-23 02:15:46
Location: Switzerland
Contact:

Post by Anne Cuneo »

Did you save it as a Nisus Macro? As for example:
Number Lines.nwm
Saved as a Perl Macro it gave that error with me too.
Dirk: Brilliant! I'm going to try. Of course, I saved it as Pearl Macro… I'll keep you posted.
Nisus Macros are supposed to treat straight quotes the same as curly quotes, but it seems not to be the case when you run this macro. This must be filed as a bug.

Hamid: Wow! You are right, the straight quotes went curly, I hadn't noticed.
I am just leaving, I'll be in the train for several hours (offline) and try things out. I'll let you know tonight.
Anne

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

Quotes

Post by Hamid »

the straight quotes went curly
It is the QuickFix settings of your language which does that in the macro file. To prevent this happening, use a Tech language setting for all NWP (.nwm) and perl (.pl) macro files; this is particularly important for perl macros, or perl code included in NWP macros, which require straight quotes.

Post Reply