Go to page:

Search:   Help



LyX documentation


Shared groups



Categories: Tips
<< | Page list | >>

How to include a file containing math-macros in child documents (LyX < 1.6).

If you do a fair bit of math in LyX, you will soon want to create one or more files containing common math-macro definitions, which you can then include in other files on which you are working. This will work, as LyX will parse the included file and use it just as if the definitions were in the file itself. However, (up to 1.5.x) preview will work only if the file containing the definitions is opened before the file in which it is included. Math-macro support is completely revamped in LyX 1.6.

You can run into problems, however, if you try to use this technique with a master document that includes various child documents. To get preview to work correctly, you have to include the macro definitions in your child documents. But then, when you compile the main document, LaTeX will choke on all the redefinitions of the macros.

With LyX 1.5.x, you can include (or insert) the math-macro file in a branch and deactiveate (or just not define) this branch in the parent document.

With LyX < 1.5 read on:

Solution: At the beginning of the file, add ERT containing e.g.: \ifx\EPS\undefined, and then at the end of the file add ERT containing: \fi. Here, EPS can be any macro you define in the file and "undefined" can be any macro that you know will remain, uh, undefined. If \EPS is defined, LaTeX will skip the definitions: No choking.

Solution2: Create a new document where you define all your macros with the math-macro command. In the preamble of your master document and of your child document you put the command "\include{macros}". (you find the preamble in Layout>>Document...>>Preamble) This makes sure that you can preview your child document and the master document. At the same time only the preamble of the document where you actually press View>>something is processed so you don't get an error because a macro is already defined. If you now want a nicer display in your Lyx-document (not in the dvi/pdf/whatever-output, that's already done) you can include the file macros.lyx in every document which should provide a nicer output. Just include the file Insert>>Include file... using the input-method and put this input in a comment-environment. This way Lyx can see the input and provides the nice output but LaTex doesn't see it! (You may have to reload your document to see the effect.)


Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2008-06-24 11:12 CEST