Difference between revisions of "Modes"

From Wiki
Jump to navigation Jump to search
(doifmode and doifmodeelse [] to {})
Line 73: Line 73:
  
 
<texcode>
 
<texcode>
\doifmode{*\v!first}{%
+
\doifmode{*first}{%
 
   % external program which creates a file figure1.ps
 
   % external program which creates a file figure1.ps
 
   \executesystemcommand{some_external_program ...}
 
   \executesystemcommand{some_external_program ...}

Revision as of 03:41, 11 September 2006

< The ConTeXt Way | Inside ConTeXt | Project structure >

Often you'd like to publish different versions of a document, say a presentation and a handout or a student's and a teacher's version.

ConTeXt supports such filtering with its modes:

ConTeXt is a great TeX macro package.
\startmode[handout] % The following text will only appear in the handout
It’s based on Plain TeX like the better known LaTeX.
\stopmode
\startnotmode[print]
Here's a link to my homepage: \url[...]
\stopnotmode
\doifmode{answers}{The answer to the homework is 42.}
\doifmodeelse{draft}{Draft Version}{Final Version}

...mode and ...notmode let you filter your content sufficient in most cases. You can also give several modes like \startmode[handout,print].

Modes are also a convenient way to comment out sections (typical: "obsolete" mode).

You can typeset the different modes like:

texexec myfile --mode=handout --result=handout.pdf

You don't need the --result, but otherwise you'd get the same filename for both modes.

Modes are extremely powerful when applied to text. However, they can be applied to configuration problems as well. A user wanted to generate different versions of the same file with different fonts:

\startmode[palatino]
   \usetypescript[adobekb][8r]
   \usetypescript[palatino][8r]
   \setupbodyfont[palatino,12pt]
\stopmode

\startmode[times]
   \usetypescript[adobekb][8r]
   \usetypescript[postscript][8r]
   \setupbodyfont[postscript,12pt]
\stopmode

\starttext
\input knuth
\showfontstrip
\stoptext

And run with one of the following:

 texexec --pdf --mode=palatino filename
 texexec --pdf --mode=times    filename

If you want to enable some mode(s) without changing the command line (e.g. because you use some TeX GUI), you can use \enablemode[mymode] in your source. Put this before you load your environment! You can even enable several modes at once like [a4,print].

First-run-mode: Doing things only once

When you need to call external programs to process some of your data and return you some results, you probaly want to do that only once (instead of three times, if ConTeXt needs three runs). Here's how you can do it:

\doifmode{*first}{%
   % external program which creates a file figure1.ps
   \executesystemcommand{some_external_program ...}
   % convert PS into PDF
   \executesystemcommand{texmfstart pstopdf figure1.ps}
}

% include the resulting PDF
\externalfigure[figure1]