change underline to italic? replace attribute?
change underline to italic? replace attribute?
I would like to be able to search for all underlined text in a document and change it to italicized text. I've tried using wild card and attributes in the find/replace window to no avail. What am i doing wrong? Or is there no way to do this?
Re: change underline to italic? replace attribute?
Put the cursor anywhere in an underlined text.
If the underlining is not part of a defined style, you will see a small 'a' tag in the Statusbar (at the bottom right of the document window): Click the small 'a' tag and apply 'Select All' from the dropdown menu: This will select all underlining in the document which is not part of a defined style.
Then apply "Remove Font' from the same dropdown menu.
This will remove underlining while preserving all selections.
You can change the selections to italicized text from the Format menu.
If the underlining is not part of a defined style, you will see a small 'a' tag in the Statusbar (at the bottom right of the document window): Click the small 'a' tag and apply 'Select All' from the dropdown menu: This will select all underlining in the document which is not part of a defined style.
Then apply "Remove Font' from the same dropdown menu.
This will remove underlining while preserving all selections.
You can change the selections to italicized text from the Format menu.
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: change underline to italic? replace attribute?
Hamid's suggestion might work for you, depending on the formatting in your document exactly. The thing about that little "a" icon (the font tag) is that the "Select All" command will match some bit of text in your document only if all the formatting overrides are present. So that might limit the kinds of matches that occur, depending on your use of styles and formatting overrides.
I would instead:
1. Open the Find & Replace panel.
2. Delete all text in the "find what" field.
3. From the gear button's menu, choose Wildcard > Anything to insert the "Anything" PowerFind bubble.
4. Select the bubble you just inserted.
5. Ensure that the menu Format > Any Attributes is checkmarked.
6. Apply underlining to the bubble (this will automatically turn on the "attribute sensitive" find option).
7. Click the "Find All" button.
You now have all underlined text in your document selected (regardless of whether the underlining comes from a style definition or was applied manually as an override). Changing that to italics instead is now easy:
1. Move back to the document window (keeping all selections intact).
2. Use the menus/palettes/whatever to turn off underlining.
3. Add italics.
I would instead:
1. Open the Find & Replace panel.
2. Delete all text in the "find what" field.
3. From the gear button's menu, choose Wildcard > Anything to insert the "Anything" PowerFind bubble.
4. Select the bubble you just inserted.
5. Ensure that the menu Format > Any Attributes is checkmarked.
6. Apply underlining to the bubble (this will automatically turn on the "attribute sensitive" find option).
7. Click the "Find All" button.
You now have all underlined text in your document selected (regardless of whether the underlining comes from a style definition or was applied manually as an override). Changing that to italics instead is now easy:
1. Move back to the document window (keeping all selections intact).
2. Use the menus/palettes/whatever to turn off underlining.
3. Add italics.
Re: change underline to italic? replace attribute?
Thank you Martin. That sounds brilliant (no, I'm not British, but that's the word that occurred to me) and I will try it as soon as I can turn from my current task. Thanks also to Hamid but I have to say, I'm not sure I actually understand what you are saying to do. But I'll try that too, just for the heck of it, to see what the difference is! (On a test document though.)
- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: change underline to italic? replace attribute?
Happy to help!
Some examples might clarify. But before I get to that, let's define manual formatting to make sure we're on the same page. Manual formatting is any formatting (attributes) applied to text directly, not through styles. Applying a "Heading 1" paragraph style may change the text's font and size, but that is not manual formatting. That is formatting by way of styles. On the other hand, if you select some text and change the font family/size using the Character palette, that is manual formatting.
Example 1
Let's say you have some text in your document where only the Normal style is applied. If you select that text, the font tag won't appear at all, because there is no manual formatting applied.
Example 2
If you again select that text where only the Normal style is applied, and then add an underline using the menu Format > Underline > Single, the font tag will suddenly appear. That's because the text now has some manual formatting applied, specifically an underline attribute.
If you then choose the "Select All" command from the font tag's menu, all text in the document with a manual single underline attribute will be selected. But only text with manual underlines will be selected; if the underline was enforced via a style, it would not be selected.
Example 3
Continuing with the text we have so far (Normal style + single underline), let's now change the font family as well. Say we change the font to Cochin, then the selected text now has manual formatting of (single underline + Cochin font family). If we again use the "Select All" menu from the font tag, this time only text in the document with both an underline and Cochin will be selected. And again, only if those attributes were manually applied, and were not enforced via styles.
The difference is that the font tag (little black underlined "a" icon) represents all manual font-like formatting applied to the selection. So when you activate the Select All command from the font tag's menu, it will select only all text in the document that has all of the manual formatting applied. Put another way, what the font tag selects will depend on where the selection rests in your document.Cliff S. wrote:Thanks also to Hamid but I have to say, I'm not sure I actually understand what you are saying to do. But I'll try that too, just for the heck of it, to see what the difference is!
Some examples might clarify. But before I get to that, let's define manual formatting to make sure we're on the same page. Manual formatting is any formatting (attributes) applied to text directly, not through styles. Applying a "Heading 1" paragraph style may change the text's font and size, but that is not manual formatting. That is formatting by way of styles. On the other hand, if you select some text and change the font family/size using the Character palette, that is manual formatting.
Example 1
Let's say you have some text in your document where only the Normal style is applied. If you select that text, the font tag won't appear at all, because there is no manual formatting applied.
Example 2
If you again select that text where only the Normal style is applied, and then add an underline using the menu Format > Underline > Single, the font tag will suddenly appear. That's because the text now has some manual formatting applied, specifically an underline attribute.
If you then choose the "Select All" command from the font tag's menu, all text in the document with a manual single underline attribute will be selected. But only text with manual underlines will be selected; if the underline was enforced via a style, it would not be selected.
Example 3
Continuing with the text we have so far (Normal style + single underline), let's now change the font family as well. Say we change the font to Cochin, then the selected text now has manual formatting of (single underline + Cochin font family). If we again use the "Select All" menu from the font tag, this time only text in the document with both an underline and Cochin will be selected. And again, only if those attributes were manually applied, and were not enforced via styles.
Re: change underline to italic? replace attribute?
Although NWP’s attribute sensitive Find/Replace is great and works fine in most of cases, it is not always easy to adjust the attributes of the find expression. So I wrote a macro which, I hope, makes this kind of job easier. The comment lines in the macro explain how it works. In this particular case, put the insertion point somewhere in an underlined word and run the macro. You will be asked to specify attributes to be found. So check Underline: Single (or Double?) and hit Where button.Then, you will be asked to specify text areas where you want to find underlined text. Check as many checkboxes as you like and hit Select All… button. All underlined texts in the text areas of your choice will be found and selected so that you can remove Underline and apply Italic easily.Cliff S. wrote:I would like to be able to search for all underlined text in a document and change it to italicized text.
I feel the name of the macro and some messages shown by it are not very good but, alas, my poor English does not allow me to improve them.
EDIT and P.S. How to install a new macro is explained here:
http://www.nisus.com/forum/viewtopic.php?p=8737#p8737
Code: Select all
# 1. The macro will show you a list of character attributes
# at the insertion point (or of the first character in the selection).
# 2. Check all attributes you need, e.g. 'Font Size: 12' and 'Italic: On',
# and hit 'Where'
# 3. Then, you will be asked to specify the find scope.
# Check all text areas to be included, e.g. 'body' and 'footnote',
# and hit 'Select All…'.
# 4. All text portions satisfying the criteria, i.e. 'Font Size: 12'
# and 'Italic: On' in 'body' and 'footnote', will be selected.
# - You can remove attributes you do not want to be listed up
# by editing $properties near the beginning of the macro.
# - Subscript style will be indicated inappropriately as
# 'Superscript: Subscript' for entries in the attribute list are
# generated programmatically, not to make the code yet more complicated.
# - For a List Style, you will see something redundant such as
# 'List Style: List Style "Number List"' for a command corresponding with
# 'paragraphStyleName' is not available for List Style.
# - The macro will show RGB values of colors except for very basic ones:
# white, black, red, green and blue.
$doc = Document.active
if $doc == undefined
exit
end
$properties = Cast to String 'fontSize, fontFamilyName, bold, italic, underline, strikethrough, superscript, characterCase, language, textColor, textBackgroundColor, textHighlightColor, characterStyleName, paragraphStyleName, listStyle, firstLineHeadIndent, headIndent, tailIndent, paragraphAlignment, paragraphWritingDirection, paragraphSpacingBefore, paragraphSpacingAfter, fixedLineHeight, lineHeightMultiple'
$properties = $properties.split ', '
$humanize = Hash.new
$humanize{'bold'} = $humanize{'italic'} = Array.new 'Off', 'On'
$humanize{'underline'} = $humanize{'strikethrough'} = Array.new 'None', 'Single', 'Double'
$humanize{'superscript'} = Array.new 'Subscript', 'None', 'Superscript'
$humanize{'characterCase'} = Array.new 'None', 'lowercased', 'Capitalized', 'Small Caps', 'UPPERCASED'
$humanize{'paragraphAlignment'} = Array.new 'Left', 'Right', 'Center', 'Justified'
$humanize{'paragraphWritingDirection'} = Array.new 'Natural', 'Left-to-Right', 'Right-to-Left'
$white = Color.white
$black = Color.black
$red = Color.red
$green = Color.green
$blue = Color.blue
$humanize{'colors'} = Hash.new $white, 'White', $black, 'Black', $red, 'Red', $green, 'Green', $blue, 'Blue'
$sel = $doc.textSelection
if $sel.location == $sel.text.length
$attr = $sel.displayTypingAttributes
else
$attr = $sel.text.displayAttributesAtIndex $sel.location
end
$valueOfProperty = Hash.new
$propertyList = Array.new
$sep = ': '
foreach $property in $properties
$value = $attr.getProperty($property)
$valueOfProperty{$property} = $value
$propertyName = $property
$propertyName.findAndReplace '^.', '\T{uppercase:\0}', 'E-i'
$propertyName.replaceAll '(?<=\p{Lower})(?=\p{Upper})', '\x20', 'E-i'
if $property == 'superscript'
$value += 1
elsif $property == 'textColor'
if Defined $humanize{'colors'}{$value}
$value = $humanize{'colors'}{$value}
end
elsif $property == 'textBackgroundColor'
if Defined $humanize{'colors'}{$value}
$value = $humanize{'colors'}{$value}
end
end
if Defined $humanize{$property}
$value = $humanize{$property}[$value]
elsif $value == undefined
$value = 'None'
end
$propertyName = $propertyName.textByAppending $sep, $value
$propertyList.appendValue $propertyName
end
$message = 'Adjust Search Criteria'
$detail = 'Check attributes to be included'
$button = 'Where'
$properties = Prompt Checkboxes $message, $detail, $button, $propertyList
if ! $properties.count
exit 'Nothing checked, exiting…'
end
$objectTypes = Hash.new
foreach $text in $doc.allTexts
$objectTypes{$text.documentContentType} = 1
end
$objectTypes = $objectTypes.keys
$objectTypes.sort
$message = 'In checked text areas:'
$button = 'Select All…'
$objectTypes = Prompt Checkboxes $message, '', $button, $objectTypes
if ! $objectTypes.count
exit 'Nothing checked, exiting…'
end
foreach $i, $property in $properties
$property = $property.split $sep
$property = $property.firstValue
$property.findAndReplace '^.', '\T{lowercase:\0}', 'E-i'
$property.replaceAll '\x20', '', 'E-i'
$properties.setValueAtIndex $property, $i
end
$sels = Array.new
foreach $text in $doc.allTexts
if $text.length
if $objectTypes.indexOfValue($text.documentContentType) != -1
$i = 0
while $i < $text.length
$attr = $text.displayAttributesAtIndex $i
$range = $text.rangeOfDisplayAttributesAtIndex $i
$passed = true
foreach $property in $properties
if $attr.getProperty($property) != $valueOfProperty{$property}
$passed = false
break
end
end
if $passed == true
$sel = TextSelection.new $text, $range
$sels.appendValue $sel
end
$i = $range.bound
end
end
end
end
if $sels.count
$doc.setSelections $sels
else
exit 'Nothing found, exiting…'
end- martin
- Official Nisus Person
- Posts: 5230
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: change underline to italic? replace attribute?
That's a very cool macro Kino, thank you!
I'm sure many will find it easy, convenient, and very useful. I'll have to add it to the repository.