# PassOptionsToPackage and knitr child documents

I am using Knitr and the standalone version of .RNW files where I can compile either a main document or work with and compile child documents individually. Because of other packages, I would like to use the optional document class argument draft.

However, I do not want the functionality of the draft argument to be passed to the graphicx package. I can avoid this by using the PassOptionsToPackage command before documentclass and this works fine.

The problem is that the child document does not pass this option to graphicx and thus, when compiling the child document by itself I get draft outputs of the graphs.

How can I pass the final argument to the graphicx package in the child document?

My parent file TestParent.RNW:

\PassOptionsToPackage{final}{graphicx}
\documentclass[draft]{article}
\begin{document}

This is text from the main file.

<<child, child='TestChild.RNW'>>=
@

This is also text from the main file.

\end{document}


Child document TestChild.RNW.

<<set-parent_stocks, echo=FALSE, cache=FALSE>>=
set_parent('TestParent.Rnw')
@

This chunk below is from the child document.

<<test-child, out.width='2in'>>=
plot(1:2)
@


• What happens if you add a second \PassOptionsToPackage{final}{graphicx} after \documentclass[draft]{article}.? Dec 19 '17 at 10:59
• @UlrikeFischer I tried but the output is unchanged. Should I add to the question that I have tried it? Dec 19 '17 at 11:11
• And what happens if you add \usepackage[final]{graphicx}? Dec 19 '17 at 11:12
• Sorry, I probably should have stated this. I cannot add the package since knitr adds usepackage[]{graphicx} right after the documentclass when it weaves the document and thus creates a clash of a package being loaded twice. Dec 19 '17 at 12:05
• Then add \setkeys{Gin}{draft=false} to your preamble (and hope that it gets after graphicx ;-)). Or perhaps better use \AtBeginDocument{...}. Dec 19 '17 at 12:08

You can reset the draft key of graphics locally (for the following pictures) with

 \setkeys{Gin}{draft=false}


So you only need to ensure that this commands comes after the loading of the graphicx package. From the comments I got that this here will work:

\documentclass[draft]{article}
\setkeys{Gin}{draft=false}
\begin{document}

This is text from the main file.

<<child, child='TestChild.RNW'>>=
@

This is also text from the main file.

\end{document}


But one can also delay the setting further by using \AtBeginDocument{\setkeys{Gin}{draft=false}} in the preamble instead.