TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
I can find a tool to convert PDF to EPS
in my neither bathroom nor kitchen.}

$\A$ is my favourite equation and the following is my favourite quote.

Is it OK to define a macro before document class? What is the side effect?

share|improve this question
I think it ought to be "neither in my bathroom nor in my kitchen", in other questions and answers of yours as well. – doncherry Jul 24 '11 at 22:17
@Harrold: I personally don't care if it's technically correct grammar. It's confusing, especially for non native speakers, and not the usual way to say it – Martin Scharrer Jul 24 '11 at 22:55
@Martin On this type of website, I do not care about it either – I was just trying to support doncherry. I think that his suggestion is less confusing than the original sentence by xport, who generally seems to be doing easy things the hard way. :-P – Harold Cavendish Jul 24 '11 at 23:07
@doncherry An example of the same construction: “In her neither too short nor too long career, she has made great revelations.” I normally rather use either + or because the positive e.g. “I can” at the beginning may be misleading in long sentences. – Harold Cavendish Jul 25 '11 at 12:23
@Harrold. There's nothing to apologize for. Sometimes, English retains strange syntactic constructions from past stages for singular phrases. It's always enlightening to discuss such matters with native speakers and I'm glad we could solve this question. So now, xport could edit her post(s). – doncherry Jul 27 '11 at 12:14
up vote 8 down vote accepted

TeX processes tokens following its rules and \def\A{...} conforms to them. On the other hand defining tokens that way may break depending on what packages are loaded. Even \newcommand might not be sufficient, because packages could define their macros with \def, but in any case macros with the same name at the outer level cannot exist.

One should know what's being done, in other words.

To the contrary, defining macros before \documentclass is a well known practice. Suppose you have a part of your document that you don't want to be processed in certain situations. It can be done by enclosing the part in

<part not to be always included>

(we assume that conditionals are properly balanced in that part). Calling the compilation of the file, named file.tex, with

pdflatex "\def\dontincludethispart{}\input{file}"

will not include the "secret" part. The comment package allows for similar tricks and has been discussed here on TeX.sx.

share|improve this answer
A nice example of defining a macro that is used in the \documentclass is in one of Norman Gray's answers: tex.stackexchange.com/questions/611/… – Charles Stewart Jul 25 '11 at 0:42

Yes, it is OK. There is no side effect for macros in general. The class file isn't any special from TeX points of view. However, you shouldn't define or change important macros which are also set in the class at random. You can even load packages before the class when you use \RequirePackage instead of \usepackage. Of course there might be some packages which rely on the fact to be loaded after the class.

share|improve this answer

Some macros you shouldn't define before the documentclass. Namely, if you wanted to redefine, say \section which is defined by the document class, the redefinition wouldn't work if you put it before the document class.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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