I occasionally face the following situation when writing LaTeX documents. (This question is probably not LaTeX specific, though). Suppose I have a document, say orig.tex
. Then I quote from that document in another document, say new.tex
. So, for example… orig.tex
is
\documentclass{article}
%% orig.tex
\begin{document}
Here is some text. {This is some text I want to quote.} Here is yet
more text. The quick brown fox ran over the lazy dog.
{I want to quote all the text in this para. Some more text to get this
line to wrap.
And this para as well, in one quotation.}
\end{document}
and new.tex
is
%% new.tex
\documentclass{article}
\usepackage{quoting}
\begin{document}
Quotation one from orig.tex is
\begin{quoting}
This is some text I want to quote.
\end{quoting}
Quotation two from orig.tex is
\begin{quoting}
I want to quote all the text in this para. Some more text to get
this line to wrap.
And this para as well, in one quotation.
\end{quoting}
\end{document}
However, the problem is that after I have copied in these quotations to new.tex
, I may change the text in orig.tex
. I want LaTeX to automatically copy the text across from orig.tex
to new.tex
. Each quotation could be associated with some kind of label.
The curly braces in orig.tex
mark the quotation start and end points. This is a stand-in for proper macro or function usage. This will cause some clutter in the original document, but I can remove these markers after the new.tex
has been sent off. Till then, I want these two documents to stay in sync.
For simplicity, let's assume these quotations are non-overlapping, as this would add extra complexity to the problem. However, as shown in the example, they may cross line and paragraph breaks.
The closest thing in terms of functionality that I am aware of is the xr package by our very own David Carlisle :-), but I don't know if it can be adapted for use here.
UPDATE: Apparently this question wasn't as clear as it should have been. I just used {}
's in orig.tex
because I wasn't sure what kind of syntax to use, but I was thinking of something along the lines of some macro like \c
(for cut) in orig.tex
, thus,
...\c[label]{some text to quote}
and then another macro \p
for paste, which inserts that text in new.tex
, thus.
...\p[label]...
UPDATE2: Thanks to Peter Grill, David Carlisle, and Aditya for their answers.
I have tested both Peter's macro solution and David's solution. A choice between the two of them would have been difficult. However, Peter's approach uses the standalone package, which seems to have some bad interactions with the custom class I'm using, Springer's svmult.cls
. I was on a deadline and didn't want to take the time to figure this out, so I went with David's solution, which has no package dependencies, and worked for me.
I think this code is worth packaging – I'm surprised it does not exist as a package already. Handling multiple input files would be a desirable feature, though.
I haven't tested Aditya's solution, but plan to do so.
Best Answer
I don't think picking up just on brace groups is viable, there are too many braces in a TeX document. I used
\q{...}
here.After clarification in chat and comments, a version with named references.
orig.tex
new.tex
qting.sty
The main restrictions are that:
You can't have two
\q
on the same line in the original document. Or more exactly, everything on the line after the}
of a\q
is ignored.Any
\q
inside brace groups will not be seen by the scanner (as it uses TeX delimited arguments to look for\q
tokens). This may be used to hide\q
that may have locally different meaning, but does mean that you have to arrange that any text that you do want to quote is at the top level of the original file.Extended version of this code placed at
http://code.google.com/p/dpctex/source/browse/#svn%2Ftrunk%2Fqting