2

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?

Luis
  • 587
  • 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 08 '16 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 08 '16 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 08 '16 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 08 '16 at 21:56
  • Do you really need extra conditions? Can't you instead just use \@ifclassloaded and \@ifpackageloaded? –  Aug 08 '16 at 23:20
  • @godbyk hyperref redefines a lot of macros, also from packages. Hence the rule of thumb: Load hyperref as late as possible in the preamble. But there are exceptions. – Johannes_B Aug 09 '16 at 07:51
  • @Andrew Which extra conditions do you mean? I have only \@ifclassloaded right now. The idea to put two in a sort of if-then-else-default-construction was to avoid other classes, and may be deleted, yes. – Luis Aug 09 '16 at 10:10
  • @Luis Sorry, I misunderstood!. I thought that you were adding new conditionals for several packages... –  Aug 09 '16 at 13:38
  • @Andrew No problem, and thanks for having a look! :) – Luis Aug 10 '16 at 11:25

0 Answers0