Rabu, 01 Januari 2025

Difference Between Input And Include

The Latex \input Command

Syntax:
\input{filename}

where filename is the name of the LaTeX file (with or without the .tex extension) that contains the content to be inserted. This way, we can insert text, equations, or images (latexeps, pdf, png, jpeg, jpg).

For example,

let’s say we have a section in the file section1.tex:
\section{My First Section}
In a hole in the ground there lived a hobbit.

We can insert its content into our main document using \input:

\begin{document}
\input{section1} 
\end{document}

Additionally, we can use \input in our document’s preamble. In that case, the included file should contain only the commands that are allowed to be in a preamble.

The \include Command

The \include command can be used to insert larger pieces of content such as chapters or major sections into a LaTeX document. We can use it for both figures and texts. Its syntax is the same as that of \input:

\include{filename}
For example, let’s say we have three chapters. We can keep each chapter in its own file and compile the entire book by including them with \include:

\begin{document}
\include{chapter1}
\include{chapter2}
\include{chapter3}
\end{document}
  • The \include command starts a new .aux file for each included file and also adds a page break to the document before inserting a file. The included file will start a new page before processing the \include command.
  • So, we can use it only between \begin{document} and \end{document}. We can’t use it in the preamble.

Sameness Between \input and \include

  • The LaTeX file name must use dash line or underscore line to replace the whitespace.
  • The LaTeX file name (with or without the .tex extension)
  • You can provide relative or absolute paths to the files.

Different Between \input, \include And \includeonly Package

\input

  • We can use it anywhere in a document
  • Suitable for inserting small things where a page break isn’t required
  • You can nest \input macros.
  • You don’t get the cross-reference, bibliography benefit.

\include

  • Can only be used between \begin{document} and \end{document}
  • The included file will start a new page before processing the \include command. when a page break is not required
  • Suitable for large documents pieces of content (such as chapters or major sections) where page breaks are required
  • You can't nest \include files.

\includeonly

  • It must appear in the preamble or even earlier, e.g., the command line
  • You have to specify the names separated by commas with no intervening spaces. (e.g. \includeonly{firstbit,lastbit} )
  • The \include and \includeonly must in pair is very useful for working on long documents.

Bibliography

https://ctan.org/
https://www.overleaf.com/
https://latexref.xyz/ 
https://www.baeldung.com/
https://www.wikitechy.com/
https://www.medunigraz.at/ (university) 
https://www.mq.edu.au/ (university)

Tidak ada komentar:

Posting Komentar