LyXInserting C++-Code gets really messy

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
raycluster
Posts: 2
Joined: Thu Jan 24, 2013 12:42 am

Inserting C++-Code gets really messy

Post by raycluster »

Hi ;)

I tried to insert this:
listing.png
listing.png (30.87 KiB) Viewed 5671 times
into LyX, but all I get is this:
lyx.png
lyx.png (77.42 KiB) Viewed 5671 times
I tried many different programs to copy the code from, and also tried to convert my source to different codings, but nothing works. Please help, I need to get this code into my document :(
Last edited by Stefan Kottwitz on Thu Jan 24, 2013 11:22 am, edited 2 times 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.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

tommytex
Posts: 39
Joined: Wed Jan 23, 2013 10:04 pm

Inserting C++-Code gets really messy

Post by tommytex »

Hi,

i would use the listings-package written by Casrten Heinz. You can easily insert C code by typing

Code: Select all

\begin{lstlisting}[language=C, frame=single, felxiblecolumns=true]
void main(void)
{
...
}
\end{lstlisting}
I don't know how to implement latex code in lyx :mrgreen:
User avatar
tommytex
Posts: 39
Joined: Wed Jan 23, 2013 10:04 pm

Inserting C++-Code gets really messy

Post by tommytex »

take a look at wiki...

http://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings

the \lstinputlisting-command can be used to implement files:

Code: Select all

\lstinputlisting[firstline=17,lastline=20]{prog.c}
to include line 17 to 20.

You can define single parts of the file:

Code: Select all

\lstdef{part1}{mycfile.cpp}{1}{5}
then use

Code: Select all

\lstuse{part1}
to include this part of the file. ;)
raycluster
Posts: 2
Joined: Thu Jan 24, 2013 12:42 am

Re: Inserting C++-Code gets really messy

Post by raycluster »

I worked it out.
Instead of inserting the Code with CTRL-V, insert it with CTRL-SHIFT-V. This removes any formatting inside the clipboard before pasting it to the textfield of a program. ;)
Post Reply