# Ignoring LATEX special characters

I have to add in a Latex document a page with the code from program I use for the report. However, when I simply copy and paste the code into Latex, I get a ton of warnings. Is there a way to tell Latex to ignore all of the special characters in the code, just in this part of the report?

• Packages like listings or minted take care of that/ Jul 24, 2016 at 12:02

One option is to use the verbatim environment:

\begin{verbatim}
The verbatim environment
simply reproduces every
character you input,
including all  s p a c e s!
\end{verbatim}


Sample taken from here: https://en.wikibooks.org/wiki/LaTeX/Paragraph_Formatting#Verbatim_text

Similar environment with line breaking and a tiny font size using listings package:

\begin{lstlisting}[breaklines,basicstyle=\tiny]
This is a very long line that breaks and is tiny...
\end{lstlisting}


And like Johannes_B wrote, there are dedicated packages for displaying source code listings:

They allow line nubering, syntax coloring etc. Example using minted package:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{minted}

\begin{document}
\begin{minted}[frame=lines,linenos]{python}
def function():
return
\end{minted}
\end{document}

• The verbatim command works nice, but some parts of the text are not displayed, since the lines are sometimes too wide. Jul 24, 2016 at 12:41
• Ok. There are ways to fix that: break lines or change font size to smaller. I added an example to both break the lines and decrease the font size using lstlistingenvironment. Jul 24, 2016 at 12:51