TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to merge two repository where each one contains a lot of LaTeX files. Each repository contains a lot of macros files. Some macros are shared between the repositories.

However, in these shared macros, some don't display the same thing. Since there are a lot of files, I'd like to know if there is an easy way to rename conflicted macros without doing some ugly search-replace.

For the same reason, the solution listed here would be very time-consuming, so I'd like to avoid it.

share|improve this question
it sounds like the text from the two projects is to be "interleaved", rather than having one follow the other, unchanged. if you can identify the commands that have the same names but different meanings, one approach might be to segregate the files from each project, choose a new name for one member of each such pair, and write a perl script to make suitable replacements in just (copies of) the files for the project for which the names need to be changed. keep good notes. – barbara beeton Sep 3 '13 at 15:22
You're right in your description of the problem. However, what I'd like to avoid is writing the perl script, especially if there is an appropriate already existing tool. – fxm Sep 3 '13 at 15:27
most likely a simple search/replace is the easiest but what do you mean by "merge" do you really need to finely integrate them or is it more at the level of combining different sections, if the latter you can put your macro definitions into two sets and then just use \definitionsA .... stuff using set A ... \definitionsB ....stuff using set B \definitionsA .... stuff using set A again – David Carlisle Sep 3 '13 at 15:30
You could create a pair of environments, say, project1 and project2, and in each one, declare the appropriate commands with the correct definitions for each project. Then you can surround each chunk from the separate projects with their environment, and the commands work without change. If you are already copy-pasting text from both files, it is only a small amount of extra work to add the environments. – Ryan Reich Sep 3 '13 at 15:30
@DavidCarlisle the trouble is the number of files. Doing so would be very time consuming – fxm Sep 3 '13 at 15:49

I'd do the following.

Assume that the first project has f1.tex, f2.tex etc., and the second project has s1.tex, s2.tex etc. We want to be able to include them in arbitrary order. Assume that the conflicting macros that are defined differently in the two projects are called \foo and \bar.

% packages...
\newcommand{\firstfoo}{<first definition of \foo>}
\newcommand{\secondfoo}{<second definition of \foo>}
\newcommand{\firstbar}{<first definition of \bar>}
\newcommand{\secondbar}{<second definition of \bar>}

% etc. ...

This is only a skeleton and I haven't tested it, there may be errors.

Someone with more TeX knowledge could make a generalised solution to n projects where you can do something like

\multipledef{\foo}{3}{<first def>}{<second def>}{<third def>}

where 3 is the number of definitions and


where 2 means "use the second definition" but that's beyond my knowledge.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.