Math & ScienceHow do I format text in listing?

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Medova
Posts: 28
Joined: Thu Nov 06, 2008 4:20 pm

How do I format text in listing?

Post by Medova »

I want to include the code in the attached file "parameter.txt" in my report. The format that I want is \texttt and a textsize so that it doesn't exceeds the margin; \footnotesize, \small, or alike (for this application line breaks are not acceptable).
I have looked at the documentation for the listings package. I don't get much of it but it seems like the Keyword style should give me what I need, just can't get the syntax right. Can anyone help me with this?
Thx...

Code: Select all

Code, edit and compile here:
\documentclass[a4paper,11pt,twoside,openright,fleqn]{report}
\usepackage[english]{babel}
\usepackage{listings}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\begin{document}
Just som random text to show margins. Just som random text to show margins. Just som random text to show margins.
\lstset{frame=none,breaklines=on,columns=fixed}
\lstinputlisting{./parameter.k}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Attachments
parameter.txt
(585 Bytes) Downloaded 273 times

Recommended reading 2024:

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

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

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How do I format text in listing?

Post by localghost »

Medova wrote:[…] The format that I want is \texttt and a textsize so that it doesn't exceeds the margin; \footnotesize, \small, or alike (for this application line breaks are not acceptable).[…]
See the listings manual (Section 4.6 - Figure out the appearance, p. 28ff) and look at the basicstyle option.


Thorsten
TritonMan
Posts: 8
Joined: Tue Jun 01, 2010 1:58 am

How do I format text in listing?

Post by TritonMan »

Hi Medova,

I used

Code: Select all

Code, edit and compile here:
\usepackage{listings}
\usepackage{color}
\definecolor{offwhite}{rgb}{0.99,1,0.84}
\definecolor{lightgray}{gray}{0.6}
\definecolor{myred}{rgb}{0.9,0,0}
\definecolor{myblue}{rgb}{0,0,0.5}
\definecolor{mygreen}{rgb}{0,0.5,0}
\lstset{ %
language=sh, % choose the language of the code
basicstyle=\footnotesize\ttfamily, % the size of the fonts that are used for the code
keywordstyle=\color{myred}\textbf,
identifierstyle=\color{myblue}\textbf,
commentstyle=\color{lightgray},
stringstyle=\color{mygreen},
morestring=[b]`,
showstringspaces=false, % underline spaces within strings
breakindent=0em,
breaklines,
breakatwhitespace=true,
numbers=left, % where to put the line-numbers
numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
stepnumber=2, % the step between two line-numbers. If it's 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{offwhite}, % choose the background color
showspaces=false, % show spaces within strings adding particular underscores
showtabs=false, % show tabs within strings adding particular underscores
escapeinside={\%*}{*)} % if you want to add a comment within your code
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
to typeset bash scripts in a report with syntax highlighting (so lots of style changing!). Obviously I needed to include the color package to define and change colours.

I believe the bit that may be pertinent is to use \ttfamily in your style, rather than \textt{}, but I may be wrong (I'm still learning!).

Hope this helps though.
Post Reply