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?

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

1 Answer 1


One option is to use the verbatim environment:

The verbatim environment
  simply reproduces every
 character you input,
including all  s p a c e s!

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:

This is a very long line that breaks and is tiny...

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

https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings https://www.sharelatex.com/learn/Code_Highlighting_with_minted

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



def function():
  • The verbatim command works nice, but some parts of the text are not displayed, since the lines are sometimes too wide.
    – blackarrow
    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.
    – Paapaa
    Jul 24, 2016 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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