How to discard automatically generated hidden character styles?

By inspecting the XML code in the .fodt format of a Writer document, I noticed that Writer automatically inserts hidden character styles whenever I’m editing lines. These styles do not have a visible effect on the screen, and they do not appear in the styles menus.

An example is:
<text:span text:style-name="T10045">#U</text:span>
where I only entered “#U”, which is used for finding lines in my document (it would be deleted from the final version) and for counting features.
Whenever I edit such a line new hidden character styles are inserted automatically at unwanted positions.

There are thousands of such styles in my document (500 pages, 3 languages, 12MB .fodt).
Is it possible to remove these styles?

I’m using LibreOffice 7.3.7.2 on Mac.

After disabling both Random number to improve accuracy in document comparison and Store it when changing the document, and then saving the document in ODF version 1.3 (rather than 1.3 Extended), the FODT file size decreases by 26% and the line count by 19%. Many (but not all) of the automatically generated character styles were discarded in this file format.

In the XML, styles have internal immutable “technical” names. This naming schema allows to change the user-visible name without having to modify the whole XML. Paragraph style name start with T, character with T, …

To know which effect a style has, you must look for its definition in the style directory using the “T10045” key. You’ll then find that it only contains a <style:text-properties officeooo:rsid="00205bc2"/> element. The rsid attribute allows to track and identify changes.

You can control this “addition” in Tools>Options, LibreOffice Writer>Comparison through the Store it when changing the document check box in Random number … section.

IMPORTANT: after changing this setting, close LO so that it takes effect on next restart. But it does not erase existing rsid.

I don’t remember the trick to disable rsid generation (@mikekaganski does), but I found a workaround to minimise the number of “technical” track changes styles: untick Edit>Track Changes>Show. All future changes will share a single character style. Unfortunately, this does not merge existing records.

You mentioned the correct setting. Doesn’t it work for you?

@mikekaganski: I checked with an example, but rsid are still generated. I event went to Advanced configuration and forced 2 parameters(*) to false (they were “void”, quite strange) to no avail. Only when I disable Track Changes>Show, all future changes are tagged with the same char style. This does not remove existing rsid.
My current LO is 7.4.5.1.

EDIT
Shame on me: I skipped one step. I didn’t close LO. After a restart, it is OK. I’ll correct my answer.

(*)They are in org.openoffice.Office.Writer, both have Preference Name equal to Comparison. Property is UseRSID and StoreRSID. They were Type void before I forced them to boolean false.

Thanks for your comments and suggestions. Here some further notes.

  1. If I understand correctly then, every edit to the Writer document generates a new style, when the option Randon number to improve accuracy in document comparison is on, and the answer Store it when changing the document is selected (as is the case by default). (This option is under Preferences>LibreOffice Writer>Comparison.)

  2. When I create a Character Style within Writer, its actual name (rather than its internal “technical” name) appears in the XML .fodt file, everywhere the style is used. This means it is possible to distinguish user-defined character styles from those that are generated automatically by document changes.

  3. What can be done in order to remove all these random number document comparison tags? Right now I’m applying a Perl script with regular expression substitutions on the XML .fodt file, but obviously this is error-prone. And would it be safe to remove all such random number tags in the document section of the .fodt file? Do you see a better way, preferably within LibreOffice Writer?

  1. Yes. Untick both boxes to stop adding revision “marks”.
  2. Wrong. Your user-readable name is recorded in the style dictionary as an attribute of the style definition. The “rsid” styles have no user-readable name and therefore are not listed in the style sidepane. In the XML encoding, only the “internal” name Pxxx, Tyyy, … is used. As I mentioned, if you change your style name, the change is made in the style dictionary only once and the rest of the XML is unchanged, retaining the strange internal name.
    In the XML itself, you can’t distinguish a user style from some Writer generated style like rsid or direct formatting.
  3. I have not looked carefully at the XML but as you say the process is error-prone and I fear that regular expressions are not powerful enough to handle the case. This is a job for a more sophisticated macro-generator (I have one if you’re interested, written in C for Linux – MacOS is based on FreeBSD, so it should compile). In my opinion, the first pass is to enumerate the rsid styles from the style dictionary. The second pass is the elimination pass. Considering you have possibly nested <text:span>, you must manage the nesting level in order to eliminate the correct </text:span>. This is something regular expressions can’t do.