1

This question already has an answer here:

I have a code of around 350 lines, and I need to paste it inside a LaTeX file without losing the formatting such as the extra spaces. What do I need to use to get this in LaTeX?

marked as duplicate by Zarko, Stefan Pinnow, Maarten Dhondt, moewe, Paul Gaborit Apr 22 '16 at 6:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    What "code" exactly do you have? Is it some source code that you want to show as a listing (use verbatim then)? Could you copy-paste a few lines here as an example? – Georges Dupéron Apr 21 '16 at 22:56
  • 2
    Have a look at the listings package. You can include an external file with \lstinputlisting. – Andrew Apr 21 '16 at 23:00
5

You can use the package \usepackage{listings} and put your code in the following way

\begin{lstlisting}
Put your code here.
\end{lstlisting}

For information, you can read the wikibook LaTeX/Source Code Listings at https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings

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