# Is it possible to refer some text from file1 in file2?

I have two files, say file1 and file2

suppose in file1

...bla bla bla, I am text in file1..., I want to repeat it in file2... bla bla bla...

I want to repeat some text in file1 (I am text in file1..., I want to repeat it in file2...) in file2.

Expecting content in file2:

some text, some text... the following sentences from file1 "I am text in file1..., I want to repeat it in file2..." has been revised. more text, more text

This is just for avoiding repeated revision of those text in both files.

Is it possible to do it automatically?

Just seconds before, I found the following code is available for one file, but how improve it to fit on two files conditions?

\documentclass{minimal}

\makeatletter

\newcommand{\customlabel}[2]{%

\protected@write \@auxout {}{\string \newlabel {#1}{{#2}{}}}#2}

\makeatother

\begin{document}

Here is some text. \customlabel{foobar}{asdasd asdfasdf asdfasdf}

Here is some more text \ref{foobar}.

\end{document}


By far the simplest way is to put

(I am text in file1..., I want to repeat it in file2...)


in a file file-shared.tex and then have each of file1 and file2 say

\input{file-shared}


At the relevant points in the text.

• Thanks, that was what I just know as well. but in my paper, there are far too many revisions, I wonder if I can do it without adding too many files. I don't really care about the complexity, I just want it work! I have also found some body could use \ref or \nameref to refer a paragraph, is there any possiblity to create a new environment such as "sentences", so that I can use \ref and \nameref to refer the content? thanks in advance – user30816 May 16 '13 at 10:57
• tex.stackexchange.com/questions/7627/how-to-reference-paragraph this is the link for refer a paragraph – user30816 May 16 '13 at 11:05

Here is pseudocode for a strategy that uses just one file to hold the stuff to be repeated. You have to remember the names of the pieces, but that would be necessary with ref commands too.

The outline is too long for a comment.

Working out the details is more than I have time (or knowledge) for now. Maybe you can do it, perhaps with something like the code you added to your question, or someone else can. I can remove this answer if someone provides one with working code.

file1

% file1.tex
\documentclass[12pt]{article}

%first argument is the name of the stuff to repeat
%second argument is the content
\newcommand{\stufftorepeat}[2]{%
% write to stufftorepeat.tex, expanding just the right
% amount of input (not something I know how to do)
% \newcommand{\#1}{#2}
%
% now just put stuff here
#2
}

% open file stufftorepeat.tex
\begin{document}

Some normal text
\stufftorepeat{firstbatch}{blah, blah, blah}
More text.
\stufftorepeat{secondbatch}{whatever}
% close stufftorepeat.tex

\end{document}


Here is file2

# file2.tex
\documentclass[12pt]{article}

\input{stufftorepeat}

\begin{document}

Repeated from file1:
\firstbatch{}
More text from file1:
\secondbatch{}

\end{document}