I want to include the source code of my latex generated pdf file in the pdf file itself as printed text. Is there any way to do this?
4 Answers
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}
- 88,848
-
1
-
-
1@cyber_snipa -- i think you might still be able to accept the answer by clicking on a check mark. and since the alleged duplicate question really addresses a different problem, i will vote to reopen. i will also edit the title to add "(print)", and similarly the text, which should make the intent clearer. (you could do that, of course, but i'm being impetuous today.) – barbara beeton Jan 30 '14 at 13:36
-
Sorry for double post, but I got a problem, the lines of the source code are not wraped. How to force that? Sorry if this is a dumb question, I am very new to latex. – cyber_snipa Jan 30 '14 at 13:37
-
@cyber_snipa -- i don't know of any verbatim package that wraps long lines. however, two of the authors of
verbatim(rainer schoepf and bernd raichle) should be reachable at the addresses given in the documentation, and i think that asking if a "wrap line, length" option could be provided would be reasonable. (the system i use tex on handles "hard returns" quite happily, so i just keep all my lines short. but this doesn't work for everyone.) – barbara beeton Jan 30 '14 at 14:09 -
I figured something out with listenings. Thanks for the help nonetheless. – cyber_snipa Jan 30 '14 at 15:41
-
@cyber_snipa -- if you have a good answer with
listings, you might edit it into your question. that would help people looking for a solution to this problem in the future. – barbara beeton Jan 30 '14 at 15:54 -
@cyber_snipa,there are several "prettyprinting" packages around, check CTAN. – vonbrand Jan 30 '14 at 15:56
Use the package attachfile and put \expandafter\attachfile\expandafter{\jobname.tex} in your file. This will attach the *.tex-file to the pdf (thanks to Heiko Oberdiek, who answered this question years ago).
- 30,892
[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.
- 259,911
- 34
- 706
- 1,036
Here is what you can do if you want to print an example.tex code in a PDF file.
\documentclass{article}
\usepackage{verbatim}
% Rest of preamble
\begin{document}
\begin{verbatim}
% Enter your .tex code here
\end{verbatim}
\end{document}
- 159
- 193
attachfile– Jan 29 '14 at 21:41attachfilepackage doesn't seem to cover the territory, nor do the answers to the question cited by @Daniel.) – barbara beeton Jan 29 '14 at 21:49