1

I write a document with the book class and have a file (mainstyle.sty) with a number of packages that I use (pdfx, lipsum, placeins, etc\ldots).

I recently started playing around with tufte-book and got several warnings, errors and unpleasant messages. Got my hands on it, but I realise that it will take time to tune it little by little. I would like to switch classes easily and load the corresponding packages and options easily.

The main issue here is that the class tufte-book loads several packages previously, and thus my file crashes if I just change the class on the fly.

Right now, what I have in master.tex is:

%\documentclass[a4paper]{tuftebook}
\documentclass[12pt,a4paper]{book}
\usepackage{./inc/mainstyle}

\begin{document}
    text text text
\end{document}

My idea now is to split mainstyle.sty in two files and use a mixture of conditionals and \PassOptionsToPackage (inspired by these two questions). The idea would be to have a parameters.sty file and a load.sty file, with the main document modified like:

\input{./inc/parameters}
%\documentclass[a4paper]{tuftebook}
\documentclass[12pt,a4paper]{book}
\input{./inc/load}

\begin{document}
    text text text
\end{document}

Then I'd have something like:

%parameters.tex ---------
\PassOptionsToPackage{pdftex,pdfa,hidelinks}

and:

%% load.tex ------------
\makeatletter

\@ifclassloaded{book}{
    \usepackage{hyperref}
}{
    \@ifclassloaded{tufte-book}{
        % hyperref was already loaded
    }
}

\makeatother

This is roughly the same that is proposed in this other question, right?

However, it feels cumbersome and I don't know if I'm just messing things around. Also, my understanding of conditionals/macros and such is still very limited.

Is this the right way to go?

9
  • Stopped reading in the middle. There is no real use to switch classes easily. Decide now and do it properly instead of wasting time (procrastinate) in doing conditionals.
    – Johannes_B
    Aug 8, 2016 at 16:43
  • Tufte has the option nohyper which is a splendig idea. It should be used by everyone as hyperref should NEVER be loaded by a freaking class file. It cuts off YOUR control.
    – Johannes_B
    Aug 8, 2016 at 16:46
  • @Johannes_B Hehe, you made me remember this comic :)(took me less than 2 hours to find it again) Thanks for the nohyper tip, I have it in my code already.
    – Luis
    Aug 8, 2016 at 19:42
  • @Johannes_B Easy to say, but when the class is modifying the same macros that hyperref modifies, you have an arms race. There are some workarounds (like using the filehook package to patch/repatch macros after a package has been loaded, but that's just kicking the can farther down the road in some cases.
    – godbyk
    Aug 8, 2016 at 21:56
  • Do you really need extra conditions? Can't you instead just use \@ifclassloaded and \@ifpackageloaded?
    – user30471
    Aug 8, 2016 at 23:20

0

You must log in to answer this question.

Browse other questions tagged .