2

I'm studying bit by bit of a class file to understand how to modify it to fit my needs and I'm having problems understanding some definitions. Inside the the file I have this command, which allows me to write citations:

\def\@SchCita{}
\newcommand{\scholarlycitation}[2]{%
\def\@SchCita{%
\begin{flushright}
\vspace{20pt}
\begin{minipage}{0.475\textwidth}
\fontsize{9}{12}%
\usefont{T1}{bch}{m}{it}%
\color{black}%
\selectfont%
#1\\%
\fontsize{9}{12}%
\usefont{T1}{bch}{b}{n}%
\color{DarkRed}%
\selectfont{\color{DarkGoldenrod}\hrulefill}~#2%
\end{minipage}\vspace{-10pt}%
\end{flushright}%
}%
}

In the first line there is this definition

\def\@SchCita{}

Then, inside the \scholarlycommand definition this \def\@SchCita{} appears again but with a lot of code inside its {}. What happens when you define something using \def without the replacement text inside the brackets? It looks like the SchCita is being defined twice. Why is that? And... why the @ symbol? Can you help me?

Thank you very much.

3
  • \scholarlycitation defines how the visul output is. There might be another command that \defs another visual output of citations. The code is very very strange by the way, i would stay away from modifying it. Especially since you seem to be a starter.
    – Johannes_B
    Nov 5 '16 at 19:11
  • This spagghetti code will turn into a spagghetti monster and haunt your dreams at night.
    – Johannes_B
    Nov 5 '16 at 19:11
  • \def shouldn't even be used with LaTeX, it just hammers the definition. No checking at all. Beware of unexpected results.
    – Johannes_B
    Nov 5 '16 at 19:12
2

I agree with Johannes_B that this code is very strange and would be better avoided altogether. It is also true that \def should be avoided in LaTeX when possible. Moreover, it could easily be avoided here, so it would be better to avoid it.

@ is usually used to mark a macro as 'internal'. That is, it is not a macro which should be used directly in documents or which people should count on behaving in the same way in the future. It is part of the class's implementation of the macros it provides as part of its user interface.

In documents, @ cannot be used in macro names without changing its category code to make it a letter. When reading class and package files, however, LaTeX defaults to treating it as a letter, allowing it to be used in the names of internal macros.

When you see code in a document's preamble

\makeatletter
...
\makeatother

this is to switch the category code of @ temporarily, allowing it to be used in macro names as though the code was in a class or package file rather than a document. This is often done to redefine a macro, for example, to behave differently or to workaround a problem.

In the code shown in the question

\def\@SchCita{}

makes sure that \@SchCita is defined by default. Without this definition, the macro might be undefined because the substantive definition is only constructed when \scholarlycitation{}{} is used. Presumably, \scholarlycitation{}{} is something which it is expected the user will issue in the document. \scholarlycitation{}{} uses the two arguments passed to it to redefine \@SchCita, which is then presumably used by other code, as specified in the class file.

Providing a default definition ensures that errors will not occur if \@SchCita is called before the user uses \scholarlycitation{}{}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.