Skip to content

Instantly share code, notes, and snippets.

@literalplus
Last active April 17, 2018 13:20
Show Gist options
  • Save literalplus/c45ff5914eb171dad47e4a040e1d4bce to your computer and use it in GitHub Desktop.
Save literalplus/c45ff5914eb171dad47e4a040e1d4bce to your computer and use it in GitHub Desktop.
Multiple Choice in LaTeX

LaTeX Multiple Choice

Here's a thing I made to make creating multiple choice quizzes and answers easier in LaTeX.

\usepackage{amssymb}
\usepackage{pifont}
\usepackage{ifthen}
\newcommand{\lmss}{\fontfamily{lmss}\selectfont} % Latin Modern Sans
% checkboxes - https://tex.stackexchange.com/a/313337
\newcommand{\xmark}{\ding{55}}%
\newcommand{\mcbox}{$\square$}
\newcommand{\mccheck}{\rlap{$\square$}{\raisebox{2pt}{\large\hspace{1pt}\checkmark}}}
\newcommand{\mccross}{\rlap{$\square$}{\large\hspace{1pt}\xmark}}
% multiple choice
\newcommand{\mctrue}{richtig}
\newcommand{\mcfalse}{falsch}
\newcounter{mcquest}
\newcommand{\mcstart}{\hline \setcounter{mcquest}{0}}
\newcommand{\mccontinue}{\hline}
\newcommand{\mcquest}[1]{%
\fontsize{10}{12}\normalfont\bfseries\lmss \stepcounter{mcquest}%
(\arabic{mcquest}) #1\normalfont%
}
\newcommand{\mcans}[2]{%
\if\relax#1\relax % is empty; https://tex.stackexchange.com/a/53091
\mcbox
\else
\mccross
\fi
{\raisebox{1pt}{\hspace{3pt}#2}}%
}
\newcommand{\mcexplain}[1]{\normalfont\newline #1 \vspace{2pt}}
\newcommand{\mctf}[1]{%
\ifthenelse{\equal{#1}{t}}%
{%then (t)
\mcans{x}{\mctrue} & \mcans{}{\mcfalse}
}{%else (!t)
\ifthenelse{\equal{#1}{f}}%
{%then (f)
\mcans{}{\mctrue} & \mcans{x}{\mcfalse}
}{%else (!f)
\mcans{}{\mctrue} & \mcans{}{\mcfalse}
}
} \\ \hline
}
\emph{Welche Aussagen treffen zu? Begründen Sie Ihre Antwort.}
\begin{tabu}{p{\linewidth-4cm} | l l}
\mcstart
\mcquest{Ein Objekt von E kann direkt auf die Variable x zugreifen.} & \mctf{t}
\mcquest{Another thing} \mcexplain{Here's your explanation} & \mctf{f}
\mcquest{wow this one is a mystery} & \mctf{}
\end{tabu}
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>

The parts that are taken from StackExchange are licensed under https://creativecommons.org/licenses/by-sa/3.0/. These are marked by comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment