Find only direct formatting of characters using AltSearch

I am trying to replace many instances of text direct formatted with bold to a character style that uses bold. Find and Replace cannot handle this, since it does not access character styles, only paragraph styles. The AltSearch extension can access character styles. However, when I use AltSearch to find bold (using [:::CharWeight::] in the Search For field), it finds bold text set by paragraph styles as well as by direct formatting, whether or not the AltSearch Paragraph styles option is checked. I only want to find direct formatting bold. Is there a way to do this with AltSearch? If so, what is it?

Aside: There is a clumsy workaround: Have both the Find and Replace dialog box and the AltSearch dialog box open at the same time. In F&R, search for direct formatting bold (via Format button without the F&R Paragraph Styles option being checked). In Altsearch, set the Replace field to the desired character style with bold. Now, click Find Next in F&R followed by Replaced in AltSearch. While this does work, it involved excessive clicking and is prone to user error by accidentally clicking the wrong button (specifically, Replace in F&R or Search For in AltSearch).

1 Like

Please tell us, which operating system und LibreOffice Version do you use?
And which file format?

My apologies, I am using .odt file format, although the document probably originally was .docx before I converted to LO. Version info:
Version: 7.6.5.2 (X86_64) / LibreOffice Community
Build ID: 38d5f62f85355c192ef5f1dd47c5c0c0c6d6598b
CPU threads: 20; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL threaded

1 Like

The extension AltSearch was written in StarBasic.
You can modify and improve its features.
.
Tools - Macros - Edit Macros

Roundabout > 10 Kloc … comments, names in czchech?! … you’ll have fun! :joy:

1 Like

I have no problems with using Attributes
to find directly formatted bold text.

Version: 24.2.1.2 (x86) / LibreOffice Community
Build ID: db4def46b0453cc22e2d0305797cf981b68ef5ac
CPU threads: 8; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
Locale: en-CA (de_DE); UI: en-US
Calc: threaded

2 Likes

Yes, but that is not my problem. Find and Replace cannot replace direct formatting with a character style, since the only styles it can access are paragraph styles. So, I cannot use Find and Replace to solve my problem.

AltSearch can access characters styles, but as far as I can figure out it cannot detect just directly formatted text. Its [:::CharWeight::] finds all bold text, including that set by paragraph and character styles. Is there a way to detect just directly formatted text in AltSearch?

Thank you, but the time it would take me to learn to be macro writer and discover how to access the attributes of LO correctly seems excessive.

But it can select (highlight) the text formatted directly to Bold. Then you can delete the direct fortmatting properties by hitting the Ctrl-M, and finally you can apply the desired (and existing) character style to the selection.

Yes, but I have hundreds of instances of directly formatted bold (and italic and bold-italic) text throughout the document, so your procedure will be very time consuming, like hours of work (vs. at best minutes if I could use Find and Replace or AltSearch to do this task). I need to convert over to character styles in place of direct formatting, as direct formatting is too hard to maintain in a large document that changes frequently.

Can you declare the rules (what properties you want to change to which styles?
Can you upload a sample file here?

I hope that you want to DELETE ALL of the direct (manual) formatting properties from that document. Then this task will not consupt more than about 15 minutes.

Rules:

  1. Change all directly formatted bold-italic text to a (custom, already-defined*) character style that puts the text in bold-italic. Text set in bold-italic by any style is not to be affected. (I do not not want, for example, a heading that is in bold by a paragraph style to have the bold character style added to it, as that will make document maintenance unacceptable.)

  2. Change all directly formatted bold text to a (custom, already-defined) character style that puts the text in bold. Text set in bold by any style is not to be affected.

  3. Change all directly formatted italic text to a (custom, already-defined) character style that puts the text in italic. Text set in italic by any style is not to be affected.

If Find and Replace could use character styles or AltSearch could find only direct formatted text, it would take just three Replace All clicks to reformat the entire document, likely less than 15 minutes as you say.

I do not currently have a small sample file but can make one once I have some time.

  • ASIDE: The requirement to use a custom character style is desired but not mandatory. AltSearch can find and replace character styles, so a solution that uses LO-defined character styles is acceptable, as I can then use AltSearch to change them to custom character styles. I note the LO does provide Emphasis (italic) and Strong Emphasis (bold) but not bold-italic. However, a LO style I do not use like Example could be used, which I could then change to my custom bold-italic character style.

Did you consider using standard Find & Replace's Find All to select all the disjoint occurrences at once, to apply the wanted changes then to all selected places at once?

2 Likes

You may be misled by the label of the “Paragraph Styles” checkbox.

  1. Specify the formatting attributes required for the search using the Format button in the standard dialog F&R.
  2. Pay attention to the new label of the checkbox “Including Styles”. If this checkbox is not checked, then the search will be performed only using direct formatting, as @mikekaganski points out.

Thank you, but I know this. The problem with using Find and Replace is not this, but the fact that F&R cannot access character styles. So, once F&R finds the direct formatted text, there’s no way to specify in its Replace field to replace the direct formatting with a character style.

The result of clicking the Find All button is the selection of found fragments in the document. Next, we apply the character style to the selection in the usual way (without using the F&R dialog).

2 Likes
  1. Start with searching Bold+Italic texts. Set the “Bold” (Font weight) and the “Italic” (Font posture) options in the Attributes sub Form of the F&R function ) use the real names of these properties.

  2. Leave empty the “Find” and the “Replace” boxes of the F&R and click on the Select All button.
  3. Close the F&R feature. The selection still visible.
  4. Apply the Ctrl-M (delete the direct formattinfg properties on the selected texts) manually.
  5. Apply the desired Character Style manually to the selected texts from the SideBar.

  6. Then repeat the steps 2-5 but with the Bold option only.

  7. Finally repeat the steps 2-5 but with the Italic option only.
3 Likes

None of the suggested solution worked, but the suggestions were useful enough for me to figure out an acceptable work around:

  1. Set up Find and Replace to search only for directly formatted bold text (Format-> Bold; Paragraph Styles unchecked). Turn on Regular Expressions. Set the Find field to (.+). This will find all strings in bold. Note that (.+) may not work for everyone, but it works exactly right for my document.

  2. Set up Find and Replace via Format to “No Bold” (which then displays as “normal” in the F&R box, see screenshot). In the Replace field, enter $1 (which will be the string found via the Find field) and enclose it between characters you do not use in the document, for example, =!=$1=!=. (My document does not use =!= anywhere.) The purposes of =!= is to make the string for use with AltSearch.

SolutionPart1

  1. Click Replace All. All strings directly formatted in bold like Foo Bar have bold removed and are now bounded by =!=, such as =!=Foo Bar=!=.

  2. Open AltSearch. In the Find field, enter =!=([\w\s.]+)=!=. [\w\s.]+ find all alphanumeric words and whitespace enclosed by =!=. This works perfectly for the text in my document but may need to be changed for other types of text. The key here is that =!= will not show up in the replaced string.

  3. In the AltSearch Replace field, enter \1\C{aBold}. This will use the ([\w\s.]+) found by the Find field but drop the =!= bounding strings. \C{aBold} will add the character style aBold (my custom char style) to the \1 string. Instead of aBold, you can use LO’s Strong Emphasis or whatever defined character style you want.

SolutionPart2

  1. Click AltSearch’s Replace All. All marked strings are replaced. For example, =!=Foo Bar=!= becomes Foo Bar, using a bold character style rather than direct formatting.

Final Note: Once F&R and AltSearch were set up as above, it took less than a minute to change 366 strings directly formatted in bold to strings using a character style!