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?




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



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

Here is some more text \ref{foobar}.


2 Answers 2


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


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, 2013 at 10:57
  • tex.stackexchange.com/questions/7627/how-to-reference-paragraph this is the link for refer a paragraph
    – user30816
    May 16, 2013 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.tex

%first argument is the name of the stuff to repeat
%second argument is the content
   % 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

% open file stufftorepeat.tex

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


Here is file2

# file2.tex



Repeated from file1:
More text from file1:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .