5
\def\A{E=mc^2}
\def\B{%
I can find a tool to convert PDF to EPS
in my neither bathroom nor kitchen.}

\documentclass{article}
\begin{document}
$\A$ is my favourite equation and the following is my favourite quote.
\begin{quote}
\B
\end{quote}
\end{document}

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

lockstep
  • 250,273
Display Name
  • 46,933
  • 5
    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
  • @doncherry However strange it sounds (and the sentence is indeed weird), the usage is correct. Compare with “she saw herself as neither wife nor mother” which is preferred to “she neither saw herself as wife nor mother”. – Harold Cavendish Jul 24 '11 at 22:43
  • By the way, she has asked about it on a sister-site: http://english.stackexchange.com/questions/30075/still-confused-with-neither-nor @Martin Doncherry was right as well. – Harold Cavendish Jul 24 '11 at 22:49
  • 1
    @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
  • 2
    @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
  • @xport “This is my book and my screwdriver. These things are mine.” If you say “This is my book and a screwdriver,” it indicates that the screwdriver is not yours, hence the possessive adjective is needed. – Harold Cavendish Jul 24 '11 at 23:22
  • @xport No problem, it was you asking. I am sorry for making it too “grammarish”. – Harold Cavendish Jul 24 '11 at 23:30
  • It's unfortunate that a number of comments have been deleted, so I can only guess what's going on. @Harrold, as you seem to be a native speaker of English, so I value your opinion higher than mine as a German-born English major; I'd be really curious though to see another example of this construction "preposition + possessive + 'neither' + A + 'nor' + B" used by a native speaker of English. It simply contradicts everything I've learned about syntax. This is definitely a different issue than the one discussed on english.sx. Maybe @AlanMunn could chime in here? :-) – doncherry Jul 25 '11 at 11:46
  • 1
    @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: Thanks, but this is a different construction (I was imprecise in my description earlier, we're almost in need of syntactic trees here): In your example, neither too short nor too long forms something like an adjective phrase that specifies career, while neither bathroom nor kitchen is a complex noun phrase that seems to be governed by my, which imho doesn’t work. So I should've asked for an example in which A and B are nouns. – doncherry Jul 25 '11 at 12:40
  • @doncherry My apologies, you are most probably correct. I thought it works with nouns as well but as I think about it now, not remembering any such usage indicates otherwise. I feel embarrassed but at least have learned something useful. Thank you. :-) – Harold Cavendish Jul 25 '11 at 14:32
  • 1
    @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

3 Answers3

9

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

\ifdefined\dontincludethispart\else
<part not to be always included>
\fi

(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.

egreg
  • 1,121,712
  • 1
    A nice example of defining a macro that is used in the \documentclass is in one of Norman Gray's answers: http://tex.stackexchange.com/questions/611/setting-class-options-after-documentclass/617#617 – Charles Stewart Jul 25 '11 at 00:42
6

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.

Martin Scharrer
  • 262,582
2

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.

Seamus
  • 73,242