LaTeX forum ⇒ 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.
ThinkDifferent
Posts: 3
Joined: Thu Oct 21, 2010 5:54 am

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

Postby ThinkDifferent » Thu Oct 21, 2010 7:38 am

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

AP
Posts: 6
Joined: Thu Mar 11, 2010 3:19 pm

Postby AP » Thu Oct 21, 2010 10:35 am

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

Postby ThinkDifferent » Thu Oct 21, 2010 11:53 am

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

Postby frabjous » Thu Oct 21, 2010 5:05 pm

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

Postby ThinkDifferent » Fri Oct 22, 2010 6:38 am

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

Postby frabjous » Fri Oct 22, 2010 6:50 am

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.


Return to “General”

Who is online

Users browsing this forum: No registered users and 9 guests