Calling macro fails with error \inaccessible

I am trying to define a macro which I will include in a class definition. For the time being I put the macro definition in the normal document. Compiling the following document fails.

\documentclass[10pt,a4paper]{article}

\makeatletter
\def\ntcstitle#1{\def{\@ntcstitle}{#1}}
\newcommand{\thentcstitle}{\@ntcstitle}
\makeatother

\ntcstitle{Lorem Ipsum}

\begin{document}
\thentcstitle\par
\end{document}


This example is something I copied from another question here, which seemed to work:

Define variable in a class

I also tried to move this definition into a class file, omitted the \makeatletter and \makeatother commands. Using the class file was successful, the error message is the same.

This is the error message:

! Missing control sequence inserted.
<inserted text>
\inaccessible
l.10 \ntcstitle{Lorem Ipsum}


Then I replaced the macro with the LaTeX style definition:

\documentclass[10pt,a4paper]{article}
\usepackage{lipsum}

\makeatletter
\newcommand{\thentcstitle}{\@ntcstitle}
\makeatother

\ntcstitle{Lorem Ipsum}

\begin{document}
\thentcstitle\par
\end{document}


And that works as expected.

I tried to use \def instead of \newcommand because I assumed \def was the correct way to define macros in class files. What I am doing wrong here?

• Use \newcommand if you can as it is safer. What is the purpose of the command exactly? I'm not sure why you are defining 3 different commands. – cfr Dec 1 '14 at 0:43
• @cfr: The intention of the command is to define \@ntcstitle. Later I use the macro \thentcstitle to print the variable \@ntcstitle. I define the macro to set \@ntcstitle only once, but two different MWE. – jlinkels Dec 1 '14 at 1:08
• @cfr: If \newcommand is the preferred way, I'll use it. – jlinkels Dec 1 '14 at 1:13

You should not use \def in latex but if you do the syntax is

   \def\@ntcstitle{#1}}


not

   \def{\@ntcstitle}{#1}}


(The #1 and the trailing } of course only valid in the context of your definition of \ntcstitle)

• @paul The extra brace was intentional, I'll add a note in the answer – David Carlisle Dec 1 '14 at 0:48
• That is a stupid mistake. I have looked for 2 days at this code and the example and I did not notice the {}. Aaarrggghhhh – jlinkels Dec 1 '14 at 1:05
• @DavidCarlisle Sorry for my miscorrection: I did not read carefully the question... – Paul Gaborit Dec 1 '14 at 7:38
• @jlinkels: I strongly feel with you! Well, you should admit yourself that the error message was not exactly helpful to find the culprit. – Daniel Dec 19 '14 at 14:40