Page 1 of 1

Moving text to a specific column

Posted: Mon Feb 25, 2002 8:48 pm
by scott johnson
Hi all,
I have a table of contents that I got from another platform. The problem is is that the page numbers for the chapters, sections, etc. are appended right next to the name of the chapter, section, etc.
Now separating them wasn't a problem, I just used a regex. However that left the page numbers in a jagged vertical formation. I need to move them to a specific column, hopefully without doing it by hand, with the caveat that the chapter titles, etc. are different lengths. In other words, I can't just insert ten spaces and have them all line up that way. I need to insert ten spaces here, fifteen spaces there, two space in another place, etc.
Now I would like it if I could do this with a regex, or for that matter, a macro. But it seems that the only solution I can come up with requires Textpad's regex's and macros to be able to perform simple arithmatic. For example, if I want to align all the page numbers to the thirtieth column then I need to be able to subtract the length of the chapter title from 30 to get the number of spaces that need to be inserted (or subtracted, I almost forgot to mention that!) before the page number to get it to the correct column. Anybody got any other suggestions?


Scott J.

Re: Moving text to a specific column

Posted: Mon Feb 25, 2002 10:12 pm
by Ed
Can you give an example of before and after?

Have you tried putting a Tab before each page number (by using a regex) then
View/Document Properties/Tabulation/Default tab spacing set to (say) 30
where 30 is larger than the largest title. This should line the numbers up
and
View/Document Properties/Tabulation/"Convert existing tabs to spaces when saving files" Checked
Save
You have now achieved something. But is it what you want???

Re: Moving text to a specific column

Posted: Wed Feb 27, 2002 9:37 pm
by Mark Schnitzius
I would write a macro that:

1. Grabs the page number.
2. Trims off everything after the chapter title.
3. Appends a whole bunch of spaces to the end of the chapter title.
4. Moves cursor to 80 (or however many) characters from the beginning of the line.
5. Pastes in the page number.
6. Trims the remaining spaces.

Re: Moving text to a specific column

Posted: Fri Mar 08, 2002 5:46 am
by flash
The GoTo (ctrl-G) option works great for that if you can approximate the starting point of the "jagged edge". You have to be in BLOCK MODE.

Go to the jagged edge and cut to the end of the line (ctrl-X) . Then use the <GoTo - Column> command to move the cursor the desired column position and Paste it (ctrl-V). You can use it in conjuction with GoTo Bookmarks if you have a few formats that are different. Tag one type - run a macro to GoTo the next bookmark - cut/paste - clear the bookmarks and tag the next group...

Re: Moving text to a specific column

Posted: Fri Mar 08, 2002 12:13 pm
by Carlyle Sutphen
I would suggest that you write the same number of regex relacements as you have maximum digits in your line numbers.

for the a maximum of 3 digit numbers, assuming the line numbers are followed by a dot and at least one space:

s/^ *\([0-9]\{1\}\)\. +\([^ ].*\)$/ \1. \2/s/^ *\([0-9]\{2\}\)\. +\([^ ].*\)$/ \1. \2/
s/^ *\([0-9]\{3\}\)\. +\([^ ].*\)$/\1. \2/

The first example matches any (or no) spaces at the line's beginning. Then "remembers" the single digit at that point, which is followed by a point and at least one space and then "remembers" the rest of the line starting at the first non space character. The the line is replaced with two spaces, followed by the digit, the period, one space and then the rest of the line.

The next two are the same except for two digits preceded by one space respectively three digit preceded by no spaces.