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 use a package to make flashcards which has the formatting \card{#1}{#2}, where #1 and #2 represent the front and back side. The package works great.

I like to block out text, so I have made newcommands \frontcard, which blocks out the text using highlighting or underlining and makes the text white, and \backcard, which is essentially a dummy command that replaces frontcard. For example, I would have to write \card{The chancellor of Germany is \frontcard{Angela Merkel}}{The chancellor of Germany is \backcard{Angela Merkel}}.

\documentclass[frontgrid]{flacards}
\usepackage{color}

\newcommand{\frontcard}[1]{\textcolor{yellow}{\colorbox{yellow}{$#1$}}}
\newcommand{\backcard}[1]{#1} 

\begin{document}

\pagesetup{2}{4} 


\card{The chancellor of \frontcard{Germany} is \frontcard{Angela Merkel}. }{The chancellor of \backcard{Germany} is \backcard{Angela Merkel}. }

\end{document} 

What I would like to reduce 2 newcommands to one command, as writing two commands is a little redundant.

I cant think of an easy way to do this though, because of the arbitrary number of blank fields (2 or more). So something like:

\newcard{The chancellor of \blank{Germany} is \blank{Angela Merkel}}

I was thinking how i could accomplish this; maybe with the ifthen package or etoolbox package? So, if im in #1 do this command, if im in #2 then do the other command. However I can't figure out how to implement this exactly. Any suggestions?

Thanks in advance!

share|improve this question
    
Why can't you use \frontcard in both arguments of \card? –  Gonzalo Medina Jun 18 '11 at 13:53
    
Welcome to TeX.sx. Note that you can mark inline code by using backticks (`), as I've done in your post. –  Torbjørn T. Jun 18 '11 at 13:54
1  
Can you please add to your question a minimal, complete, and compilable example showing your settings and the involved commands in action? –  Gonzalo Medina Jun 18 '11 at 13:57
    
@Gonzalo. because the front is blacked out and the back gives the answer. –  georg Jun 18 '11 at 15:57
add comment

1 Answer 1

up vote 6 down vote accepted

Like this:

\documentclass[frontgrid]{flacards}
\usepackage{color}

\newcommand{\frontcard}[1]{\textcolor{yellow}{\colorbox{yellow}{$#1$}}}
\newcommand{\backcard}[1]{#1} 

% new:
\newcommand{\Card}[1]{% create new command for cards with blanks
    \card{% call the original \card command with twice the same argument (#1)
        \let\blank\frontcard% but let \blank behave like \frontcard the first time
        #1
    }{%
        \let\blank\backcard% and like \backcard the second time
        #1
    }%
}

\begin{document}

\pagesetup{2}{4} 


\card{The chancellor of \frontcard{Germany} is \frontcard{Angela Merkel}. }{The chancellor of \backcard{Germany} is \backcard{Angela Merkel}. }

\Card{The ``Altkanzler'' of \blank{Germany} is \blank{Helmut Kohl}. }

\end{document}

Note that I used \frontcard and \backcard in my definition of \Card


There are also ways to get this with an \if construct or even the ifthen package but thats an overkill I think. The above is the easiest solution I could imagin, exept that one can put the definition of \frontcard and \backcard in the definition of \Card

share|improve this answer
1  
Yes, this works perfectly! Ill upvote when I have enough rep –  georg Jun 18 '11 at 16:08
    
@michael: OK. Please note, that I added some explanations to my code … –  Tobi Jun 18 '11 at 16:10
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.