7

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 can't 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 I'm in #1 do this command, if I'm in #2 then do the other command. However I can't figure out how to implement this exactly. Any suggestions?

4
  • Why can't you use \frontcard in both arguments of \card? Jun 18, 2011 at 13:53
  • Welcome to TeX.sx. Note that you can mark inline code by using backticks (`), as I've done in your post. Jun 18, 2011 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? Jun 18, 2011 at 13:57
  • @Gonzalo. because the front is blacked out and the back gives the answer.
    – georg
    Jun 18, 2011 at 15:57

1 Answer 1

9

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

2
  • 1
    Yes, this works perfectly! Ill upvote when I have enough rep
    – georg
    Jun 18, 2011 at 16:08
  • @michael: OK. Please note, that I added some explanations to my code …
    – Tobi
    Jun 18, 2011 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .