Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle inclusion of text in LaTeX [closed]

I am trying to make a thorough header in LaTeX that will save time later when I write quizzes and tests. I'd like to include solutions to each question in the .tex file, with some flag that toggles whether they appear when compiled.

So in a document like this...

\begin{document}

Some question
\solution{ the answer to the question}

\end{document}

..the solution would be invisible unless I include a "\showsolutions" flag.

Is there a command I can create that will do this?

like image 872
user1634145 Avatar asked Sep 01 '25 22:09

user1634145


1 Answers

Use \newif to create a new if-type construct, and set the default value.

\newif\ifshowsolutions
\showsolutionsfalse

Then use it in your \solution command

\newcommand{solution}[1]{\ifshowsolutions #1 \fi}

To turn on solutions, use

\showsolutionstrue
like image 122
Ken Bloom Avatar answered Sep 03 '25 16:09

Ken Bloom