10

I think this is clearest in an example. Here's my document:

\begin{enumerate}
\item{1} The heart
    \begin{enumerate]
    \item{1} It pumps blood through the body.
    \item{2} It has four chambers.
    \item{2} The inferior and superior vena cava bring blood from the body.
    \end{enumerate}
\end{enumerate}

The idea is that I could set typeset-level=1 and get a document that just says:

  1. The heart

    a. It pumps blood through the body.

Or I could set typeset-level={1-2} and it typesets the whole thing. I don't want to be restricted to typesetting certain "depths" of the outline, I want to be able to specify, for each entry, a "complexity level".

The goal is to make documents for my students such that a student with no background can read the level 1 doc, then the level 2 doc, etc. and the student with good background can just skip to the level 3 doc. And I think the level 1 doc should always be a subset of the level 2 doc (and 2 a subset of 3, etc.).

Thanks for any suggestions you can offer!

rcorty
  • 275
  • 2
  • 7

2 Answers2

7

As I said in the comment above, in ConTeXt you can use modes for such conditional processing. I also like to use semantic markup, so if I were creating such a document, I'd do the following:

  1. Create dummy environments notes and details that, by default, simply gobble their content. In ConTeXt, such environments are created using definebuffer[...].

  2. If the modes notes or details are set, redefine the notes environment so that it simply typesets its content. In ConTeXt, such an environment is created using \definestartstop[...].

  3. If the modes details is both set, redefine details environment so that it simply typesets its content.

Combining this logic, we get the following:

\definebuffer[notes]
\definebuffer[details]

\startmodeset
    [notes,details]  {\definestartstop[notes] }
    [details]        {\definestartstop[details]}
\stopmodeset

Now, lets take a test document.

\starttext

\startitemize[n]
  \item The heart
    \startnotes
      \startitemize[a]
        \item It pumps blood through the body
          \startdetails
            \item It has four chambers
            \item The inferior and superior vena cava bring blood from the body.
          \stopdetails
      \stopitemize
    \stopnotes
\stopitemize
\stoptext

When we compile this document using context filename, we get

enter image description here

When we compile this document using context --mode=notes filename, we get

enter image description here

When we compile this document using context --mode=details filename, we get

enter image description here

If you are compiling the document from an editor rather than command line, you can add

\enablemode[notes]

on the top of the file rather than passing it as a command line argument.

Aditya
  • 62,301
5

While I don't doubt that ConTeXt's modes are much more robust and interesting than this answer, for simple(r) applications, you could do something like this.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}

\newif\ifTLone
\newif\ifTLtwo
\newif\ifTLthree

% \TLonetrue
\TLtwotrue
% \TLthreetrue

% note: \def is used here for brevity; it is a bad choice if your text
% is \long-er than a paragraph
% see here http://tex.stackexchange.com/q/39450/8528 for more information

\ifTLone
  \def\tli   #1{#1}
  \def\tlii  #1{}
  \def\tliii #1{}
\fi

\ifTLtwo
  \def\tli   #1{#1}
  \def\tlii  #1{#1}
  \def\tliii #1{}
\fi

\ifTLthree
  \def\tli   #1{#1}
  \def\tlii  #1{#1}
  \def\tliii #1{#1}
\fi

\begin{document}

This is outside all levels. Hopefully most of your text fits in this
category.

\tli  {This is level one.}  \par
\tlii {This is level two.}  \par
\tliii{This is level three.}\par

\begin{itemize}
\tliii{\item TL 3: $a + b = x^2$}

\item regular%
\tliii{\footnote{A super-secret footnote for those already in the know.}}

\tlii{\item TL 2.}

\item regular
\end{itemize}

\end{document}

There are obvious limitations like jamming some verbatim text in these macros, but if you don't need to do anything nearly so fancy this might get the job done.

You could also move the \newif and \ifTL<level> declarations out of the file and call them from the command line instead, and combine with the -jobname=<filename> to create the different 'levels' of output files: assuming an original input file called myfile.tex, use:

pdflatex -jobname=TLtwo "\newif\ifTLone\newif\ifTLtwo\newif\ifTLthree\TLtwotrue\input{filename.tex}"

This should produce TLtwo.pdf with up to level 2 realized in the output.

jon
  • 22,325
  • Would you now of a cleaner (more robust) non context way to do this? I would love to have the capability to use it for figures, text, and math sections alike, but I would also like to use simple pdflatex. I asked a question on this here: https://tex.stackexchange.com/questions/411293/different-complexity-levels-of-the-same-document-cleanly – Thorbjørn E. K. Christensen Jan 21 '18 at 17:53