0

I have a custom class that loads article. I can set certain default parameters, but the draft option seems to be ignored. I have the following in my custom class:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sdy-article}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

\LoadClass[10pt, a4paper, draft]{article}

This indeed gives me a 10pt a4paper, but it is not in draft mode. If I set the draft mode in the document where I load the custom class like so:

\documentclass[draft]{sdy-article}

It does go into draft mode. The thing is, I want to have some conditional in my custom class to determine whether draft mode should be set or not and then pass that on.

I have tried passing it like this as well to no avail:

\PassOptionsToClass{draft}{article}

EDIT

Adding a full example here to show what is happening.

sdy-article.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sdy-article}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

\LoadClass[10pt, a4paper, draft]{article}

main.tex:

\documentclass{sdy-article}
\usepackage{graphicx}

\begin{document}

\noindent\includegraphics[width=3cm]{example-image-a}\qquad
\includegraphics[width=3cm]{example-image-golden}\qquad
\includegraphics[width=3cm]{example-grid-100x100pt}

\noindent\includegraphics[height=5cm]{example-image-b}

\noindent\includegraphics[scale=0.5]{example-image-c}

\noindent\includegraphics[width=3cm]{example-image}

\end{document}

this gives the following output: enter image description here

As you can see, images are rendered as if draft mode was not set. The weird thing is that \overfullrule is in fact set to 5.0pt as you would expect in draft mode. When I add the draft option in main.tex (\documentclass[draft]{sdy-article}), it does go full draft mode:

enter image description here

2 Answers 2

2

You didn't show an example where draft was not passed on.

If I run

\documentclass{sdy-article}

\begin{document}

\showthe\overfullrule
\end{document}

Then the terminal shows

> 5.0pt.
l.5 \showthe\overfullrule
                         
? x
No pages of output.

showing that the article class draft mode is active, setting the overfull box rule to 5pt rather than the default 0pt.


With the modified example, the question is now rather different. draft is passed on to the article class but it is not passed to graphicx and it is not a global document option as it is not in the explicit user-supplied list of options passed to \documentclass therefore graphicx does not see draft Your class could do

\PassOptionsToPackage{draft}{graphicx}

Then if graphicx is loaded it will see draft

7
  • Right, I see that too. However, the resulting document has all images rendered as if the document wasn't in draftmode. Also, \ifraft from the package ifdraft will execute as is draftmode was not set Commented Jun 16, 2020 at 21:08
  • I have added a full example to my question Commented Jun 16, 2020 at 21:24
  • @SeeDoubleYou ah that's a different question, I'll add a note to my answer Commented Jun 16, 2020 at 21:40
  • @SeeDoubleYou updated answer Commented Jun 16, 2020 at 21:44
  • Thanks David, however, my question is not about graphicx specifically, my example was merely... an example. The thing is, when I set draft as an option in main.tex, it is set and used everywhere. So graphics are in draft, \ifdraft renders the draft case, etc. However, when I set it in \Loadclass or with \PassOptionsToClass, this does not happen. I want to know why that is, since I really don't want to pass draft manually to all packages. Also, I have quite some things relying on \ifdraft Commented Jun 16, 2020 at 21:49
0

To those getting here later, let me show you how I "solved" this in the end. @DavidCarlisle's answer will remain as the accepted answer since it explains what going wrong and why. This is just for any future readers that may want to accomplish something similar.

Again, in short, I want to set the draft option "globally" once, like what would happen if you add it as an option to documentclass. I want to do this in my custom class, based on some conditional.

David mentioned in the chat that although it no being a supported interface, adding draft to \@classoptionslist "by hand" could do the trick. Then I came across this answer here: https://tex.stackexchange.com/a/274057/45330 And I did pretty much the same thing:

[...]
<pseudo: conditional states we need to set draft>
  \@expandtwoargs\in@{draft}{\@classoptionslist}
  \ifin@
  % draft has been used as a global option by the user, do nothing
  \else
    % append draft to the list of global options
    \ifx\@classoptionslist\@empty
      \g@addto@macro\@classoptionslist{draft}
    \else
      % with a comma if the list is not empty
      \g@addto@macro\@classoptionslist{,draft}
    \fi
  \fi
}{}
<end conditional block>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .