Text FormattingConditional Formatting using ifthen

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

Conditional Formatting using ifthen

Post by gibsonsdad »

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;

Code: Select all

\newcommand{\choice}{\textbf}
\newcommand{\distractor}{--??--}
\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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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

Conditional Formatting using ifthen

Post by gibsonsdad »

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

Code: Select all

\documentclass[12pt]{article}
    \usepackage{ifthen, color}
        \begin{document}
            %Create the boolean flag cs (Choice Selector)
            \newboolean{cs}
                %Set the value of cs
                \setboolean{cs}{false}
                %Create a new command to set the text color to red
                \newcommand{\setcstrue}{\textcolor{red}}
                %Create a new command to set the color as normal
                \newcommand{\setcsfalse}{}
                %Create the command to surround the correct selection
                \newcommand{\cs}{\ifthenelse{\boolean{cs}}{\setcstrue}             
                           {\setcsfalse}}
                    %Use the command 
                    \cs{Red}
        \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.
Post Reply