I'm interested in trying to use the onlyitems code posted here with some way to exclude text inside the items.

The reason I would like to do this is that I am typesetting course notes and would like to be able to generate answers to selected exercises for students. I've read a couple of other posts about this - see these two about the answers and exercises packages (here and here) that were not helpful to me. The above code seems best, but I can't quite do exactly what I want with it. I need to keep the item (exercise) numbers the same. I have tried two solutions that don't work.

  1. I have two environments, statement and answer, which I would like to be able to switch between depending on the version I want to generate. I suspect that the use of \newcommand in the onlyitems code mentioned above precludes the use of \excludecomment inside the items. The code works for me without the use of \excludecomment but does not work with it, so I would appreciate any suggestions.

  2. I have also tried creating a \newif that could be turned on and off (see second code sample). This also does not work.

The following part of the preamble is from the onlyitems code above:

`% from https://tex.stackexchange.com/questions/4502/onlyitems-how-to-select-specific-items-from-an-item-list
% A huge list of pgfkeys to be set up.
/onlyitems/.is family, /onlyitems,
% Utility keys
utility/store tag/.store in = \itemOptions,
utility/store bool/.store in = \itemIf,
utility/process true/.style = {process/#1 = \iftrue},
utility/process false/.style = {process/#1 = \iffalse},%\fi
utility/set store bool/.style 2 args = {#1/.style = {utility/store bool = #2}},
utility/set select style/.style 2 args = {utility/set store bool = {select/#1}{#2}},
utility/verdict/.style = {},
utility/add to reset/.style = {
reset/.prefix style = {select/#1/.style = {select/.unknown}}
utility/current key/.estore in = \itemKey,
% Nothing in the process family is ever set, so any selection option is set to store a  boolean
process/.unknown/.style = {
utility/current key = \pgfkeyscurrentname,
select/\itemKey/.style = {
utility/set store bool = {utility/verdict}{#1}
utility/add to reset/.expand once = \itemKey
% For clearing the list of selected items (to support nested {itemize})
reset/.style = {},
reset/reset/.style = {reset/.style = {reset/reset, default}},
% Here are the options you can actually pass.  These go to the {itemize}...
include/.style = {utility/process true/.list  = {#1}},
exclude/.style = {utility/process false/.list = {#1}},
all/.style  = {utility/set select style = {.unknown}{\iftrue}},
none/.style = {utility/set select style = {.unknown}{\iffalse}},%\fi
default/.style = {all},
% ...and these to the \item's
tag/.style = {utility/store tag = {[#1]}},
id/.style = {select/#1},
% Like tikzset, it sets a default key path
\newcommand\onlyitemsset[1]{\pgfkeys{/onlyitems, #1}}

% Have to use a \newcount because (ugh) the LaTeX \setcounter is a global assignment
% The \egroup closes off any \vbox'es from the previously ignored \item.
% The conditional \bgroup cancels it out when there aren't any.
\advance\itemsSoFar by 1 %
\onlyitemsset{utility/store tag = {}, utility/verdict/.style = {},    select/\the\itemsSoFar, #1, utility/verdict}%
% The vbox is set and then discarded, effectively ignoring an entire \item.
% This inner \itemLaTeX is necessary to avoid a glitch when we ignore the first \item of an itemize that itself contains a nested \itemize.  Don't ask, I don't know.

% \let\itemizeLaTeX=\itemize
% \let\enditemizeLaTeX=\enditemize
% \renewcommand\itemize[1][]{%
%  \let\itemIf=\iftrue
%  \itemsSoFar = 0 %
%  % We have to reset here so that the selections from an outer itemize don't conflict with an inner one.
%  \onlyitemsset{reset, #1}%
%  \itemizeLaTeX
% }
% \renewcommand\enditemize{%
%  % This closes off the last \vbox
%  \itemIf\bgroup\fi\egroup\enditemizeLaTeX
% }

\itemsSoFar = 0 %
% We have to reset here so that the selections from an outer itemize don't conflict with an inner one.
\onlyitemsset{reset, #1}%
% This closes off the last \vbox

Here is what I am trying to do (requires above in preamble):

% Here is my part of the preamble



Determine whether...

The rectangle...




Here is the code for my second proposed solution. The earlier parts of the preamble are required, with the addition of:


\newcommand{\showanswer}[1]{\ifshowanswer #1}


\newcommand{\showstatement}[1]{\ifshowstatement #1 \fi}


\showstatement{Determine whether...}

\showstatement{The rectangle...}




closed as not a real question by Joseph Wright May 6 '12 at 7:52

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – egreg Mar 29 '12 at 22:52
  • While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. I attempted to cut and paste the above into something I could work with, but got errors, so would be helpful if you created a compilable example. – Peter Grill Apr 3 '12 at 23:55

Browse other questions tagged or ask your own question.