etoolbox bool cv 和字母表达式(早期的 ifthen 包)

etoolbox bool cv 和字母表达式(早期的 ifthen 包)

我有一个.tex文件,我之前用 定义了一个表达式\usepackage{ifthen}。现在我想用它\usepackage{etoolbox}来达到这个目的,但不知道如何正确使用它,Undefined control sequence.}编译后出现错误。

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

未定义控制序列的错误在哪里?我找不到错误。如何正确使用ifbool?如果一个表达式为真,我是否需要从其他括号中断?任何帮助都将不胜感激

答案1

根据您给出的 MWE你的旧问题像这样更改你的简历(请参阅标有 ​​的重要代码更改<======):

\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}

生成以下 pdf:

导致简历无字母

答案2

\ifbool{<bool>}{<true>}{<false>}需要参数。第一个是布尔变量(通过 定义\newbool{<bool>}),而第二个和第三个定义要遵循的分支,取决于布尔值的值为<true><false>

在此处输入图片描述

\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}

相关内容