GeneralIs there a way of linking equations to a different tex file?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ThinkDifferent
Posts: 3
Joined: Thu Oct 21, 2010 5:54 am

Is there a way of linking equations to a different tex file?

Post by ThinkDifferent »

basically, we have a bunch of tex files describing various math models.
most of the time a model is an extension of an already existing one for which there is already a tex file with description. so, the equations describing a new model are equation from the old one + some extra stuff.

instead of just copying/pasting tex code, is there a way of creating a link (reference) to an equation in other tex file?

thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
AP
Posts: 6
Joined: Thu Mar 11, 2010 3:19 pm

Re: Is there a way of linking equations to a different tex f

Post by AP »

The simplest solution is that you define the recurring fragments as commands:
\newcommand{\codeA}{Here comes my code}.

The second option is that you define the different fragments in a dedicated files and include them with \input{codeA}.

There are also possibilities to do this with if-else statements, but it is rarely worth the effort.
ThinkDifferent
Posts: 3
Joined: Thu Oct 21, 2010 5:54 am

Re: Is there a way of linking equations to a different tex f

Post by ThinkDifferent »

thanks!
i'm not sure though how to use a newcommand in file model2.tex that was defined in model1.tex?
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Is there a way of linking equations to a different tex file?

Post by frabjous »

You see check out the xr package and see if it has the capabilities you need.
ThinkDifferent
Posts: 3
Joined: Thu Oct 21, 2010 5:54 am

Re: Is there a way of linking equations to a different tex f

Post by ThinkDifferent »

thanks.
looks like xr package only allows referencing from external files.

I think method using \input{..} would do the trick.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: Is there a way of linking equations to a different tex f

Post by frabjous »

You don't need to do anything special for cross references or newcommands defined in another file if you're using \input. With \input, it's more or less as if you had copied the contents of the inputted file into that spot of the other file. Labels and commands defined in the master file (or in an earlier inputted file) should just work. If if it's not for you, post an example of the kind of thing giving you trouble.
Post Reply