\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}
If you're willing to add a single space before the <<>>
and the @
, that'll do the trick. (The Sweave driver only interprets as chunks blocks of text beginning with <<>>=
at the beginning of a line -- no spaces allowed!)
Your input file will now look like this:
\documentclass{article}
\begin{document}
\begin{verbatim}
<<>>=
1+1
@
\end{verbatim}
\end{document}
And your output file will look like this, possibly indented, but without leading spaces:
<<>>=
1+1
@
ADDED LATER
Alternatively, you can use a chunk of R code that, when Sweave'd, uses cat()
to output the desired tex code. This solution is probably formally better (in some sense), and also works as desired:
<<results=tex, echo=FALSE>>=
cat("",
"\\begin{verbatim}",
"<<>>=\n",
"1+1\n",
"@\n",
"\\end{verbatim}")
@
Best Answer
You can use
alltt
,fancyvrb
orlistings
package for this purpose.For
fancyvrb
, see manual "4.1.16 Catcode characters". Example:It is easier to use
listings
package, see manual "4.14 Escaping to LaTeX". Example: