Text FormattingKeep the Formatting for copied Text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
kr0w
Posts: 1
Joined: Wed Sep 19, 2012 4:26 pm

Keep the Formatting for copied Text

Post by kr0w »

Hello LaTeX users.

My problem is to copy programming code from a compiler (with the colors, spaces, and so on) into my Lyx document and KEEP the formatting (colors, etc.).

I want this output in PDF from LyX.
Output-LibreOffice.png
Output-LibreOffice.png (164.4 KiB) Viewed 3771 times
I've searched the Internet and found out that the writer2tex extension for LibreOffice Writer has the solution. So I copy the programming code to Writer (see link above), then exporting this text into .tex (which works fine too), open LyX and import the file as LaTeX (plain).

Now I see this:
Output-LyX.png
Output-LyX.png (252.92 KiB) Viewed 3771 times
It gives me errors of \usepackage "Option clash for package babel." and a lot of undefined colors "Undefined color `['."

I also tried to use TeXworks. It can export it to PDF and keep the format, but not inside my hand-in document (the other tab in my picture above) in LyX. It also shows me the LaTeX code and tried to copy it in LyX as Tex code, but didn't work either.

Do you have any idea of what I'm doing wrong or how I can solve this problem?
Last edited by localghost on Wed Sep 19, 2012 5:13 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Keep the Formatting for copied Text

Post by cgnieder »

Hi kr0w ,

Welcome to the LaTeX community!
kr0w wrote:It gives me errors of \usepackage "Option clash for package babel."

This most probable means that you're document is loading babel twice but with a different set of options.
kr0w wrote:and a lot of undefined colors "Undefined color `['."
In the red marked LaTeX code in your LyX document you can see

Code: Select all

\textcolor{[}{rgb}]{0.5803922,0.11765706,0.8745098}{public}
These are causing the errors. The \textcolor command takes two or three arguments, depending on the usage.
  1. Either \textcolor{<colorname>}{<text to be colored>}, for example \textcolor{red}{Attention!}
  2. or \textcolor[<colormodel>]{<specs>}{<text to be colored>}, for example \textcolor{rgb}{1,0,0}{Attention!}
In your case it should obviously be the second case

Code: Select all

\textcolor[rgb]{0.5803922,0.11765706,0.8745098}{public}
but is actually the first:

Code: Select all

\textcolor{[}{rgb}% all that follows now isn't argument to \textcolor
Since there nowhere is a color name [ defined you get these errors.

The best way to use code in a LaTeX document is by using the listings package. How you can use it with LyX I cannot tell as I am inexperienced with LyX.

Regards
site moderator & package author
Post Reply