3

Now that Frodo has left to fight Sauron, Bilbo is all alone at home and searching for new things to do. So it came to his mind that he could apply for a job. For his application, he uses the moderncv documentclass and therein the \cventry command for the educational stages of his life with a typical entry being \cventry[spacing]{years}{degree/job title}{institution/employer}{localization}{optionnal: grade/...}{optional: comment/job description}.

Since he's applying for several jobs and is a person working effectively, he is reusing some parts of his CV for the different applications. However, he wants to have some pieces of information in the CV to show up only for certain conditions. Since he plans to apply for jobs in The Shire as well as in other parts of Middle Earth, one of the conditions is that for jobs outside of The Shire, he wants to have "The Shire" added to names of places. He does not want to add that for applications within The Shire, since he expects that people are familiar with the localities.

Unfortunately, concerning the "institution" and "localization" field in the \cventy there are two different cases which can be seen in the MWE below: In some cases the institution's name does already contain the location name, e.g. "Bag's End Hobbit School", while others don't contain such a localized name. In the former case, the "localization" field should only contain the country and only, if the applications is for an employer outside The Shire. In the latter case, the "localization" should contain the city name for applications within The Shire and "City, The Shire" for applications in the rest of Middle Earth.

To achieve this, Bilbo has defined a boolean variable international which should be tested to decide which localization should be used. This does work fine in other entry types (see the \cvitem entry by the end of the MWE), but not in the \cventry command, where putting an \ifthenelse statement into one of the arguments results in "! Argument of \boolean has an extra }." errors.

To me, the crux seems to be in the way the \cventry command is parsed (the respective original code is in the \makeatletter ... \makeatother section). However, I have no idea what to change to get it working or how to work around it.

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}

\makeatletter
\renewcommand*{\cventry}[7][.25em]{%
  \cvitem[#1]{#2}{%
    {\bfseries#3}%
    \ifthenelse{\equal{#4}{}}{}{, {\slshape#4}}%
    \ifthenelse{\equal{#5}{}}{}{, #5}%
    \ifthenelse{\equal{#6}{}}{}{, #6}%
    .\strut%
    \ifx&#7&%
    \else{\newline{}\begin{minipage}[t]{\linewidth}\small#7\end{minipage}}\fi}}
\makeatother

\newboolean{international}
\setboolean{international}{true}

% personal data
\name{Bilbo}{Baggins}
\address{A house in}{Bag's End}{The Shire}

\begin{document}
\makecvtitle
\section{Education}
\cventry{2130--2135}{Hobbit}{Bag's End Hobbit School}{The Shire}{}{}
\cventry{2130--2135}{Hobbit}{Bag's End Hobbit School}{\ifthenelse{\boolean{international}}{}{The Shire}}{}{}
\cventry{2126--2130}{Small Hobbit}{"The smallest Ones" Primary School}{Bag's End\ifthenelse{\boolean{international}}{}{, The Shire}}{}{}

\section{Master thesis}
\cvitem{title}{\emph{There and back again}}
\cvitem{supervisor}{Gandalf the Grey}
\cvitem{description}{How I fought the Dragon\ifthenelse{\boolean{international}}{}{ and found a ring}.}
%Not everyone has to know that I have this ring...
\end{document}
  • As far as I know Bilbo wasn't left at home ;-) – user31729 Oct 6 '15 at 10:16
  • If you're open to etoolbox and its \ifblank{} command -- give it a try – user31729 Oct 6 '15 at 10:24
  • @ChristianHupfer Damn, you're right about Bilbo... How could I forget. – Benedikt Bauer Oct 6 '15 at 10:48
2

I wouldn't redefine the \cventry but do the following:

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}
\usepackage{etoolbox}

\newbool{international}
%\setbool{international}{true}
\setbool{international}{false}

\newcommand*{\mytoggle}[2]{\ifbool{international}{#1}{#2}}

% personal data
\name{Bilbo}{Baggins}
\address{A house in}{Bag's End}{The Shire}

\begin{document}
\makecvtitle
\section{Education}
\cventry{2130--2135}{Hobbit}{Bag's End Hobbit School}{The Shire}{}{}
\cventry{2130--2135}{Hobbit}{Bag's End Hobbit School}{\mytoggle{}{The Shire}}{}{}
\cventry{2126--2130}{Small Hobbit}{"The smallest Ones" Primary School}{Bag's End\mytoggle{}{, The Shire}}{}{}

\section{Master thesis}
\cvitem{title}{\emph{There and back again}}
\cvitem{supervisor}{Gandalf the Grey}
\cvitem{description}{How I fought the Dragon\mytoggle{}{ and found a ring}.}
%Not everyone has to know that I have this ring...
\end{document}
  • We had similar ideas ;-) (+1) – user31729 Oct 6 '15 at 10:50
  • @ChristianHupfer: Basically I don't like \ifthenelse. :) And nesting a conditional inside another and then another... sigh. BTW, scores leveled :) – user11232 Oct 6 '15 at 10:57
  • Would \newtoggle do as well? That's what I had in my mind, but I've not tried yet – user31729 Oct 6 '15 at 10:58
  • @ChristianHupfer: Certainly. Then \newcommand*{\mytoggle} wouldn't be necessary :) – user11232 Oct 6 '15 at 11:00
  • Go ahead ...;-) – user31729 Oct 6 '15 at 11:00
2

I think etoolbox boolean features are safer somewhat -- this is mixed approach. I'll update after feedback

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}

\usepackage{etoolbox}

\newbool{international}
\setbool{international}{false}

\makeatletter
\renewcommand*{\cventry}[7][.25em]{%
  \cvitem[#1]{#2}{%
    {\bfseries#3}%
    \ifblank{#4}{Nope}{, {\slshape#4}}%
    \ifblank{#5}{}{, #5}%
    \ifblank{#6}{}{, #6}%
    .\strut%
    \ifx&#7&%
    \else{\newline{}\begin{minipage}[t]{\linewidth}\small#7\end{minipage}}\fi}}%
\makeatother

%\newboolean{international}
%\setboolean{international}{true}

% personal data
\name{Bilbo}{Baggins}
\address{A house in}{Bag's End}{The Shire}

\begin{document}
\makecvtitle
\section{Education}
\cventry{2130--2135}{Hobbit}{Bag's End Hobbit School}{The Shire}{}{}
\cventry{2130--2135}{Hobbit}{Bag's End Hobbit School}{{\ifbool{international}{}{The Shire}}}{}{}
\cventry{2126--2130}{Small Hobbit}{"The smallest Ones" Primary School}{Bag's End\ifbool{international}{}{, The Shire}}{}{}

\section{Master thesis}
\cvitem{title}{\emph{There and back again}}
\cvitem{supervisor}{Gandalf the Grey}
\cvitem{description}{How I fought the Dragon\ifbool{international}{}{ and found a ring}.}
%Not everyone has to know that I have this ring...
\end{document}

enter image description here

  • The errors are gone. However, the second cventry now produces a comma and a white space, so the fifth argument isn't completely suppressed. – Benedikt Bauer Oct 6 '15 at 10:47
  • @BenediktBauer: I updated. I noticed and changed the boolean variable (as I already indicated in my answer leadin to the bool type from etoolbox. It's more robust, in my point of view. – user31729 Oct 6 '15 at 10:47
  • Unfortunately also your updated version still produces ", " instead of being left out completely if I set international to true. Harish Kumar's version is working as expected. – Benedikt Bauer Oct 6 '15 at 11:08
  • @BenediktBauer: Yes, that , was already in your original \ifthenelse{...} code. Harish did not redefine \cventry and so there're no leftover's of unwanted code ;-) – user31729 Oct 6 '15 at 11:13
  • Well, then it's my bad. Sorry for that! – Benedikt Bauer Oct 6 '15 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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