1

I'm using the elsarticle document class with the draft option enabled. I thought that the draft mode would skip the files imported with the \input{} command as well but it is not the case. I use the \input{} command for TikZ pictures and tables stored in separate files.

I've found a workaround by using the ifdraft package but I think the draft mode should skip \input{} lines as well automatically.

Is this behavior a bug or feature?

Is there an easier workaround than including the \ifdraft command before every \input{} command?

Edit after comments:

It would be enough for me if the \input command does not fail compilation when the importable file does not exist. Meaning, I want to reduce its error to a warning. Is it possible?

6
  • 4
    No, that's the intended behaviour. Ultimately, \input is used to read in any external files to your document, so with \input disabled, not even packages would be included. TikZ has a external library, which allows the separate compilation of pictures and then you can conditionally include them Feb 2, 2020 at 18:16
  • 1
    the main effect of draft mode is to mark overfull lines with a rule, it has no effect on \input, Feb 2, 2020 at 18:25
  • @PhelypeOleinik, thank you, I was not aware of how low-level the \input command is. It alters my question a little bit. Probably I will use the suggested tikz library as well.
    – Mathiassa
    Feb 2, 2020 at 18:43
  • 1
    @Mathiassa Yes, \input is one of the (two) TeX primitives for reading files, although LaTeX adds a few things on top of the primitive, like checking if the file exists and keeping track of a input file stack. You definitely don't want to change this one ;-) Feb 2, 2020 at 18:48
  • 1
    for your edit, replace \input{zzz} by \InputIfFileExists{zzzz}{}{} Feb 2, 2020 at 19:12

1 Answer 1

2

Use the external TikZ library instead. With that library, each tikzpicture is compiled in a separate LaTeX run (you need to compile with -shell-escape) and then a generated PDF file of that picture is included. The example document below takes 2 s in the first run, and then 0.3 s in the next runs. Also, since the draft option is used and the picture is an external PDF file, the picture inclusion is skipped and the usual box appears instead.

Without draft:

enter image description here

With draft:

enter image description here

\documentclass[draft]{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}

hello
\begin{tikzpicture}
  \foreach \i in {1,...,1000}
    \node at (0,0) {picture that takes a long time to compile};
\end{tikzpicture}
bye

\end{document}

As for your update, LaTeX's input is roughly:

\InputIfFileExists{file}%
  {}% do nothing if the file exists
  {\ERROR{file does not exist}}

so you can just define a \myinput:

\newcommand\myinput[1]{%
  \InputIfFileExists{#1}%
    {}% do nothing if the file exists
    {\PackageWarning{Mathiassa}{File '#1' not found.}}%
  }

And if you are feeling bold and want \input to behave like that, instead of defining \myinput, you can redefine \@iinput (the LaTeX macro which takes care of doing that).

You must log in to answer this question.

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