Add new commands to moderncv template

moderncv is an awesome template for writing your resumé (here‘s the project on launchpad). The only down side to it is that you must know some latex if you want to edit it, as for every latex template.

What I wanted to do was simply to add a second mobile number field, right below the first mobile number. Bad news is, you can’t call \mobile{my_second_number} or it will only display the second number.

I was only able to find how to add a second address field thanks to this answer by user Werner (who looks like some latex guru seeing his profile) on stackexchange.

It’s all there, you only have to know how latex treats commands, which I keep forgetting as it’s something I don’t need all the time.

So I thought it might help to have a little list of what you need to do.

  1. pick the appropriate snippet (depending on the moderncv style you use) from Werner’s answer, copy and paste it right after the \moderncvstyle{classic} (or \moderncvstyle{casual})
  2. define your command: after this line
    \newcommand*{\addresstwo}[2]{\def\@addressstreettwo{#1}\def\@addresscitytwo{#2}}
    

    add a new line for your command. In my case it’s this line

    \newcommand*{\mobiletwo}[1]{\def\@mobiletwo{#1}}
    

    (notice the first 1, it’s the number of values that you define as argument for that command)

  3. set where your command must be displayed in the title: add a line in the correct position inside the \renewcommand*{\makecvtitle} block. I put my second mobile number right after the first, so my mobile phone numbers look like this:
    \ifthenelse{\isundefined{\@mobile}}{}{\makenewline\mobilesymbol\@mobile}
    \ifthenelse{\isundefined{\@mobiletwo}}{}{\makenewline\mobilesymbol\@mobiletwo}
    
  4. set where your command must be displayed in the letter head: do the same thing as in the previous step, but this time inside the \renewcommand*{\makelettertitle} block
  5. set the value for the new command somewhere in the document: the position is defined by the command, so you actually don’t have to respect the order when setting values. It’s a good idea to keep them sorted as they’re supposed to appear in the final document, though.

That’s it!

You can leave the \addresstwo lines or delete them, it doesn’t make a difference as long as you don’t set values for those fields (that’s the whole point of those \ifthenelse{\isundefined{blahblahblah}{}{show something}}, where the empty brackets mean “if not defined, don’t do anything”).