13

I have a file bar.tex that I include in other files.

$ cat bar.tex
hello, world
$ cat foo.tex
\documentclass{article}
\begin{document}
\include{bar.tex}
\end{document}
$ pdflatex foo.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2015/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./foo.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 2 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)) (./foo.aux
(./bar.tex.aux))
No file bar.tex.tex.
(./foo.aux (./bar.tex.aux)) )
No pages of output.
Transcript written on foo.log.

You can see above that pdflatex could not include the file because No file bar.tex.tex. It was looking for bar.tex.tex instead of bar.tex.

Of course the following works fine.

$ cat foo2.tex 
\documentclass{article}
\begin{document}
\include{bar}
\end{document}
$ pdflatex foo2.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2015/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./foo2.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 2 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
No file foo2.aux.
(./bar.tex) [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./foo2.aux
(./bar.aux)) )</usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr
10.pfb>
Output written on foo2.pdf (1 page, 11574 bytes).

But when I use \input instead of \include both bar.tex and bar seem to work.

$ cat foo3.tex 
\documentclass{article}
\begin{document}
\input{bar.tex}
\end{document}
$ pdflatex foo3.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2015/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./foo3.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 2 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
No file foo3.aux.
(./bar.tex) [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./foo3.aux)
 )</usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on foo3.pdf (1 page, 11574 bytes).
Transcript written on foo3.log.
$ cat foo4.tex
\documentclass{article}
\begin{document}
\input{bar}
\end{document}
$ pdflatex foo4.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2015/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./foo4.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 2 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
No file foo4.aux.
(./bar.tex) [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./foo4.aux)
 )</usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on foo4.pdf (1 page, 11574 bytes).
Transcript written on foo4.log.

Why is there this inconsistency between \include and \input, i.e. why \include requires the file to be included to be speicified without the extension name whereas \input does not care whether or not the extension name is specified?

13

There is no inconsistency. The \include command should have an argument that is a file name without extension; this is the documented behavior and is a requirement.

The command is only meant for inputting .tex files in order to do “selective processing” of the material by means of \includeonly.

On the other hand, \input can be used for any kind file (even binaries, if you are bold enough), provided they have an extension, because the default for TeX is to add .tex if an extension is missing (except on some implementations).

So the two commands are very different from each other and are not interchangeable. Ultimately, \include uses \input, but this is not something a user should be concerned with.

  • If both bar and bar.tex exist, then \input{bar} inputs bar.tex. This makes sense as per your answer because you mentioned that the default for TeX is to add .tex if an extension is missing. But when only bar exists and bar.tex is missing, then \input{bar} inputs bar. Why? Where can I read about the rules governing these things? – Lone Learner Jul 15 '16 at 8:58
  • @LoneLearner It really depends on the implementation. One of them might load bar (without extension) if there is no bar.tex available (which is what TeX Live does), another might ignore files without extension. – egreg Jul 15 '16 at 9:17
  • I disagree with this answer. The fact that this behavior is documented doesn't make the inconsistency disappear. And the two commands are replaceable in the most frequent use case. – Federico Poloni Jul 15 '16 at 22:01
  • @FedericoPoloni You're very wrong, sorry; \input doesn't issue a \clearpage command, for instance. Have you ever tried \include{../foo}? Well, if you do, you'll have a surprise. No problem with \input{../foo}, instead. In some restricted cases, the behavior of \include and \input seems to be the same; this is the maximum I can concede. – egreg Jul 15 '16 at 22:15
  • There's no bug as everything is documented, but the fact that one of them has a documented requirement that it should be without extension, and the other is documented that it can be either with or without extension, is obviously and by definition an inconsistency :-) So I don't see why the first sentence is “There is no inconsistency”; at most you can say there is no need or expectation for the two commands to be consistent, because they are so different. – ShreevatsaR Mar 15 at 13:21
5

The clue is in the terminal output that you show.

(./bar.tex.aux)

\include needs to construct the name of an aux file, and in tex if the user requests foo you can not tell if the actual file input is foo or foo.tex so the most reliable way (if you have reliable users) is to document that the file should always have an extension, and the \include argument should not mention the extension. then #1.tex is the document file, and #1.aux is the aux file.

  • 1
    What is different about \input? Why does it not to construct the name of the aux file? – Lone Learner Jul 15 '16 at 8:51
  • @LoneLearner \input just inputs the file, no aux file is involved. – David Carlisle Jul 15 '16 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.