[Tex/LaTex] the difference between \thename and \the@name while writing a .cls file

documentclass-writingmacros

What is the difference between \myname and \my@name while writing a .cls file? Are they equivalent?
Please let me know if it is necessary to post a minimal example.
Edit:
Let me ask my question more clearly:
What is the difference between the two following lines?

‎‎\def\myname#1{\gdef\@myname{#1}}‎‎
‎\newcommand*{\myname}[1]{\gdef\my@myname{#1}}‎‎

I am a bit confused with these lines. I know exactly the difference between \myname and \@myname, however I don't know the difference between \myname and \my@name in a .cls file.

Best Answer

\my@name and \myname are in different 'namespace' of TeX.

The catcode of @ are different in a .tex file and a .cls file. @ is a letter in a .cls or .sty file (catcode 11); but an 'other character' in a .tex file (catcode 12). (see TeXbook, Ch 8)

Therefore, a user of your class file cannot use \my@name directly in .tex file, it is protected; but (s)he can use \myname freely.

Macros with @ like \my@name are used for internal macros. They slould not be accessed by normal users. While macros without @ like \myname are used for interface macros, that should be used by normal users.

An example (it's silly, for demostration only):

% setname.sty
\providecommand\setname@name{}
\newcommand\setname[1]{%
  \renewcommand\setname@name{#1}}
\newcommand\getnameinparens{%
  (\setname@name)}
\endinput

Package users can use \setname to set the name and \getnameinparens to get the (name). However, they cannot access \setname@name, unless \makeatletter is used.

Related Question