Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In LaTex, I use \verbatim to add a block of text. But the problem is that the verbatim text doesn't follow the page style, and it exceeds the page boundary if the text is long. The result is shown as below:

enter image description here

As you can see, the example call exceeds the boundary. That's where I use verbatim. The following is my code to set up verbatim text, could anyone tell me how to fix this problem? I will appreciate. I am kind of in a rush to get it done.

% Used by @verbatim ... @endverbatim
\newenvironment{DoxyVerb}{%
  \fontencoding{OT1}\fontfamily{cmr}\fontseries{b}\fontshape{n}\fontsize{10pt}{10}\selectfont%
  \verbatim%
}{%
  \endverbatim%
  \normalsize%
}
share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

enter image description here

\documentclass[dvipsnames,cmyk]{article}
\usepackage{listings,xcolor}

\lstset
{
    breaklines=true,
    tabsize=3,
    showstringspaces=false
}


\lstdefinestyle{Common}
{
    extendedchars=\true,
    language={[Visual]Basic},
    frame=single,
    %===========================================================
    framesep=3pt,%expand outward.
    framerule=0.4pt,%expand outward.
    xleftmargin=3.4pt,%make the frame fits in the text area. 
    xrightmargin=3.4pt,%make the frame fits in the text area.
    %=========================================================== 
    rulecolor=\color{Red}
}

\lstdefinestyle{A}
{
    style=Common,
    backgroundcolor=\color{Yellow!10},
    basicstyle=\scriptsize\color{Black}\ttfamily,
    keywordstyle=\color{Orange},
    identifierstyle=\color{Cyan},
    stringstyle=\color{Red},
    commentstyle=\color{Green}
}

\lstdefinestyle{B}
{
    style=Common,
    backgroundcolor=\color{Black},
    basicstyle=\scriptsize\color{White}\ttfamily,
    keywordstyle=\color{Orange},
    identifierstyle=\color{Cyan},
    stringstyle=\color{Red},
    commentstyle=\color{Green}
}

\begin{document}

\begin{description}
\item[Visual Basic] is a programming language from Microsoft.
\begin{lstlisting}[style=A]%please try style=B
Option Explicit

Sub Signal(strSignalfolge As String, Optional lngTakt As Long = 100)
'Prozedur erzeugt eine Serie von Warntönen.
'Die optionale Variable lngTakt gibt den Takt in Millisekunden vor (Standard: 100 ms)
'Das Muster kann über die String-Variable strSignalfolge beeinflusst werden:
' Stern (*)     -> 1 Warnton
' Ziffern 1..9  -> 1..9 Takte Pause
' Leerzeichen   -> 1 Sekunde Pause
' Minus (-)     -> 1.5 Sekunden Pause
End Function
\end{lstlisting}
\item[Visual CSharp] is my favourite programming language.
\end{description}
\end{document}
share|improve this answer
    
There are too many settings available in listings.sty such as framing, coloring, etc. If you need more details, type texdoc listings in you command prompt. –  xport Jul 19 '11 at 16:22
    
It really helps. Thanks a lot –  Jason Xu Jul 19 '11 at 18:17
add comment

Verbatim mode is quite special and doesn't work inside other macros or environments (except for verbatim environments which are specially written for this). I would recommend to use a verbatim related package like listings. It allows you to define own environments including font changes and line wrapping. It also supports syntax highlighting for a lot of different languages.

\documentclass{article}

% Recommended to get bold text typer font:
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{listings}

\lstnewenvironment{DoxyVerb}{%
    \lstset{%
        basicstyle={\fontencoding{OT1}\fontfamily{cmr}\fontseries{b}\fontshape{n}\fontsize{10pt}{10}\selectfont},
        breaklines,
        language=C,
    }%
}{%
}

\usepackage{lipsum}% for dummy text
\begin{document}
\lipsum[1]

\begin{DoxyVerb}
uint16 someparameter;


someparameter_init_procedure_very_long_name = some stuff + even more ; // And also a comment afterwards

int random() {
   return 4; // chosen by fair dice roll
}
\end{DoxyVerb}

\lipsum[2]

\end{document}

Result

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.