I was wondering if it was possible to define a group of modes, such as only one can be used. A MWE is :

\environment myEnvironment
  This is mode A
  This is mode B

which displays "This is mode A" when run with context --mode=modeA file.tex and "This is mode B" when run with context --mode=modeB file.tex

The bonus question is : is there a way to automatically (I mean without manually typing --result=newName) generate different output files (like file_modeA.pdf in the first case and file_modeB.pdf in the second).

  • For the first part see Modes in the Garden. For the second part; no but that is a limitation of TeX. The \jobname is fixed on startup but you can set the jobname from the command line and use a macro to parse for the corresponding mode and enable it. – Henri Menke Sep 22 '16 at 23:05
  • 1
    If modeA and modeB are never set together, you can just use a single mode and test with \startmode and \startnotmode. – Aditya Sep 22 '16 at 23:23
  • Or, if you want mutually exclusive modes, what is the desired output when I run context --mode=modeA,modeB file.tex? – Aditya Sep 22 '16 at 23:25
  • It is not logical in my context to run it ; the example I was trying to implement was generating a lesson handout in two versions : one for students and one for the teacher. – A. Licari Sep 24 '16 at 7:41

If you don't want to specifiy the mode alongside the result, just use the result name as the mode. For example you can call the example below using

context --result=students test.tex


context --result=teachers test.tex

to enable the eponymous mode. Because enabling the mode takes place at the Lua end you can of course construct much more sophisticated mode-checking constructs.

You can then check for the mode using all the available mode checking commands listed in the Garden. Below I used \doifmode and \doifnotmode but the solution is not restricted to these.

context.enablemode{environment.arguments.result or ""}


\doifmode{students}{for student's eyes}
\doifnotmode{students}{for teacher's eyes}

\doifmode{teachers}{for teacher's eyes}
\doifnotmode{teachers}{for student's eyes}

| improve this answer | |
  • This seems great. I'll try it as soon as I can. – A. Licari Sep 27 '16 at 6:12
  • @A.Licari Did it work? – Henri Menke Oct 1 '16 at 14:22
  • Sorry, I didn't try yet, I had an awful lot of tests to grade -_- – A. Licari Oct 2 '16 at 18:56

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.