How to include (print) Latex source code in generated pdf?

if the purpose of this exercise is to make the source code visible to readers of the pdf file, say to document self-contained code examples, i've had excellent results with this simple approach.

\documentclass{article}
\usepackage{verbatim}

% your preamble

\begin{document}

% your text

\newpage
\verbatiminput{\jobname.tex}
\end{document}

[OPs answer moved from question]

I found a way to do this. You have to use listings as follows.

\usepackage{listings}
\lstset{breaklines=true}

% optional ˇ
\lstset{literate=%
{Ć}{{\'C}}1
{ć}{{\'c}}1
{Č}{{\v{C}}}1
{č}{{\v{c}}}1
{Š}{{\v{S}}}1
{š}{{\v{s}}}1
{Đ}{{\DJ}}1
{đ}{{\dj}}1
{Ž}{{\v{Z}}}1
{ž}{{\v{z}}}1
}
% optional ^


\begin{document}

%text

\lstinputlisting{SourceCodeFile.tex}

\end{document}

In the \lntinputlisting{} goes the file path. I used \lstset{literate=% ... for special characters that you have to define.I tried to find a way without using literate but nothing worked.

Tags:

Pdf

Pdftex