# Producing self-contained source?

Is there a way (terminal command?) to take a TeX file, possibly with externally linked macros, bibstyle files, bibTeX source, etc., and automatically produce a single, self-contained TeX file? For example, I could generate the bbl file, copy and paste the entries there and add to the source, but it gets tedious. Anyone solve this problem?

• just stick bib files bst files and anything else you need at the start of the tex document, in filecontents environemnts. – David Carlisle Jul 2 '17 at 22:09
• @HenriMenke Not really a duplicate. This question rather needs that plus one or more of the linked bibliography strategies to create a document-specific .bib etc. – cfr Jul 3 '17 at 1:14
• @DavidCarlisle Can you elaborate on your suggestion? So if I have a file with macros stored in some central directory (so as to avoid duplication in the working directory, and also clutter in the document), and I want to include that in a document I'm currently working on, how would I use filecontents? I looked at the documentation for the package but couldn't figure out how it would work for this purpose. Thanks! – Skeptic Jul 3 '17 at 14:12
• you don't need a package, I'll post an example – David Carlisle Jul 3 '17 at 14:47

This document bundles up a local latex package and a local bibtex database as a single file, usimg filecontents, producing

\begin{filecontents}{mypackage.sty}
\def\zzzz{Hello}
\end{filecontents}
\begin{filecontents}{zzz.bib}
@article{zz99,
title={something},
author={M. Eee and Y. Ouoo},
journal={TugBoat},
volume={14},
number={2},
pages={200--100},
year={1884},
publisher={example.org}
}
\end{filecontents}
\documentclass{article}

\usepackage{mypackage}

\begin{document}

\zzzz, \cite{zz99}

\bibliographystyle{plain}
\bibliography{zzz}

\end{document}