Ask Your Question
0

How to maintain font color when text is imported but style is changed?

asked 2021-04-09 17:14:55 +0200

gek gravatar image

I import Matlab script with colored statements, copying from Matlab and pasting into writer doc (odt). I need to change the font style whose font color is defined automatic. What happen? All the color internal to a row ,say xxxxxxx (black) yyyy (green) green is maintained. But colored rows starting from the left margin , say xxxxxxxxxxxxx (green) are automatically changed to black. Of course I can recover by hand the original color (green) . I could also shift to the right the text, but I am wandering whether in the style definition there is a way to impede font color change. Enrico Canuto

edit retag flag offensive close merge delete

Comments

Matlab is an external program with its own rules. How this is encoded is per Matlab specification. Could you attach to your question a sample Matlab data file you import (the shorter the better) so that I can have a look at its markup? From that, I could then suggest a robust solution based on styles.

Note you can attach only to a question (not to a comment). For that, edit your question, scroll to bottom, type twice Enter and use the "paperclip" tool.

Please do not use Add Answer but edit your original question to enhance the details of your question (answers are reserved for solutions to a problem on this Q&A site).

ajlittoz gravatar imageajlittoz ( 2021-04-09 17:39:09 +0200 )edit

Actually, you can attach anything in a comment (done that already in several of my comments). Just "prepare" the operation by editing your question (or even starting a new one). BUT just CUT the new content without validating the answer and paste that code in the comment. This way, you keep the chronological chain of exchanges.

Hagar Delest gravatar imageHagar Delest ( 2021-04-09 17:45:14 +0200 )edit

3 Answers

Sort by » oldest newest most voted
1

answered 2021-04-09 19:07:17 +0200

ajlittoz gravatar image

The first snippet which is supposed to be the raw import (but I'd have liked to see it before it is imported in Writer) is a real mess of direct-formatting with a mixture of direct paragraph styles (or rather anonymous paragraph styles) and direct character styles.

In the second snippet, you forced the paragraph style to Text Code which replaced the paragraph style layer but left intact the direct character style layer.

Where the initial formatting used no character style, i.e. the font colour was specified in the paragraph style, you end up with formatting dictated by Text Code (as expected). This happens on lines which are homogeneous (a single set of attributes for the whole line).

If your line has several highlightings, the corresponding attributes are set in various character styles which are not erased by your user paragraph style.

The "Choose orbital type" line kept its colour because the initial space is separately encoded. The line has thus two sections necessitating two direct formatting sequences. These are not overridden, explaining why the line remained green.

To solve your problem, it is necessary to know exactly what Matlab hands over to Writer. In the absence of this information, you must design your own character styles and apply them on the sequences. After that, you can Ctrl+M to clear direct formatting. If your character styles are correctly designed, you should see no change.

To show the community your question has been answered, click the ✓ next to the correct answer, and "upvote" by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

In case you need clarification, edit your question (not an answer which is reserved for solutions) or comment the relevant answer.

edit flag offensive delete link more
1

answered 2021-04-09 19:24:59 +0200

I were you, I would try to learn a bit about macros and then create one that searches for text with each color and applies the relevant style depending on the color.

The time spent on building the code may be a time saver if you have to reformat many snippets like that.

You can ask in the forum (see my profile), there are macro gurus and already a lot of code examples.

edit flag offensive delete link more
0

answered 2021-04-09 17:59:29 +0200

gek gravatar image

updated 2021-04-09 18:42:44 +0200

C:\fakepath\Prova.odtThanks for your kind and quick reply. Actually i made other tests and I am confused about the reasons of the color change. Before to enclosed a case I will made other tests. Any way, the raw copy remains intact and if I change the font size intact. I will continue after other tests.

edit flag offensive delete link more

Comments

Always nice to have feedback, but on this site answers are reserved for solutions. In order not to confuse other users, be kind enough to use the more link at bottom of your answer (only you as answer owner can see this link) to "repost as a comment". Thanks.

ajlittoz gravatar imageajlittoz ( 2021-04-09 18:26:31 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2021-04-09 17:14:55 +0200

Seen: 36 times

Last updated: Apr 09