Numbers by Chicago, Part 2

Our previous article outlined a fairly lengthy Find and Replace routine to make sure inclusive (elided) numbers follow the style outlined in the Chicago Manual. Astute reader Andrew Lockton responded with a technique that is so important, it deserves a second article. Andrew suggested taking the "Find What Expression" wildcard, which takes the form 1, 2, and so on, and putting it not in the Replace With box, where it is ordinarily used, but in the *Find What* box--something I did not know was possible. Hats off to you, Andrew.

Instructions for using the "Find What Expression" wildcard can be found here:

http://lists.topica.com/lists/editorium/read/message.html?mid=1706365638

Andrew's discovery opens up all kinds of possibilities for various problems I've previously been unable to solve, but let's look specifically at getting numbers by Chicago. The previous method required 18 separate searches. Andrew's brilliant methodology requires only three. Here's the explanation:

1. Numbers that take the form 104-105 need to be converted to 104-5:

Find What:

([1-9])0([1-9])-10([1-9])

Replace With:

102-3

What's going on there is that the first number grouping, ([1-9]), is being referred to by the 1 that follows the hyphen--in the Find What string. See it? Just before the 0 there? That tells Word to find (again) whatever was found by the first number grouping. For example, when the search hits something like "203-205," it says, "Hey, my first number group finds 2 [the first number in 203]. Let's see, is there also a 2 after the hyphen? Yes, there is!" Slicker than snake shoes, as expert word whacker Hilary Powers is fond of saying.

2. Numbers that take the form 104-110 need to be converted to 104-10:

Find What:

([1-9])0([1-9])-1([1-9])([0-9])

Replace With:

102-34

3. Numbers that take the form 111-112 or 119-120 need to be converted to 111-12 or 119-20:

Find What:

([1-9])([1-9])([0-9])-1([1-9])([0-9])

Replace With:

123-45

At first I thought it might be possible to combine 2 and 3:

([1-9])([0-9])([0-9])-1([1-9])([0-9])

But that would also find even hundreds (100, 200), which need to be ignored (100-114 rather than 100-14).

Many thanks to Andrew for the terrific tip.

_________________________________________

READERS WRITE

Alan Seiden wrote:

Here's another caps lock fixer. The program is called AntiCapsLock. It is free to try, but costs $10 to have the program remember one's settings.

http://www.orionsoft.cz/anticapslock.asp

We've set it up so that caps lock only toggles on or off when SHIFT is pressed along with the CAPS LOCK key. It works very well for a fussy computer user.

----------------------------

After reading the article "Numbers by Chicago," Jeanne Pinault wrote:

What I do with elided numbers is just replace all the hyphens with en dashes and then fix whatever comes up wrong when I edit the notes. That's because every set of endnotes I see is wrong in a slightly different way from every other set of endnotes I ever saw, so I have to read every character anyway. I can see that your marvelous find and replace would be a godsend with consistently formatted and voluminous endnotes produced on a regular basis, though. Are en dashes in there someplace?

I responded:

In the Find string, use ^150 (the en-dash code) instead of the hyphen.

----------------------------

Margaret Berson wrote:

I just was looking at your sequential replacement operation for page numbers. Why would you not use a macro that would go through and use the string position functions to evaluate the first digit of the first page number against the first digit of the second page number, deleting the unneeded first digit of the second number if it's the same, and leaving it alone if it's higher?

Wordmeister Steve Hudson sent in a macro that takes things even further. He wrote:

The following solution was designed to not just satisfy the English world with its 0-9 numerics. Use it to reduce hexadecimal addresses, Japanese, or anything. Even if the numbers aren't sequential, like hex, we just use ranges for the find such as "0-9A-F".

It is as simple as possible whilst being as generic as possible. Simpler solutions cannot work for non-English solutions as we cannot guarantee ASCII status. It is fully commented and written for clarity and education rather than speed. It will still run like greased lightning but 🙂


Public Sub NumberCruncher()
'Link this one to your toolbar
'Change any parms as needed from here
NumberCrunch ActiveDocument.Content
End Sub
Public Function NumberCrunch( _
Scope As Range, _
Optional NumberSeparator As String = "-", _
Optional Numbers As String = "0-9" _
) As String
'Another document solution from WordHeretic.com
'Produces short form number ranges anywhere in the provided
'document range. Eg 309-310 into 309-10 and 307-308 into 307-8
'You can use Unicode nnnn by using "^nnnn"
'NumberRange and architecture is for true I18N
'Known Issues: n-n will end up being n-. Eg 300-300 to 300-
'___________________
'Declare
'___________________
Const EndOfWord As String = ">"
Dim NumberRange As Range
Dim FirstNumber As Range
Dim SecondNumber As Range
Dim Separator As Range
Dim AnyNumber As String
Dim LenFirst As Long
Dim LenSecond As Long
'___________________
'Initialise
'___________________
Set NumberRange = Scope.Duplicate
Set FirstNumber = Scope.Duplicate
Set SecondNumber = Scope.Duplicate
'___________________
'Clarity
'___________________
AnyNumber = "[" & Numbers & "]@"
With NumberRange.Find
.Text = AnyNumber & NumberSeparator & AnyNumber & EndOfWord
.MatchWildcards = True
End With
'___________________
'Main program loop
'___________________
While NumberRange.Find.Execute(Replace:=wdReplaceNone)
Set Separator = NumberRange.Duplicate
With Separator.Find
.Text = NumberSeparator
.Execute(Replace:=wdReplaceNone)
End With
'So now we have the entire number range AND
'the separator range, we can calc the numbers
FirstNumber.Start = NumberRange.Start
FirstNumber.End = Separator.Start
SecondNumber.Start = Separator.End
SecondNumber.End = NumberRange.End
'Counting chars is NOT the same as an offset
LenFirst = FirstNumber.Characters.Count
LenSecond = SecondNumber.Characters.Count
'Now lets work out what's the same
'First up, if the second number is shorter than
'the first, it's already been done or is irrelevant.
'Eg 200-7
'If the second number is longer we cannot find common ground
'Eg 97-101
'Thus, we can ONLY operate on equal length numbers.
'Then, test for the number being a dynamic field
'as we can't really change those
If LenFirst = LenSecond And NumberRange.Fields.Count = 0 Then
'Now we need to match every character or finish
'We will shrink our FirstNumber range as we go,
'and delete the secondnumber range as we go
'Char comparisons DO use unicode
While FirstNumber.Characters(1) = SecondNumber.Characters(1)
FirstNumber.MoveStart
SecondNumber.Characters(1).Delete
Wend
End If
Wend
'___________________
'Destroy all objects
'___________________
Set FirstNumber = Nothing
Set SecondNumber = Nothing
Set Separator = Nothing
Set NumberRange = Nothing
End Function
Steve later added:
We may also want to include something like this if the user wants to run the macro on a range of text:
Public Sub NumberCruncherSelection()
NumberCrunch Selection.Range
End Sub

If you don't know how to use macros like that one, you can find out here:

----------------------------

The consistently brilliant Eric Fletcher wrote:

I was interested to see the tip from Meg Cox and Joy Freeman in the last Editorium posting about highlighting all instances of an item. In a job some time ago, some very foreign names were being used throughout. I knew they would cause problems later in the spell check but unless I was careful, a slightly different spelling of the same name would easily slip past. For example, "Mkandawire" might also be "Mkandewire"... I wanted to avoid the tedium of clicking the Ignore button during spell check but still have a way to check the items.

So, in order to both flag a word as already seen and turn off proofing, I created the little macro below. To use it, I select the word (or words) and click the button associated with it. All identical instances (note the MatchCase) are set in green color with no proofing. The resultant green color shows that the word has already been encountered (as noted in your reader's tip).

However, what is particularly useful about this approach is that you can then later collect all of the flagged items in a single step -- either for separate review or for use in a style guide. (This method only works for Word 10+.)

1. In the Find box, leave Find What empty but use Format to select the color (Green in my case).

2. Click the "Highlight all items found in:" box and choose Main Document. The Find button changes to Find All, and when you click it, all instances of the color green will be highlighted.

3. Now for the fun part: close the F&R dialog and choose Copy (Ctrl-C); open a new document and paste (Ctrl-V).

What you get is a list with each found item on a line of its own. You can then sort it and more easily review the list since all identical instances of the same item sort together. (...and I'm sure someone out there will even have a VBA script that could eliminate all duplicates in the sorted list!)

[Editor's note: You'll find such a script here: http://lists.topica.com/lists/editorium/read/message.html?mid=1702467672]

Here's my macro:


Sub FlagThis()
' FlagThis Macro
' Flags current selection as green with no proofing throughout the
document. E Fletcher 2003-10-23
'
Dim flagit As String
flagit = Selection
Selection.MoveLeft Unit:=wdCharacter, Count:=1
With ActiveDocument.Content.Find
.ClearFormatting
.Text = flagit
.MatchCase = True
With .Replacement
.Text = "^&"
.ClearFormatting
'-- colour and no proofing options for replace
.Font.Color = wdColorGreen
.NoProofing = True
End With
.Execute Format:=True, Replace:=wdReplaceAll
End With
Selection.MoveRight Unit:=wdWord, Count:=1
End Sub

Note that I have it set up so the cursor ends up at the end of the first word in the selection. If users want to just add color and not set the proofing off, the ".NoProofing = True" statement should be removed.

I also use a slightly modified version of this method to flag words set in a different language. My Quebec flag button sets the selection in my custom "French" character style [French (Canada) language and font color blue] so I modified the FlagThis macro to set all instances of the selection to the French style. The spell check switches languages on the fly so it checks properly in multiple languages. Then, before I print or release the final version of the file, I modify the style definition(s) to change the language color(s) to automatic.

Many thanks to Alan, Jeanne, Margaret, Steve, and Eric for their terric tips and comments.

This entry was posted in Editing. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

You must be logged in to post a comment.

  • The Fine Print

    Thanks for reading Editorium Update (ISSN 1534-1283), published by:

    The EDITORIUM, LLC
    http://www.editorium.com

    Articles © on date of publication by the Editorium. All rights reserved. Editorium Update and Editorium are trademarks of the Editorium.

    You may forward copies of Editorium Update to others (but not charge for it) and print or store it for your personal use. Any other broadcast, publication, retransmission, copying, or storage, without written permission from the Editorium, is strictly prohibited. If you’re interested in reprinting one of our articles, please send an email message to editor@editorium.com

    Editorium Update is provided for informational purposes only and without a warranty of any kind, either express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, and freedom from infringement. The user (you) assumes the entire risk as to the accuracy and use of this document.

    The Editorium is not affiliated with Microsoft Corporation or any other entity.

    We do not sell, rent, or give our subscriber list to anyone. Period.

    If you’d like to subscribe, please enter your name and email address below. We publish the newsletter once a week, and on rare occasions we may send an important announcement. We never, ever send spam. Thank you for signing up!