In MS Word I can copy the text of computer code I am writing and paste it into Word. After I paste there is a little box below the pasted text that will let me keep source formatting (color, fontname, etc). How can I do that in Writer?
From where do you copy the code? (e.g. Website) and how do you copy it? (e.g. CTRL+C)
You can analyse what is actually copied, by installing a clipboard manager and see if formating is actually copied / available or not. In some cases, MS Tools(word/exel/…), just insert images of copied areas, to get around this issue, which if find quiet missleading. Also this might be of interest, even if it is a bit dated. Libre-Office Writer Pasting with source formatting
I copied the code from the editor in MATLAB. I used right-click then copy.
Mmmh, i personally do not use MATLAB, but from my expericne, these IDE - Editors dont normaly provide extensive formating. But i could be wrong.
I know it works with Word, because I have done it dozens of times. I think it might be a Ubuntu issue because I am switching from Win10 to Ubuntu as a trial run.
Since you are on ubuntu you could try installing a clipboard manager (6 Best Clipboard Manager for Ubuntu | TechWiser) and see if what is copied actually contains formatting. Post a screenshot maybe.
If your pasted text has some formatting (color, font face, …), this means it is not pure unformatted text but contains some mark up. Usually IDEs (integrated development environment) decorate source programs internally and do not make explicit the mark up. When you copy a sequence, you get unformatted text.
If M$ Word can keep such formatting,
- either your IDE hands over the mark up, and the question is “what is the format of the text?” to see if Writer can handle it;
- or Word detects somehow this is a source program and macro(s) are launched to attach formatting to it (I sort of remember there are extensions for this job)
A poor substitute is to apply Preformatted Text paragraph style to the text. This style can be customised to change the background, add borders or other attributes to make clear this is a special text.
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!