# How to print any command on the PDF document exactly like in the TeX file?

\documentclass{article}
\begin{document}
My text.
\end{document}


Here 'My text' is the output.But I want to get the following output:

\begin{document}
My text
\end{document}


Is there any way to get this output ?

-
Here 'My text' is the output.But I want to get the following output: '\begin{document} My text \end{document}'. Is there any way to get this output ? –  Md Kutubuddin Sardar Mar 19 '13 at 13:16
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces or enclose words in backticks , they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). –  hpesoj626 Mar 19 '13 at 13:17
Are you asking about the verbatim environment? –  JLDiaz Mar 19 '13 at 13:20
Related/Duplicate: How do I print a syntax-highlighted LaTeX source file? –  hpesoj626 Mar 19 '13 at 13:31
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Apr 20 '13 at 10:49

Yes. Use the verbatim environment.

\documentclass{article}
\begin{document}
\begin{verbatim}
\begin{document}
My text.
\end{document}
\end{verbatim}
\end{document}


If you want to output the whole source code of some file, say myfile.tex, you can make a frame file and use \VerbatimInput from the fancyvrb package:

\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\VerbatimInput{myfile.tex}
\end{document}

-
with \usepackage{verbatim}, \verbatiminput{myfile.tex} (lowercase \verbatiminput) does the same thing. if you want a file to input itself, you can say \verbatiminput{\jobname.tex}`. (great for documenting small examples.) –  barbara beeton Mar 19 '13 at 15:10