LyXSoftware Listings and LaTeX Code

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
Caterpillar
Posts: 7
Joined: Fri Jan 13, 2012 3:43 pm

Software Listings and LaTeX Code

Post by Caterpillar »

One month ago I started studying LyX to write a software project documentation.
Everything is okay except for software listings.
I would like to have software listings like you can see in http://gapil.gnulinux.it/files/2011/12/gapil.pdf at page 641 (number of page, not number of pdf's page)
To do that I downloaded the .tex files of Gapil book at http://gapil.truelite.it/sources/browser/trunk

The software listings of Gapil book are under listati subfolder. I found out that the part of tex file that manages software listings are:

Code: Select all

\begin{figure}[!htb]
	\footnotesize \centering
	\begin{minipage}[c]{15.6cm}
		\includecodesample{cancellami/UDP_daytimed.c}
	\end{minipage}
	\normalsize
	\caption{Sezione principale del server per il servizio \textit{daytime} su     UDP.}
	\label{fig:UDP_daytime_server}
\end{figure}
So I tried to insert LaTex code into the Lyx document but it did not work. Before I get into specific error messages, is there anything wrong in this procedure I am doing?

LyX version: 2.0.2

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

Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

Software Listings and LaTeX Code

Post by Stefan Kottwitz »

Welcome to the board!

You need to
  • load the listings package in your preamble, such as by

    Code: Select all

    \usepackage{listings}
  • define the macro \includecodesample which you used. In your book example it is defined in macros.tex:

    Code: Select all

    \newcommand{\includecodesample}[1]{\lstinputlisting{#1}}{}
Put both in your document preamble.

Stefan
LaTeX.org admin
Caterpillar
Posts: 7
Joined: Fri Jan 13, 2012 3:43 pm

Software Listings and LaTeX Code

Post by Caterpillar »

Can I insert those lines in a single Tex commands box toghether with the lines I mentioned before?
I inserted a TeX code box like that

Code: Select all

\usepackage{listings}
\newcommand{\includecodesample}[1]{\lstinputlisting{#1}}{}
\begin{figure}[!htb]    \footnotesize \centering    \begin{minipage}[c]{15.6cm}       \includecodesample{cancellami/UDP_daytimed.c}    \end{minipage}    \normalsize    \caption{Sezione principale del server per il servizio \textit{daytime} su     UDP.}    \label{fig:UDP_daytime_server} \end{figure}
Caterpillar
Posts: 7
Joined: Fri Jan 13, 2012 3:43 pm

Software Listings and LaTeX Code

Post by Caterpillar »

How can I check if

Code: Select all

\usepackage{listings}
has been well loaded?
scottkosty
Site Moderator
Posts: 542
Joined: Sat Sep 01, 2012 6:38 am

Re: Software Listings and LaTeX Code

Post by scottkosty »

Note that LyX has natively supported "listing" for a couple of years now. Go to Insert > Program Listing. You can right-click on a listings inset (box) and go to "Settings" to get more control. Also look under Document > Settings > Listings for more customization.
Post Reply