% \iffalse meta-comment
%
% Copyright (C) 2013 Eduardo C. Lourenço de Lima
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or (at your option) any later
% version. The latest version of this license is in
%
%
http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% \fi
% \iffalse
%
%<package>\NeedsTeXFormat{LaTeX2e}[1996/06/01]
%<package>\ProvidesPackage{copypaste}[2013/01/11 v0.1 Copy and paste]
%<*driver>
\documentclass{ltxdoc}
\usepackage{copypaste}
\usepackage{color}
\definecolor{orange}{rgb}{0.8,0.4,0.2}
\newcommand\announcement[1]{\begin{center}\color{orange}#1\end{center}}
\newenvironment{Description}
{\par\medskip\noindent\ignorespaces}{}
\newenvironment{synopsis}
{\begin{list}{}
{\setlength\parsep{0pt}
\setlength\itemsep{0pt}}}
{\end{list}}
\newenvironment{Example}[1]
{\if#1\else\paragraph{Example.}#1\fi}
{}
\newenvironment{page}
{\begin{center}\begin{minipage}[t]{0.5\linewidth}}
{\end{minipage}\end{center}}
\newcommand\TODO{\texttt{Todo:}}
\begin{document}
\DocInput{copypaste.dtx}
\end{document}
%</driver>
% \fi
% \changes{0.1}{2013/01/11}{Initial version}
% \GetFileInfo{copypaste.sty}
% \CheckSum{199}
% \DoNotIndex{\,,\@addtoreset,\begin,\closeout,\csname,\end,\endcsname}
% \DoNotIndex{\expandafter}
% \DoNotIndex{\@ifundefined,\immediate,\input,\jobname,\label}
% \DoNotIndex{\@makebox,\makebox,\mbox,\MessageBreak,\@namedef,\@nameuse}
% \DoNotIndex{\newcommand,\newcounter,\newenvironment,\newwrite,\noindent}
% \DoNotIndex{\normalfont,\openout,\PackageError, \par,\parskip,\ref}
% \DoNotIndex{\relax,\renewcommand,\setlength,\string}
% \DoNotIndex{\write}
% \title{The \textsf{copypaste} package\thanks{This document
% corresponds to \textsf{copypaste}~\fileversion,
% dated~\filedate.}}
% \author{Eduardo C. Louren\c{c}o de Lima \\ \texttt{
[email protected]}}
% \maketitle
%
%
% \announcement{This package is obsolete and has been superseded by the |clipboard| package.}
%
% \section*{Introduction}
%
% This package provides a basic framework for copying and pasting content
% into a single document, or across different documents.
%
% \section{Basic Usage}
% \begin{synopsis}
% \item |\savecopypaste| \marg{basename}
% \item |\yank| \marg{key} \marg{content}
% \item |\paste| \marg{key}
% \item |\opencopypaste| \marg{basename}
% \end{synopsis}
%
%
% \begin{Description}
% \DescribeMacro{\savecopypaste}
% The first step is to create a copy-and-paste apparatus.
% \begin{synopsis}
% \item |\savecopypaste| \marg{basename}
% \end{synopsis}
% \end{Description}
%
% \begin{Description}
% \DescribeMacro{\yank}
% The command |\yank| typesets \meta{content} and identifies it as \meta{key}.\footnote
% {\texttt{copy} is already defined in {\TeX}.}
% \begin{synopsis}
% \item |\yank| \marg{key} \marg{content}
% \end{synopsis}
% \end{Description}
%
% \begin{Description}
% \DescribeMacro{\paste}
% And |\paste| just typesets the content identified by \meta{key}.
% \begin{synopsis}
% \item |\paste| \marg{key}
% \end{synopsis}
% \end{Description}
%
% \begin{Description}
% \DescribeMacro{\opencopypaste}
% Finally, |\opencopypaste| makes available content from |doc1.tex| to |doc2.tex|. In that way, you can paste into |doc2.tex| content from |doc1.tex|. Make sure to use the same \meta{basename} in both documents.
% \begin{synopsis}
% \item |\opencopypaste| \marg{basename}
% \end{synopsis}
% \end{Description}
%
% \section{Example}
%
% This is how to copy |bar| from |doc1.tex| and paste it into |doc2.tex|:\bigskip
%
% \noindent |doc1.tex|:
% \iffalse
%<*example>
% \fi
\begin{verbatim}
\documentclass{article}
\usepackage{copypaste}
\savecopypaste{myfoo}
\begin{document}
\yank{foo}{bar}
\end{document}
\end{verbatim}
% \iffalse
%</example>
% \fi
%
% \noindent |doc2.tex|:
% \iffalse
%<*example>
% \fi
\begin{verbatim}
\documentclass{article}
\usepackage{copypaste}
\opencopypaste{myfoo}
\begin{document}
\paste{foo}
\end{document}
\end{verbatim}
% \iffalse
%</example>
% \fi
%
% \noindent Now, running:
%
% |$ latex doc1|
%
% |$ latex doc2|
%
% \noindent outputs 2 documents with the same content, namely, |bar|.
%
% \StopEventually
%
% \section{Implementation}
% \begin{macrocode}
\newwrite\@copypaste
\newcommand\savecopypaste[1]{%
\immediate\openout\@copypaste=#1.cpy}
\newcommand\opencopypaste[1]{%
\input{#1.cpy}}
\newcommand\yank[2]{%
\defcopy{#1}{#2}%
\immediate\write\@copypaste{\noexpand\defcopy{#1}{\unexpanded{#2}}}%
#2}
\newcommand\defcopy[2]{%
\@namedef{@copypaste@#1}{#2}}
\newcommand\paste[1]{%
\@nameuse{@copypaste@#1}}
% \end{macrocode}