Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm creating a set of mathematics worksheets, and I'd like to have an upside down "answer key" below a set of enumerated questions. Here is what I have at the moment:

\usepackage{graphicx}

Answers:

\rotatebox{180}{$1. \underline{5}$ $2.\underline{5}$
$3.\underline{10}$ $4.\underline{8}$}

This produces the following:

enter image description here

Given that all the answers are in the same format (problem number, then an underlined answer), is there a way to create a command that would produce the formatted text (I can add the \rotatebox myself) for a set of values?

I'm thinking something like this:

\createanswerbox[5,5,10,4]
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Taking some hints from Package xparse \SplitList last token, you can define a list processor that performs your request iteratively:

enter image description here

\documentclass{article}
\usepackage{graphicx,xparse}% http://ctan.org/pkg/{graphicx,xparse}
\newcounter{itemcntr}
\NewDocumentCommand\createanswerbox{O{,\,} >{\SplitList{,}}m}
{%
  \setcounter{itemcntr}{0}% Start at 1.
  \def\itemdelim{\def\itemdelim{#1}}% Define list separator with one delay
  \ProcessList{#2}{\myitem}% Process list
}
\newcommand\myitem[1]{\stepcounter{itemcntr}\itemdelim\theitemcntr.\underline{#1}}

\begin{document}
\createanswerbox{5,5,10,4}

\rotatebox{180}{\createanswerbox{5,5,10,4}}
\end{document}
share|improve this answer
    
Exactly what I was looking for! I added dollar signs before and after the underline to put the answers in math mode. Thanks! –  Chris Gregg May 22 '13 at 7:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.