0

Is it possible to make 2 (or more) PDF with the same source in Context ?

For example, I want to write a booklet with some algorithmics exercise, and a booklet with the solution wrote in Python (and after Java, C#…)

e.g.

\section{First Exercise} %common title to all booklets
\startQuestion %only for "exercise" booklet
  Write a program to get the software version you are using
\stopQuestion
\startPython %only for Python booklet
  print (sys.version)
\stopPython
\startJava %only for Java booklet
…
\stopJava
\stoptext

I've tried to use modes, but it did'nt work :( The Context Garden wiki is not very clear about that.

Thanks to help me :)

3
  • I wrote the wiki article on modes. I will really appreciate if you could help in making it more clear. As an experienced user, it is sometimes hard to imagine what new users find difficult.
    – Aditya
    Jun 17, 2019 at 16:07
  • In fact, I'm lost with \startnotmode, \startmode… And it seems not working if we put modes in new command definition
    – Ray Lemon
    Jun 17, 2019 at 17:31
  • @RayLemon You should the read modes manual. Jun 17, 2019 at 17:38

3 Answers 3

1

I don't know how to do to compile one tex file once and from it get several pdf files. The following works if you are OK with compiling once for each setup:

\starttext
\section{First Exercise}
\startmode[Question,all]
Write a program to get the software version you are using.
\stopmode

\startmode[Python,all]
print (sys.version)
\stopmode

\startmode[Java,all]
...
\stopmode
\stoptext

Try to compile this the following different options:

  • without any option (you should only get the section title).
  • --mode=all (you should get everything)
  • --mode=Python (you should get the section title and the Python part)

Of course, you could write a small script to compile several times with different modes enabled.

3
  • It's so simple like that… Sorry for this dumb question :D
    – Ray Lemon
    Jun 17, 2019 at 14:49
  • 1
    Another option is to leave out the all mode, and run --mode=Python,Java which will enable both modes
    – Aditya
    Jun 17, 2019 at 16:06
  • @Aditya Indeed. I asked about modes some time ago, and I have since then found it convenient to have a mode that includes everything. But your point with the comma separated list is good.
    – mickep
    Jun 17, 2019 at 16:41
1

You can also use doifmode

\def\Answers#1#2#3{
    \doifmode{python}{#1} 
    \doifmode{java}{#2}
    \doifmode{csharp}{#3} 
    }

\enablemode[java]
\Answers
{Python code}
{Java code}
{C# code}

I sometimes use doifnotmode, which can be very useful too. For example here

\def\Answers#1#2#3#4{
    \doifmode{python}{#1} 
    \doifmode{java}{#2}
    \doifmode{csharp}{#3} 
    \doifnotmode{python, java, csharp}{\thinrules[color=darkgray, interlinespace=big, n=#4]}
    }

\enablemode[test]
\Answers
{Python code}
{Java code}
{C# code}
{5} % displays 4 lines after the problem
0

I tested your example. It works, but, when I define my own commands like this

\definestartstop[question][before={\startmode[question]}, after={\stopmode}]
\definetyping[python][before={\startmode[python]}, after={\stopmode}]

When I compile the document above, they print whole text, with any mode selected before ! (--mode=python, --mode=question) !

Maybe I've made a mistake anywhere ?

4
  • You can't invoke a mode environment with before and after keys because when you disable a mode the \startmode command tries to read everything untill the \stopmode command which doesn't work in this case. Jun 17, 2019 at 17:32
  • I think I consider ConTeXt like a programming language :D I'm used to write subroutines.
    – Ray Lemon
    Jun 17, 2019 at 18:10
  • It is better to define \definebuffer[question] and then \startmode[question] \definestartstop[question] \stopmode[question] , etc.
    – Aditya
    Jun 19, 2019 at 8:42
  • Could you show me a little example with these commands, please ?
    – Ray Lemon
    Jun 19, 2019 at 12:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .