This is the package
https://github.com/mliu7/latex-moderncv
I'm trying to learn how to make packages and classes something about this package makes me confused.
On line 380
\newcommand*{\makecvtitle}{}
This makes no sense because there are no parameters however in the TeX document if you type \makecvtitle
it creates a lovely title with name address and other info.
Please explain black magic that allows this command to make a cv title
Best Answer
You'll find numerous such empty definitions inside
moderncv.cls
; not just for the title.The structure of
moderncv
is such that it defines (via\newcommand
) certain fundamental constructs when you load the classThen, depending on the choice of style you want, you would call
The above is defined as
So, with a call to
\moderncvstyle{casual}
,moderncv
loads the "package"moderncvstylecasual.sty
, which redefines\moderncv
according to its own style viaThis is one approach to writing a class: The class sets up some fundamental constructions which are then extended by loading packages related to the class; an initial
\newcommand
which is then almost immediately changed via\renewcommand
.Are there any advantages to this approach? Yes. It allows the user to call the class without loading the extensions (or packages) yet still use the basic foundation. You can now modify the construction using a standard approach:
\renewcommand{\makecvtitle}{...}
.Any disadvantages? See above... :-| I guess it depends on the end-user. You won't know to use
\newcommand{\makecvtitle}{...}
or\renewcommand{\makecvtitle}{...}
until you run into a problem.A way to circumvent this (again, from the end-user's perspective) if you want to define your own styles, would be to use a TeX-like syntax; that is
since this will overwrite the definition of
\makecvtitle
regardless of its existence.