I'm just getting started with LaTeX, and I'm already struggling with the very basic stuff.
I create 2 commands, each assigning a value to a variable:
\newcommand{\firstname}[1]{\def\@firstname{#1}}
\newcommand{\lastname}[1]{\def\@lastname{#1}}
These variables are set using the commands somewhere at the beginning of the document:
\firstname{Kevin}
\lastname{De Coninck}
When I try to print the lastname, everything works fine, when I try to print the firstname, the following error is returned Use of \@ doesn't match its definition. \@f
I'm priting inside my document using the following code:
\begin{document}
\@firstname
\end{document}
What am I missing here?
Update: Entire document
% ----------------------------------------------------------------------
% -- CONFIGURATION
% ----------------------------------------------------------------------
\documentclass[11pt, a4paper]{article}
% ----------------------------------------------------------------------
% -- PACKAGES
% ----------------------------------------------------------------------
\RequirePackage{geometry}
% ----------------------------------------------------------------------
% -- COMMAND DEFINITIONS
% ----------------------------------------------------------------------
% Summary: Configure the person's name.
% Usage: \name{<firstname>}{<lastname>}
% firstname{<firstname>}
% lastname{<lastname>}
\newcommand{\firstname}[1]{\def\@firstname{#1}}
\newcommand{\lastname}[1]{\def\@lastname{#1}}
% ----------------------------------------------------------------------
% -- LAYOUT CONFIGURATION
% ----------------------------------------------------------------------
\geometry{left=2.0cm, top=5.5cm, right=2.0cm, bottom=2.0cm, footskip=.5cm}
% ----------------------------------------------------------------------
% -- PERSONAL DATA
% ----------------------------------------------------------------------
\firstname{Kevin}
\lastname{De Coninck}
% ----------------------------------------------------------------------
% -- ACTUAL DOCUMENT
% ----------------------------------------------------------------------
\begin{document}
\@firstname
\@lastname
\end{document}

\makeatletter\@firstname\makeatother, but you should define a wrapper command as well – Feb 01 '17 at 14:29@is a special character, in the sense that, in packages, it is considered a "letter", whereas in a document, it is considered an "other", and precluded from use in variable names. As Christian indicates, you can make@function as a letter in documents with the invocation of\makeatletter. This then allows its use in variable names such as\@firstname, etc. – Steven B. Segletes Feb 01 '17 at 14:30\newcommand{\printnames}{\@lastname, \@firstname}in a stylefile or between\makeatletter ... \makeatotheras Christian pointed out and command \printnames in your document. – Jan Feb 01 '17 at 14:32irstname. – Complexity Feb 01 '17 at 14:32lastnameproperty, but not thefirstname. – Complexity Feb 01 '17 at 14:34\makeatletter...\makeatotheraround your\newcommandusages as well – Feb 01 '17 at 14:38@in the holder macro, why not just writeCMPLX, then the macros should the prefixed enough and\CMPLXfirstnameworks out of the box. Macros with@in their name is genrally for intenal use and for experienced users. – daleif Feb 01 '17 at 14:38\printname:\newcommand{\printname}{% \@ifundefined{@firstname}{}{\@firstname} \@ifundefined{@lastname}{}{\@lastname}% }– Feb 01 '17 at 14:41\makeatletter...\makeatotheraround your\@...usages works, as well for the\newcommanddefinitions of\firstnameetc. The output isKevinDe Coninck(you're missing a\after\@firstnamethis way! – Feb 01 '17 at 14:46\def\@lastname{#1}, you define the macro\@in a very specific way. It is comparable to using\def\foo#1bar#2{#1: #2}, here thebaris a type of separator for the two arguments and is gobbled when TeX processes the code. In your case,lastnameis seen as a delimiter for the (not existing) argument. Thus, it is gobbled and\@is succesfully expande. If you use\@firstnameinstead,\@expectslastnameto follow and complains about incorrect usage. The call of\lastnameoverrides the definition from\firstname, thus only one works. – Patrick Happel Feb 01 '17 at 14:57