4

I saw in another question about how to create a condition, of which the best practice recommended was \iftoggle. I want to create a macro that will allow the creation of a teacher's note, a section with a definable look and feel which will conditionally compile away if I define that this is not the teacher's edition.

The error, it turns out, was that I didn't realize I had to usepackage in order to use the etoolbox. Here is the (now working) code. How can I define a border and a shading to embed in the teacher macro, and is there a better way of doing this?

\documentclass[11pt]{book}              % Book class in 11 points
\parindent0pt  \parskip10pt             % make block paragraphs
\raggedright                            % do not right justify
\usepackage{etoolbox}

\title{\bf Document Title}    % Supply information
\author{Author}              %   for the title page.
\date{\today}                           %   Use current date. 

\newtoggle{teacherFlag}
\toggletrue{teacherFlag}

\newcommand{\teacher}[1] {
\iftoggle{teacherFlag}{
    {#1}
}{
}

}


% Note that book class by default is formatted to be printed back-to-back.
\begin{document}                        % End of preamble, start of text.
\frontmatter                            % only in book class (roman page #s)
\maketitle                              % Print title page.
\tableofcontents                        % Print table of contents
\mainmatter                             % only in book class (arabic page #s)
\part{A Part Heading}                   % Print a "part" heading
\chapter{A Main Heading}                % Print a "chapter" heading
Most of this example applies to \texttt{article} and \texttt{book} classes
as well as to \texttt{report} class. In \texttt{article} class, however,
the default position for the title information is at the top of
the first text page rather than on a separate page. Also, it is
not usual to request a table of contents with \texttt{article} class.

\section{A Subheading}                  % Print a "section" heading
The following sectioning commands are available:
\begin{quote}                           % The following text will be
 part \\                                %    set off and indented.
 chapter \\                             % \\ forces a new line
 section \\ 
 subsection \\ 
 subsubsection \\ 
 paragraph \\ 
 subparagraph 
\end{quote}                             % End of indented text
\teacher{foo}
But note that---unlike the \texttt{book} and \texttt{report} classes---the
\texttt{article} class does not have a ``chapter" command.

\end{document}
2
  • When you ask a question and answers are provided, don't change the question completely to ask something different. I can't tell you what to do, I'm just giving my opinion.
    – Werner
    Sep 11, 2013 at 19:22
  • Sorry, I was editing the question while you were answering it
    – Dov
    Sep 11, 2013 at 19:23

2 Answers 2

6

I propose you another approach using the comment package:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{comment}
\usepackage{lipsum}

\specialcomment{teacher}{\begin{tcolorbox}}{\end{tcolorbox}}

%\excludecomment{teacher}

\begin{document}

\section{Test section}
\lipsum[4]

\begin{teacher}
\lipsum[2]
\end{teacher}

\section{Another test section}
\lipsum[4]

\begin{teacher}
\lipsum[2]
\end{teacher}

\end{document}

This produces the complete version:

enter image description here

Simply un-commenting out the line \excludecomment{teacher}, gives you the student version:

enter image description here

I used tcolorbox to produce a nice frame with a shaded background around the teacher section.

1
  • Thanks, this is a great solution, but see my followup next question (which references this one). Is there any way to override this state when running LaTeX? I would like to have a makefile that generates all versions of the document.
    – Dov
    Sep 11, 2013 at 19:21
3

Please always post a complete small document and/or show the full error message, however you don't really need a boolean toggle for this. You simply want a command that eats its argument or uses it so just have

\newcommand\teacher[1]{#1}
%\newcommand\teacher[1]{}

then \teacher{stuff} is the same as stuff and when you want the other version just move the % up to comment out the first version, so then \teacher{stuff} will do nothing.

You must log in to answer this question.

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