The document class options draft is extremely useful to speed up typesetting and visualize overfull \hbox warnings. Even more so, when you work on a large document. I previously introduced the draft and final options here and here.

The ifdraft package adds more flexibility to the draft and final options. It implements three commands with slightly different behavior when draft or final are set.

\usepackage{ifdraft} % load package \ifdraft {⟨draft case⟩} {⟨ﬁnal case⟩} \ifoptiondraft {⟨option draft given⟩} {⟨option draft not given⟩} \ifoptionfinal {⟨option ﬁnal given⟩} {⟨option ﬁnal not given⟩}

The command \ifdraft assumes final if no option is set. Furthermore, both options, draft and final , should not be used at the same time.

Let’s see a few examples.

Example 1: Line spacing

It is often easier to proof-read a text with extra space between lines. Especially, if the reader adds his comments on paper. In this case, \ifdraft allows automatic switching between double and single spacing, depending on the option set ( draft or final ). In the example, the setspace package is used to switch between single and double line spacing (see here for examples on package usage).

\documentclass[draft]{article} % draft or final option \usepackage{setspace, ifdraft, blindtext} \ifdraft{\doublespace}{\singlespace} % draft: double; final: single spacing \begin{document} \blindtext \end{document}

Example 2: Single column / two columns

It may be easier to edit a document using a single column style, even if the final version will have two or more columns. Sure, it would be sufficient to replace onecolumn with twocolumn in the list of document class options.

\documentclass[draft, onecolumn]{article} \documentclass[final, twocolumn]{article}

It might not seem like a big thing to do, but often the author switches frequently between draft and final or there are other draft-specific options, e.g. line spacing as shown in the previous example. In this case, it is faster and cleaner to hook all changes to the draft and final options.

\documentclass[draft]{article} \usepackage{ifdraft, blindtext} \ifdraft{\onecolumn}{\twocolumn} \begin{document} \Blindtext \end{document}

Example 3: Removing TODO notes

Todonotes provides functionality to visualize TODOs in the margins of the output PDF. The option disable removes all TODOs from the document. But then again, it’s cleaner and faster to link this behavior to the draft option.

In the following example the todonotes package is loaded without or with the option disable , depending on whether draft or final is used:

\documentclass[draft]{article} \usepackage{ifdraft, blindtext} \ifdraft{% \usepackage{todonotes}}{ % draft with TODOs \usepackage[disable]{todonotes} % final without TODOs } \begin{document} \blindtext\todo{Insert a more meaningful text here} \end{document}

Example 4: Draft watermark

This last example shows how the \ifoptiondraft command can be used to produce the watermark “DRAFT” only when draft is set. To learn more about watermarks, see my post on the topic here. In this example, the second argument is empty as nothing is to be done when no option is not given or final is used.

\documentclass[11pt,draft]{article} \usepackage{ifdraft, blindtext} \ifoptiondraft{% \usepackage{draftwatermark} \SetWatermarkText{DRAFT} \SetWatermarkScale{5} \SetWatermarkColor[rgb]{0.7,0,0} }{% % nothing to be done here } \begin{document} \Blindtext \end{document}

Share this: Twitter

Facebook

Reddit

LinkedIn

Skype

Email



Like this: Like Loading...