# Setting class options after \documentclass

Context: I'm working on my thesis, and the formatting requirements are pretty godawful. In addition to the version I submit to the grad school, I would like to also create a properly formatted version for everyone else.

In particular, my document begins:

\documentclass[twoside]{book}


Is it possible to later countermand the twoside option?

-

Yes, but like many of the kernel class options it was not exactly designed for this. You'd by much better off simply having two potential document class lines, or something as simple as

\documentclass[
twoside
]{book}


so you can comment out the option as necessary.

-
Hmmm... bummer, but thanks! BTW, the grad school is going to get an earful on this when I fill out their end-of-degree survey. They actually had the balls to tell me that 1.5-spacing is easier to read. –  Reid Jul 30 '10 at 15:55
easier to read than what? it is easier to read than single spaced –  drfrogsplat Aug 16 '10 at 5:51
@drfrogsplat, it rarelly depends. Newspapers are not set in 1.5 spacing, and they sure aren't less easy to read because of that. Books, too. I've heard once that more spacing in theses was meant for corrections/comments, or for filling up space for "correct" page counting. So, Reid, if it is mandatory to set line spacing at 1.5, do it; if it isn't an official rule, forget about it and use LaTeX default. –  Joseph Dec 24 '12 at 10:40
@Joseph, newspapers and books have much thinner columns (~5cm and ~10cm respectively) than the typical A4/similar page, single column format of most theses (~15cm). Wider columns mean more chance of picking the wrong 'next' line as you read from one to the next, so a little extra space in wider formats can help. Larger text sizes helps too of course (newsprint/books are more like 9-10pt while a thesis is more likely 12pt). 1.5 isn't necessarily the best, but its probably a little better than 1.0 and certainly better than 2.0. I picked about 1.3 for mine. –  drfrogsplat Dec 27 '12 at 12:57
@drfrogsplat: sounds sensible. Do you think one could calculate an adequate (optimal?) \baselineskip as a function of \textwidth and font size? –  user1129682 Jul 10 '14 at 8:05

I did the same thing for my dissertation. Crappy copies for the University library, decent copies for myself and the committee. The easiest thing to do might be to have two versions of the master tex file, which then \input individual chapters. This lets you tweak each one, while using the same content.

BTW: Playing with LaTeX formatting is a great way to procrastinate, while maintaining the illusion that you are doing something useful.

-
+1 for the comment on procrastination –  Juan A. Navarro Jul 29 '10 at 21:50
+1 more for the same –  Blake Stacey Jul 29 '10 at 23:45
+1 for recursion –  user1129682 Jul 10 '14 at 10:24

Joseph's answer is the most pragmatic one -- there's no need to complicate things.

In some circumstances, it can be useful to exercise some control over LaTeX from 'outside' – perhaps you want to be able to produce two different versions of a document from a Makefile. One way to do that is to create a file containing some LaTeX and \input it at some strategic point. The other is to use a not very well known feature of the TeX program (at least on Unix systems, but probably on Windows ones, too).

The \documentclass doesn't have to be the first thing in the file. Consider this:

\providecommand\pointsize{10pt}
\documentclass[\pointsize]{article}
\begin{document}
Here is some text.
\end{document}


That defines \pointsize to be 10pt if it's not defined already. How could it be defined before the beginning of the file? Easy! If this file is doc.tex, then you can do:

% latex '\def\pointsize{12pt}\input{doc}'


Voilà!

This is an occasionally useful escape hatch. I suspect it's also very easy to get carried away, and start writing something horribly obfuscated.

Edited to use \providecommand rather than TeX arcana (thanks to comments from @user1129682)

-
This type of thing is often useful when you do complex builds, and use something like a Makefile or batch script to do the actual typesetting. For example, the LaTex3 Project scripts for expl3 use similar approaches to determine how much documentation to produce. –  Joseph Wright Jul 29 '10 at 21:26
@norman-gray: Why the big guns? Intuitively, I'd \providecommand{\pointsize}{10pt}. I suppose it does the very thing you wrote, but with a much nicer interface and easier to understand. –  user1129682 Jul 10 '14 at 8:09
@user1129682 True, it does seem a bit heavy-handed, but your suggestion (if I'm understanding you correctly) is not the same, since the 10pt class option does a lot of other stuff (changing line spacings, footnote sizes, ...) beyond simply changing the point size. By the time you're in the document, it's 'too late' for those changes, so the switch has to happen before \begindocument. –  Norman Gray Jul 10 '14 at 9:46
@NormanGray: I would replace your if-statement with \providecommand, so that \pointsize would still be used as class option, as it does in your example. –  user1129682 Jul 10 '14 at 10:23
@user1129682 Ah, I see what you mean! You're right: \providecommand\pointsize{10pt}\documentclass[\pointsize]{article} is indeed rather neater. I'll edit the answer to include that. –  Norman Gray Jul 10 '14 at 16:23

This is quite similar to a problem that I encounter with just about every article: I get it looking just how I like it, and then the journal says something stupid like "Only documents in our own in house style will be accepted." The problem is that they provide a class file which (they say) must be used, and which (helpfully!) defines a load of commands, which do nothing for the style and only get in the way.


So what I've developed is a meta class file which sets up a load of stuff and then calls the real class file. So at the head of my document I have:

\documentclass[%
a4paper,%
journalX,%
%draft,%
%hopf,%
%journalY,%
%arxiv,%
%article,%
%amsart,%
defaults,%
]%
{myclass}


There, you can see that I submitted it to a journal 'X' and that it was probably previously submitted to journal 'Y'. There are presumably some changes made in draft mode. It happened to be a paper in algebraic topology, so a copy when to the hopf archive, which I've found has some font issues. Plus there are some defaults getting set. The 'a4paper' option (as with any other unknown option) gets passed on to the eventually-selected class file.

Each time I choose a new journal, I have to integrate its class file into this meta class, but that only needs doing once rather than once-per-article. One major saving on this is with organising the title page. All the title information is entered in the same way for all journals, the meta class file sorts it out into the right format for the specific journal (this is actually the major headache when integrating a new journal class file into my system - I could tell you some horror stories!).

The system gets even better when it comes to my lectures. I use beamer now for my lectures and make the slides available to the students. But I don't want them printing out the full set of slides, so I make the handout version available. Plus, to make it easier to maintain a consistent style and cut-and-paste stuff between lectures, I keep all the lectures in one file. When I run LaTeX on it, I want to be able to select: a particular lecture and a particular format (beamer, trans, handout). I do that by putting in to my meta class file a test that looks at the jobname for these details. Then I make suitable symlinks to the main file:

ln -s lectures.tex lecture.handout.2010-08-23.tex
pdflatex lecture.handout.2010-08-23.tex


produces the handout version of the lecture (to be) given on 23rd August 2010.

This solution is, I'm sure, overkill in your situation! However, as I've said, your situation is only the tip of an iceberg.

Update 2012-04-11: Every now and then I get asked about this class file. I've put a page about it on my website which is at: http://www.math.ntnu.no/~stacey/HowDidIDoThat/LaTeX/MyClass.html. A copy of the file is available there. Please note that: 1) this was written for my use with no expectation that anyone else would ever see it, let alone use it; 2) it was written a long time before this site came into existence - I would probably do it very differently now! (I'd get egreg to write it via a sequence of craftily sculpted questions.)

-
Question: when you submit to the journal, do you also include your meta class file in the submission? Somehow the journal needs to be able to compile the TeX file you submit, right? That said, this is a very neat idea! I am especially impressed by that last bit about lectures. Is there any chance you can share this class file? –  Willie Wong Jul 30 '10 at 11:11
Oh, and I completely agree with the headache on title pages. Some journals want \thanks to go inside the \author, some outside; some uses \email, some \ead; sometimes orders of commands make a huge deal. Ugh. –  Willie Wong Jul 30 '10 at 11:14
When I submit, I try to get away with just sending a PDF. If they do me the honour of actually accepting the paper, then I'm happy to do whatever changes they deem necessary. But if they insist, then I do send the whole lot. I'll happily share this class file, but I should probably go through and clean up the comments (I vaguely recall venting my fury at some journals in the comments; the order of these commands is by no means the worst I've seen!). –  Loop Space Jul 30 '10 at 11:35