moderncv 中的条件格式

moderncv 中的条件格式

我们忙着讨论在 moderncv 类中实现条件语句的方法(moderncv 中的条件内容) 上个月。

Sean Allred 想出了一个很棒的解决方案来解决这个问题(请参阅附件中的 MWE)。但是,我也很难实现条件格式(对于 resumemode=true 和 =false)。在当前代码中,格式按照第 39 行的定义进行,但对于两种情况(真和假):

\exp_args:No \moderncvcolor{\bool_if:NTF \l_mil_resume_mode_bool {green}{blue}}

有人知道如何解决这个问题或者问题可能出在哪里吗?

干杯,米尔

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


%DEFINITIONS FOR RESUME <-> CV MODE
\usepackage{expl3,xparse}
\ExplSyntaxOn
\keys_define:nn { mil / resume } { % from `expl3`
  start        .tl_set:N   = \l_mil_resume_start_tl,
  end          .tl_set:N   = \l_mil_resume_end_tl,
  degree       .tl_set:N   = \l_mil_resume_degree_tl,
  institution  .tl_set:N   = \l_mil_resume_institution_tl,
  city         .tl_set:N   = \l_mil_resume_city_tl,
  grade        .tl_set:N   = \l_mil_resume_grade_tl,
  resume-text  .tl_set:N   = \l_mil_resume_resumetext_tl,
  cv-text      .tl_set:N   = \l_mil_resume_cvtext_tl,
  resume-mode  .bool_set:N = \l_mil_resume_mode_bool
}

\NewDocumentCommand \ResumeMode { O{true} } { % from `xparse`
  \keys_set:nn { mil / resume } { resume-mode = #1 }
}
\NewDocumentCommand \CVEntry { m } {
  \group_begin:
  \keys_set:nn { mil / resume } { #1 }
  \cventry{\l_mil_resume_start_tl--\l_mil_resume_end_tl}
          {\l_mil_resume_degree_tl}
          {\l_mil_resume_institution_tl}
          {\l_mil_resume_city_tl}
          {\l_mil_resume_grade_tl}
          {
            \bool_if:NTF \l_mil_resume_mode_bool {
              \l_mil_resume_resumetext_tl
            } {
              \l_mil_resume_cvtext_tl
            }
          }
  \group_end:
}
\exp_args:No \moderncvcolor{\bool_if:NTF \l_mil_resume_mode_bool {green}{blue}}
\ExplSyntaxOff




\usepackage[utf8]{inputenc}  
\moderncvstyle{banking}

\ResumeMode[false] %true => generates RESUME; false => generates CV



%Personal Details
\name{Mil}{Test}
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}


\begin{document}
\makecvtitle

\CVEntry{
  start=1993,
  end=2005,
  degree=B.\,S.,
  institution=\TeX\ StackExchange,
  city=Internet,
  grade=Grade,
  resume-text=resume text,
  cv-text=cv text,
}
\CVEntry{
  start=1993,
  end=2005,
  degree=B.\,S.,
  institution=\TeX\ StackExchange,
  city=Internet,
  grade=Grade,
  resume-text=resume text,
  cv-text=cv text,
  resume-mode=true, %will always show resume text
}


\end{document}

4月4日编辑: Sean Allred 为这个问题提供了一个非常好的解决方案(见下文),但它带来了一些令人困惑的编译问题(至少对我来说)。根据他的建议,请看一下这两个略作修改(仅格式部分)的示例:

a) 直接实施

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

\usepackage{expl3,xparse}

\ExplSyntaxOn
\keys_define:nn { mil / resume } {
  start        .tl_set:N   = \l_mil_resume_start_tl,
  end          .tl_set:N   = \l_mil_resume_end_tl,
  degree       .tl_set:N   = \l_mil_resume_degree_tl,
  institution  .tl_set:N   = \l_mil_resume_institution_tl,
  city         .tl_set:N   = \l_mil_resume_city_tl,
  grade        .tl_set:N   = \l_mil_resume_grade_tl,
  resume-text  .tl_set:N   = \l_mil_resume_resumetext_tl,
  cv-text      .tl_set:N   = \l_mil_resume_cvtext_tl,
  resume-mode  .bool_set:N = \l_mil_resume_mode_bool
}

\NewDocumentCommand \ResumeMode { O{true} } {
  \keys_set:nn { mil / resume } { resume-mode = #1 }
}

\NewDocumentCommand \CVEntry { m } {
  \group_begin:
  \keys_set:nn { mil / resume } { #1 }
  \cventry{\l_mil_resume_start_tl--\l_mil_resume_end_tl}
          {\l_mil_resume_degree_tl}
          {\l_mil_resume_institution_tl}
          {\l_mil_resume_city_tl}
          {\l_mil_resume_grade_tl}
          {
            \bool_if:NTF \l_mil_resume_mode_bool {
              \l_mil_resume_resumetext_tl
            } {
              \l_mil_resume_cvtext_tl
            }
          }
  \group_end:
}

% < -- CHANGE HERE -- > %
\AtBeginDocument{
  \bool_if:NTF \l_mil_resume_mode_bool {
    \moderncvstyle{banking}
    \moderncvcolor{black}
    \usepackage[scale=0.9,top=0.9cm,bottom=0.5cm]{geometry}
  } {
    \moderncvstyle{casual}
    \moderncvcolor{green}
    \usepackage[scale=0.85]{geometry}
  }
}
\ExplSyntaxOff

\usepackage[utf8]{inputenc}  

\firstname{Mil}
\familyname{Longer title to see it better}


\ResumeMode[true] %False=CV - True=RESUME
\begin{document}
\makecvtitle
\vspace*{-10mm}

\CVEntry{
  start=1993,
  end=2005,
  degree=B.\,S.,
  institution=\TeX\ StackExchange,
  city=Internet,
  grade=Grade,
  resume-text=resume text,
  cv-text=cv text,
}
\CVEntry{
  start=1993,
  end=2005,
  degree=B.\,S.,
  institution=\TeX\ StackExchange,
  city=Internet,
  grade=Grade,
  resume-text=resume text,
  cv-text=cv text,
  resume-mode=true, %will always show resume text
}
\end{document}

标题未居中

b) 格式化选项放在其他地方

\documentclass[11pt,a4paper,sans]{moderncv}  
\usepackage{expl3,xparse}

\ExplSyntaxOn
\keys_define:nn { mil / resume } {
  start        .tl_set:N   = \l_mil_resume_start_tl,
  end          .tl_set:N   = \l_mil_resume_end_tl,
  degree       .tl_set:N   = \l_mil_resume_degree_tl,
  institution  .tl_set:N   = \l_mil_resume_institution_tl,
  city         .tl_set:N   = \l_mil_resume_city_tl,
  grade        .tl_set:N   = \l_mil_resume_grade_tl,
  resume-text  .tl_set:N   = \l_mil_resume_resumetext_tl,
  cv-text      .tl_set:N   = \l_mil_resume_cvtext_tl,
  resume-mode  .bool_set:N = \l_mil_resume_mode_bool
}

\NewDocumentCommand \ResumeMode { O{true} } {
  \keys_set:nn { mil / resume } { resume-mode = #1 }
}

\NewDocumentCommand \CVEntry { m } {
  \group_begin:
  \keys_set:nn { mil / resume } { #1 }
  \cventry{\l_mil_resume_start_tl--\l_mil_resume_end_tl}
          {\l_mil_resume_degree_tl}
          {\l_mil_resume_institution_tl}
          {\l_mil_resume_city_tl}
          {\l_mil_resume_grade_tl}
          {
            \bool_if:NTF \l_mil_resume_mode_bool {
              \l_mil_resume_resumetext_tl
            } {
              \l_mil_resume_cvtext_tl
            }
          }
  \group_end:
}

% < -- CHANGE HERE -- > %
\AtBeginDocument{
  \bool_if:NTF \l_mil_resume_mode_bool {
    \moderncvstyle{banking}
    \moderncvcolor{black}
%    \usepackage[scale=0.9,top=0.9cm,bottom=0.5cm]{geometry}
  } {
    \moderncvstyle{casual}
    \moderncvcolor{green}
    \usepackage[scale=0.85]{geometry}
  }
}
\ExplSyntaxOff

\usepackage[utf8]{inputenc}  

\firstname{Mil}
\familyname{Longer title to see it better}

\usepackage[scale=0.9,top=0.9cm,bottom=0.5cm]{geometry}
\ResumeMode[true] %False=CV - True=RESUME
\begin{document}
\makecvtitle
\vspace*{-10mm}

\CVEntry{
  start=1993,
  end=2005,
  degree=B.\,S.,
  institution=\TeX\ StackExchange,
  city=Internet,
  grade=Grade,
  resume-text=resume text,
  cv-text=cv text,
}
\CVEntry{
  start=1993,
  end=2005,
  degree=B.\,S.,
  institution=\TeX\ StackExchange,
  city=Internet,
  grade=Grade,
  resume-text=resume text,
  cv-text=cv text,
  resume-mode=true, %will always show resume text
}
\end{document}

字幕居中

答案1

尝试这个:

\documentclass[11pt,a4paper,sans]{moderncv}  
\usepackage{expl3,xparse}

\ExplSyntaxOn
\keys_define:nn { mil / resume } {
  start        .tl_set:N   = \l_mil_resume_start_tl,
  end          .tl_set:N   = \l_mil_resume_end_tl,
  degree       .tl_set:N   = \l_mil_resume_degree_tl,
  institution  .tl_set:N   = \l_mil_resume_institution_tl,
  city         .tl_set:N   = \l_mil_resume_city_tl,
  grade        .tl_set:N   = \l_mil_resume_grade_tl,
  resume-text  .tl_set:N   = \l_mil_resume_resumetext_tl,
  cv-text      .tl_set:N   = \l_mil_resume_cvtext_tl,
  resume-mode  .bool_set:N = \l_mil_resume_mode_bool
}

\NewDocumentCommand \ResumeMode { O{true} } {
  \keys_set:nn { mil / resume } { resume-mode = #1 }
}

\NewDocumentCommand \CVEntry { m } {
  \group_begin:
  \keys_set:nn { mil / resume } { #1 }
  \cventry{\l_mil_resume_start_tl--\l_mil_resume_end_tl}
          {\l_mil_resume_degree_tl}
          {\l_mil_resume_institution_tl}
          {\l_mil_resume_city_tl}
          {\l_mil_resume_grade_tl}
          {
            \bool_if:NTF \l_mil_resume_mode_bool {
              \l_mil_resume_resumetext_tl
            } {
              \l_mil_resume_cvtext_tl
            }
          }
  \group_end:
}

% < -- CHANGE HERE -- > %
\AtBeginDocument{
  \bool_if:NTF \l_mil_resume_mode_bool {
    \moderncvstyle{banking}
    \moderncvcolor{blue}
    \usepackage[scale=0.85]{geometry}
  } {
    \moderncvstyle{casual}
    \moderncvcolor{green}
    \usepackage[scale=0.75]{geometry}
  }
}
\ExplSyntaxOff

\usepackage[utf8]{inputenc}  

\name{Mil}{Test}
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}

\ResumeMode[false]
\begin{document}
\makecvtitle

\CVEntry{
  start=1993,
  end=2005,
  degree=B.\,S.,
  institution=\TeX\ StackExchange,
  city=Internet,
  grade=Grade,
  resume-text=resume text,
  cv-text=cv text,
}
\CVEntry{
  start=1993,
  end=2005,
  degree=B.\,S.,
  institution=\TeX\ StackExchange,
  city=Internet,
  grade=Grade,
  resume-text=resume text,
  cv-text=cv text,
  resume-mode=true, %will always show resume text
}
\end{document}

由于resume-mode可能未在序言中设定然而但必须在文档正常启动时,我们将其包装在钩子中\AtBeginDocument。(还请注意,这使我对\exp_args:构造的使用过时了;当前的实现至少要清晰得多,即使以牺牲一点内存效率为代价。;)

相关内容