I have many separate documents in subfolders that each \include a *.tex file in the parent directory that contains macros. This worked fine the last time I compiled these files, about 10 years ago and using MikTeX on a PC. Now I am using TeXShop on a Mac and am getting an error.

Here is an MWE:




    Main file


Contents of mwe_macros.tex, located in parent directory:


Here is the console window, with the error messages:

enter image description here

Suggestions? Thanks.

  • 1
    Use \input. \include is not intended for use in the preamble. It is intended for e.g. inclusion of chapters etc. which you might want to compile alone. \input does not have the same assumptions/restrictions. – cfr Jan 24 '16 at 1:21
  • It may be that 10 years ago or MikTeX or whatever doesn't have the security restriction of generally prohibiting writes to directories above the working one. You can disable this restriction, but doing so isn't recommended as it is intended to mitigate security issues. \input, unlike \include, doesn't try to write anything to the directory of the included file, so the restriction isn't a problem. – cfr Jan 24 '16 at 1:27

\include is really intended for the inclusion of chunks of a document which you might want to compile on their own while working on them e.g. chapters which are part of a book. As such, it is designed for that kind of case and comes with certain restrictions. It should not be used in the preamble, it cannot be nested and so on.

\input is intended to read in files in more generic cases. It cannot be used in the same way to support standalone compilation of document parts, but it is free of the restrictions on \include e.g. it can be nested.

Unlike \include, \input does not write any files to the directory of the included file. This means that you can \input a file which is not in the working directory or a sub-directory of the working directory without violating the default settings which generally prevent writes to directories above the working directory. Although these settings can be changed, this is not recommended as the setting is designed to mitigate potential security issues.

Hence, \input would be both more suitable and more straightforward in this case and will not result in the errors caused by the (mis)use of \include.




    Main file

  • By the way, \include should never be used before \begin{document}, where it makes no sense at all. – egreg Jan 24 '16 at 8:43
  • @egreg That's why I said it should not be used in the preamble...? – cfr Jan 24 '16 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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