1

I use moderncv for my CV and changed the header for the classic and the casual style (but not the other three styles), following the advice from this post:

Moderncv adding date of birth to personal information

That worked as a charm regarding the layout. I put each changed \makecvhead{} macro in a separate file, put them in the main LaTeX-document with \input and if I want the classic or the casual style, I have to remove the comment accordingly:

%\input{dateofbirth_for_casual}
\input{dateofbirth_for_classic}

To learn something new, and for the sake of simplicity, now I want to just change the style in \moderncvstyle{} and the rest should be taken care of automatically, i.e. the appropriate header should be used as necessary.

It boils down to the question:

How can I extract which style is defined by the user (aka myself) programmatically and use it in if-statements?

Something like this:

\ifthenelse{\equal{\@moderncvstyle}{classic}}{
    %do something because it's classic
}{}
\ifthenelse{\equal{\@moderncvstyle}{casual}}{
    %do something because it's casual
}{}

From scanning the code of "moderncv.cls" and the other files in the package, I have no clue where the value of \moderncvstyle{} is stored, and I do not know if my test is okay or maybe I have to put the testing condition in quotation marks or anything..?

\ifthenelse{\equal{**WHAT IS THE STYLE?**}{"casual"}}{
    %do something because it's casual
}{}

At the end I only want to have one file as \input I use everytime and don't want to care anymore which changed header is used:

\input{dateofbirth_for_classic_or_casual}

Thanks!


Not working ME with pseudo code:

\documentclass[12pt]{moderncv}
\moderncvstyle{casual}

% Pseudo-Code starts here:

% If style = casual
% do this
% if style = classic
% do that
% if style = banking or fancy or oldstyle
% do nothing    

\name{John}{Doe}
\address{111 Mimimi}{Here}{Somewhere}
\phone[mobile] {+01~(0)123 456789}
\email{John.Doe@mail.com} 
\begin{document}
\makecvtitle
\end{document}
1

The style loaded with \moderncvstyle is not stored to some macro, but this can be changed by patching \moderncvstyle.

The definition in moderncv.cls is

\newcommand*{\moderncvstyle}[2][]{
  \RequirePackage[#1]{moderncvstyle#2}}

so basically it is sufficient to catch the 2nd argument and redefine a storage macro, say \@moderncvstyle which can be evaluated later on.

I used the traditional \ifnum0=\pdfstrcmp{}{} test here, since \pdfstrcmp is a pdftex primitive.

\documentclass[12pt]{moderncv}

\usepackage{xpatch}

\makeatletter
\providecommand{\@moderncvstyle}{}
\providecommand{\@moderncvstyleoptions}{}
\xapptocmd{\moderncvstyle}{%
  \renewcommand{\@moderncvstyleoptions}{#1}{}{}
  \renewcommand{\@moderncvstyle}{#2}{}{}
}
\makeatother

\moderncvstyle{banking}


\makeatletter

\ifnum0=\pdfstrcmp{\@moderncvstyle}{casual}
\typeout{Yes, it's casual type}
\else
\ifnum0=\pdfstrcmp{\@moderncvstyle}{classic}
\typeout{Yes, it's classic type}
\else
\ifnum0=\pdfstrcmp{\@moderncvstyle}{banking}
\typeout{Yes, it's banking type}
\fi
\fi
\fi
\makeatother

% Pseudo-Code starts here:

% If style = casual
% do this
% if style = classic
% do that
% if style = banking or fancy or oldstyle
% do nothing    

\name{John}{Doe}
\address{111 Mimimi}{Here}{Somewhere}
\phone[mobile] {+01~(0)123 456789}
\email{John.Doe@mail.com} 
\begin{document}
\makecvtitle
\end{document}
2
  • Thank you very much! Overall, you answer is working because now I can capture the style-info and use them in a conditional, but one caveat is still there: if I use the \ifnum0=\pdfstrcmp{}{} variant, I get a strange "control-sequence not defined error" from the classic-variant (using the altered \makecvhead statement from the post I mentioned), but not for the casual-style. With ìfthenelse-statements, everything works! – Woosah Jun 26 '17 at 7:12
  • Ok, now I am confused. Tested it in a MWE, and there everything is fine, but in my real document, the error occures...therefore it is an error to be of no importance for anyone else! – Woosah Jun 26 '17 at 7:20
0

In case someone is needing the functionality of adding a birth of date and the family status, too, I posted an example with the appropriate headers for all five styles here:

https://tex.stackexchange.com/a/376850/136789

The variant with \ifnum0=\pdfstrcmp strangely did not work for me so I did it using \ifthenelse but nevertheless @christian-hupfer provided the framework to get it working in the first place.

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.