3

I had a .tex file where I defined an expression earlier with the \usepackage{ifthen}. Now I want to use \usepackage{etoolbox} for this purpose but don't know how to use it correctly I get an error Undefined control sequence.} after compile.

\usepackage{etoolbox}
\newbool{CV}
\setbool{CV}{true}    % <===========================================
\newbool{Letter}
\setbool{Letter}{false} %
\ifbool{CV}{% print CV}
\ifbool{Letter}{% print Cover Letter}

where is my mistake with the Undefined control sequence I can't find the error. How is the correct use of ifbool, do I need break from other brace if one expression is true? any help would be appreciated

1
  • Please see my added answer ... Next time please give a complete MWE not only code snippet ...
    – Mensch
    Commented Aug 23, 2021 at 13:07

2 Answers 2

2

Based on your given MWE in your old Question change your cv like this (see important code changings marked with <======):

\documentclass[11pt,a4paper,sans]{moderncv}
  
\moderncvstyle{classic}                             
\moderncvcolor{green}
                            
\usepackage[scale=0.75]{geometry}
\usepackage[ngerman]{babel}
%\usepackage[latin1]{inputenc} % <======================================
\usepackage[T1]{fontenc}
\usepackage{multicol}

\usepackage{xpatch}
\xpatchcmd{\cventry}{.\strut}{\strut}{}{}
\xpatchcmd{\cvitem}{\raggedleft\hintstyle{#2}}{\raggedright\hintstyle{#2}}{}{}
\xpatchcmd*{\cvitemwithcomment}{\bfseries}{\mdseries}{}{}
\makeatletter
\xpatchcmd{\makeletterclosing}{\bfseries \@firstname~\@lastname}
                              {\includegraphics[width=4cm, height=1cm]{unterschrift.jpg}
                              \vspace{-10pt}\par
                               \bfseries \@firstname~\@lastname}
                              {}{}
\makeatother

% personal data
\name{John}{Doe}
\title{Lebenslauf}                               % optional, remove / comment the line if not wanted
\address{asdfdsf 12}{77777 scity}{Germany}
\phone[mobile]{+49~(xxx)~xxx~xxx}                   %
\phone[fixed]{+49~(xxx)~xxx~xxx}
\email{XXXXX}                               
\photo[64pt][0.4pt]{picture}                       
\renewcommand*{\bibliographyitemlabel}{[\arabic{enumiv}]}

% commands with ifthen <================================================
%\usepackage{ifthen}
%\newboolean{CV}
%\setboolean{CV}{true}
%\newboolean{Letter}
%\setboolean{Letter}{false} 

% commands with etoolbox (alreeady loaded in class moderncv) <==========
%\usepackage{etoolbox}
\newbool{CV}
\setbool{CV}{true}
\newbool{Letter}
\setbool{Letter}{false}


\begin{document}
%\ifthenelse{\boolean{CV}} % <============================== with ifthen
\ifbool{CV} % <=========================================== with etoolbox 
{% print CV
  \makecvtitle
  \setlength{\hintscolumnwidth}{0.195\textwidth}
  \section{Hobbys}
  \cvlistitem{dance}
  \cvlistitem{chess}
  \cvlistitem{cook}
  \cvlistitem{swim}
  \ \\
  \ \\
  \includegraphics[width=4cm, height=1cm]{example-image} \\
  ccity, 10. Oktober 2017
  \clearpage
}%
{% print no CV
}
\title{Bewerbung um XXX}
%\ifthenelse{\boolean{Letter}} % <========================== with ifthen
\ifbool{Letter} % <======================================= with etoolbox
{% print Cover Letter
  \recipient{Xxxy}{Xxxxx\\XXXXX\\XXXXXXXX}
  \date{ccity, 10.10.2017}
  \opening{\textbf{Sehr geehrte Damen und Herren},}
  \closing{Mit freundlichen Grüßen,}
  \enclosure[Im Anhang]{Lebenslauf}          
  \makelettertitle

  Suspendisse commodo, massa eu congue tincidunt, elit mauris 
  pellentesque orci, cursus tempor odio nisl euismod augue.
  \makeletterclosing
}
{% print no Cover Letter
}

\end{document}

resulting in the following pdf:

resulting cv without letter

1

\ifbool{<bool>}{<true>}{<false>} takes three arguments. The first is the boolean variable (defined via \newbool{<bool>}) while the second and third define the branches to follow dependent on the value of the boolean being either <true> or <false>.

enter image description here

\documentclass{article}

\usepackage{etoolbox}

\begin{document}

\newbool{CV}
\setbool{CV}{true}% Equivalent to \booltrue{CV}
\newbool{Letter}
\setbool{Letter}{false}% Equivalent to \boolfalse{Letter}

\ifbool{CV}{print CV}{do not print CV}%

\ifbool{Letter}{print Cover Letter}{do not print Cover Letter}%

\end{document}
2
  • Thanks Werner I have 3 arguments in my tex file. The third argument (brace) is empty {}. But I have still the error with Undefined control sequence. }
    – Hakikat41
    Commented Aug 23, 2021 at 0:15
  • @Hakikat41: It doesn't show in your code snippet. Can you provide a minimal document that replicates the issue so we can inspect what's going on? It should start with \documentclass and end with \end{document} and allow us to copy-and-paste-and-compile and see exactly the error what you're seeing. Can you do that?
    – Werner
    Commented Aug 23, 2021 at 15:37

You must log in to answer this question.

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