LaTeX forum ⇒ Text FormattingConditional Formatting using ifthen Topic is solved

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
gibsonsdad
Posts: 4
Joined: Sat Oct 06, 2012 5:05 am

Conditional Formatting using ifthen

Postby gibsonsdad » Thu Dec 26, 2013 5:35 pm

I am attempting to create a master document for creating multiple choice mathematics assessments. I want to be able to create two versions, the student version, and the teacher version. The student version should format all choices the same. The teacher version should indicate the correct answer choice by bold-facing the correct choice. I have seen this done, but it has been many years. I have attempted the following;

  1. \newcommand{\choice}{\textbf}
  2. \newcommand{\distractor}{--??--}
  3. \newcommand{\selector}{\ifthenelse{\equal{--??--}{T}}{\choice}{\distractor}}


Where I have inserted --??--, I cannot determine what to put. I want this to change by commenting out some signal line to produce one of the versions, while not commenting out the signal line produces the other.

I would be appreciative of any assistance.
Last edited by cgnieder on Fri Dec 27, 2013 1:26 pm, edited 1 time in total.
Reason: added code markup

Tags:

gibsonsdad
Posts: 4
Joined: Sat Oct 06, 2012 5:05 am

Postby gibsonsdad » Fri Dec 27, 2013 2:44 am

I solved it. It is really quite simple. I used the following code;

  1. \documentclass[12pt]{article}
  2. \usepackage{ifthen, color}
  3. \begin{document}
  4. %Create the boolean flag cs (Choice Selector)
  5. \newboolean{cs}
  6. %Set the value of cs
  7. \setboolean{cs}{false}
  8. %Create a new command to set the text color to red
  9. \newcommand{\setcstrue}{\textcolor{red}}
  10. %Create a new command to set the color as normal
  11. \newcommand{\setcsfalse}{}
  12. %Create the command to surround the correct selection
  13. \newcommand{\cs}{\ifthenelse{\boolean{cs}}{\setcstrue}
  14. {\setcsfalse}}
  15. %Use the command
  16. \cs{Red}
  17. \end{document}


to set the correct choice to red if the boolean is set to true, and to print normally if the boolean is set to false.
Last edited by cgnieder on Fri Dec 27, 2013 1:27 pm, edited 1 time in total.
Reason: added code markup


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 4 guests