0

Recently, I have found a CV template class here in GitHub

In the file awesome-cv.cls, there are some definitions confuse me, like:

% Define writer's name
% Usage: \name{<firstname>}{<lastname>}
% Usage: \firstname{<firstname>}
% Usage: \lastname{<lastname>}
% Usage: \familyname{<familyname>}
\newcommand*{\name}[2]{\def\@firstname{#1}\def\@lastname{#2}}
\newcommand*{\firstname}[1]{\def\@firstname{#1}}
\newcommand*{\lastname}[1]{\def\@lastname{#1}}
\newcommand*{\familyname}[1]{\def\@lastname{#1}}
\def\@familyname{\@lastname}

Can anyone explain to me why @ symbol is used here?

updates

I found something in Minutes in Less Than Hours, which might help. enter image description here

Bernard
  • 271,350
Jiadong
  • 175
  • 1
    Best way to think of this, is if the original author had used X instead of @ (which would work) would you have asked why X was being used? @ may look different to other letters to a human but (in a class file) they look the same to latex. – David Carlisle Jul 17 '19 at 08:27

2 Answers2

2

Because are designed as internal macros for some package or document class that the final user should not know/use/rewrite. That is, the final user should/could use \firstname in the main.tex but not \@firstname, because @ (at) is then a special character (as &,%, etc.) that cannot be usually used in a control sequence, except whilst you make at a normal letter (\makeatletter) and until you do not make at other type of special character (\makeatother). This is made changing the catcodes (see What do \makeatletter and \makeatother do?). There a lot of examples in this site fixing a package bug or change the default behaviour of some class with \makeatletter (a lot of code with many @) \makeatother, although ideally the final user should not see this, even if it is their own patch, because that code is best placed hiddenly in some .sty or .cls file.

Fran
  • 80,769
  • thank you for your reply, I want to write my own cls file, that might be one reason I'f like to figure out. – Jiadong Jul 17 '19 at 08:00
0

In a sty or cls file, the letter @ changes (of what is called its catcode) and it becomes possible to use it in names of macros. In \def\@firstname, \@firstname is the name of a macro and it will be defined in the instruction.

F. Pantigny
  • 40,250
  • You mean it will be used later in the code of cls file, because I do identify their appearance in the code followed. – Jiadong Jul 17 '19 at 07:28
  • Yes, the macro \@firstname (which will contain the first name of the writer as said in the comment) is used later in the cls file or in an sty file loaded by the cls file. – F. Pantigny Jul 17 '19 at 07:37
  • what if I remove all the @ symbols and used \firstname in the macros below. Is it OK?thanks – Jiadong Jul 17 '19 at 07:39
  • Actualy, I am still confused about the catcode concept. – Jiadong Jul 17 '19 at 07:46
  • The code defines \firstname and, when used, \firstname will define \@firstname. Example: if you use \firstname{Andrew}, then \@firstname will contain Andrew and it will be used by commands latex in the cls file, for example by \makeletterclosing. – F. Pantigny Jul 17 '19 at 07:47
  • 1
    Here, the change of catcode of @ is only a security. In the normal .tex file, you won't be able to use \@firstname, because, if you type \@firstname in your tex file, it will be interpreted as \@ (a first macro) and then the letters f, i, r, etc. If you really want to use \@fistname in the tex file using that classe, you would have to write \makeatletter \@firstname \makeatother. – F. Pantigny Jul 17 '19 at 07:52
  • sorry for so many questions, so this is usually the case in writting sty and cls files? – Jiadong Jul 17 '19 at 07:52