I use the following to introduce new document variables to my document. They should behave like \author or \title. So when they're used without parameter, they should print the corresponding variable. If they're called with parameter, they should set the corresponding variable to this value.


Works ok, but I have to use

\tutor{new defined name}

to define the value and


to get the name printed instead of just using


What's the simplest way to introduce \tutor as desired?

  • 2
    This is not how \title and \author work. You never use them without the brackets. Commands like \maketitle use \makeatletter\@title\makeatother etc. internally. – qubyte Dec 10 '11 at 17:50
  • To push this point home, there is an error in your question. The passage "when they're used without parameter, they should print the corresponding variable" is incorrect. – qubyte Dec 10 '11 at 17:59

This usage is very uncommon with LaTeX (it's not the way \author etc. works), but it is possible to make the macro look ahead with \@ifnextchar to see if the next character is a brace (which needs to be written as \bgroup because you need a matching pair of braces in the macro).


This will expand to \gdef\@tutor if there is an argument (which will then be taken by it) or to \@tutor if not.

There is also the xparse package which allows to define macros with optional brace arguments and a way to test if the argument was there or not. See the package manual for the details. For this case it is IMHO a little overkill.

You could also define \tutor in the form you have in your post and redefine it at the begin of the document to be equal to \@tutor.

% or
% \newcommand*{\tutor}{\gdef\@tutor}


Then you can use \tutor{<argument>} only in the preamble and \tutor only in the document body.

Macros with an @ in the name need to be wrapped in \makeatletter ... \makeatother, except in package or class files, which do this automatically.

|improve this answer|||||

With xparse:


\def\@tutor{\ClassError{myclass}{Undefined \string\tutor}
  {You need to say \string\tutor{<NAME>} before using \protect\tutor by itself}}



I've also added an error message in case \tutor is used by itself before having defined its value (such definitions are used in class files, usually).

However, the usual strategy is to avoid having the user print explicitly the tutor's name; so only \tutor{<NAME>} should be at the user level and the class can use \@tutor to print the title page.

|improve this answer|||||

You can do it like this:


and then use it like this


Which is not what you want. However, if you will be using the content a lot, then it is perhaps more usual to encapsulate the above in a newcommand


You can now use the content of \@tutor with \thetutor.

In short, it's simpler to just make two commands with a predictable difference between the names (in this case the).

|improve this answer|||||

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.