In a different question, I wondered whether it would be possible select some formatted text and apply a character format style to it without destroying the formatting. In comment 3644204, Graham Skan correctly assured me that it would be impossible to do so.
I subsequently looked at some documents that I had massaged with some long-since lost code, and the documents show formatted text with a character style applied to them. I use the character style to hide or show certain words. For example, the attached document, an excerpt from one of my old documents, hides or shows a comment. Shift + Alt + J hides the blue text that has a character formatting of “LB Mont Comment”. Shift + Alt + Y exposes the “LB Mont Comment” text. The text that is either displayed or hidden has some italics.
Apparently there is a way to have text formatted accomplish that through code. I know that if some words already have a specific character style, one can format the words manually without losing the character style. I suppose that before I have the computer apply a character style to some words, I can have it search for things like italics, underlined text, or boldface text, and have the code put unique marks at the start and end of such areas. Then after I subsequently apply the character style that destroys formatting, I could have the computer search for those markings and reformat the text according to what is needed. To avoid having the computer mark other formatted text in the document, I think I would have to make a new document, cut and paste the text to be reformatted into the new document, make my style marking there, and then copy and paste the marked text back into the original document, apply the character style to it, and then apply the formatting as per what markings the text has.
I suspect there might be an easier way to do the same thing, but if necessary, I will do it the hard way. However, I would appreciate some suggestions as to how those tasks could be done more easily.