12

For LaTeX, I once put a whole bunch of \newcommand definitions (which I frequently needed for writing up lecture notes etc.) into a .sty file. After placing that file into my texmf directory, I could easily include it into a LaTeX document whenever required.

I wonder what the equivalent modus operandi would be for a ConTeXt project? Well, I know that in ConTeXt there exists the concept of "environments", but they seem to be primarily intended for style setups (and not so much for macro definitions), and they seem to be restricted to single projects.

So I'd like to ask if in ConTeXt

  1. there is a better place for \define orgies than environments and
  2. there is a mechanism allowing for sharing such definitions between multiple projects
13

Environments

The place to put your macros and style setups in ConTeXt is an environment file. The usage is really simple. For example save the following as env-test.tex

\startenvironment *

  \setuplayout[grid=yes]

  \def\something{something else}

\stopenvironment

Then you put in your document file

\environment env-test

\starttext

\something

\stoptext

To learn more about document organization consult the Project Structure page in the Garden.

If you need a more explicit example, just take a look at the source of the Metafun manual.

Modules

If you seek to share macros and style setups among various documents, you might be looking for a module. You just save the module in the TeX search path, such as texmf, texmf-local or the working directory.

In practice, the main difference between modules and environments is that you can pass options to modules using \usemodule[...][key=value] but the only way to pass options to environments is using modes. (Thanks Aditya!)

Save the following as t-test.tex. Module files have the naming convention <prefix>-<name> where the prefix t stands for third party.

\startmodule[test]

  \setuplayout[grid=yes]

  \def\something{something else}

\stopmodule

Then you use this module by saying \usemodule.

\usemodule[test]

\starttext

\something

\stoptext

For more detailed info see the Modules page in the Garden.

5
  • In practice, the main difference between modules and environments is that you can pass options to modules using \usemodule[...][key=value] but the only way to pass options to environments is using modes.
    – Aditya
    May 2 '17 at 21:38
  • @Aditya That is very correct. I have integrated the sentence into my answer. I hope you don't mind. May 2 '17 at 21:41
  • Henri, Aditya, thanks for your replies, that did clear things up a lot! I already had set up my project according to the recommended structure (with local environments and the like), but your texmf/t-something.tex advice will make my day! (Sigh, it really is so difficult to find useful ConTeXt information on the Web when searching for "context"...) May 3 '17 at 5:50
  • @TorstenCrass Search for context mkiv instead. Also, the mailing list is the best source of advice and you can search it via Google using site:mailman.ntg.nl <terms>. May 3 '17 at 9:08
  • Searching for context mkiv is some excellent advice, thanks! May 4 '17 at 15:11

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.