Hot answers tagged

513

\input{filename} imports the commands from filename into the target file; it's equivalent to typing all the commands from filename right into the current file where the \input line is \include{filename} essentially does a \clearpage before and after \input{filename}, together with some magic to switch to another .aux file, and omit the inclusion at all if ...


180

Short answer: \input is a more lower level macro which simply inputs the content of the given file like it was copy&pasted there manually. \include handles the file content as a logical unit of its own (like e.g. a chapter) and enables you to only include specific files using \includeonly{filename,filename2,...} to save times. Long answer: The ...


64

\input effectively replaces the command with the contents of the input file. \input's can be nested. So, you can write: \documentclass{article} \begin{document} AAA \input{b} AAA \end{document} where b.tex is: BBB \input{c} BBB and c.tex is: CCC to get output like: AAA BBB CCC BBB AAA include triggers a newpage both before and after the ...


55

You can use the following tools to do this. All of them are on CTAN but not all of them are part of either TeXLive or MikTeX, so you may need to manually install them. They need either Perl or a C compiler installed. Both should not be a problem with Linux but might be one under Windows or Mac. However IIRC TeXLive installs its own Perl interpreter. ...


46

Manuel has posted an answer that uses line numbers; there's a recent package on CTAN that lets you do it with tags in the input file: catchfilebetweentags. An example is \usepackage{catchfilebetweentags} ... \ExecuteMetaData[file.tex]{tag} where the contents of the external file is surrounded by the "tags": %<*tag> ... %</tag>


42

Edit: There is now LaTeX package for testing https://github.com/michal-h21/odsfile Before I post it on CTAN, any comments on style/grammar/spell in the documentation files, as well comments on the source code, are highly welcome. There is solution using luatex's zip library and pure lua xml processing library LuaXML, which you should install to same ...


39

From the LaTeX Wikibook : When working on big documents, you might want to split the input file into several parts. LaTeX has three commands to insert a file into another when building the document. The simplest is the \input command: \input{filename} \input inserts the contents of another file, named filename.tex; note that the ...


36

I'm fuzzy on the details, but the import package should do what you want. Off the top of my head, I think the syntax is \usepackage{import} ... \subimport{code/doc/latex/}{refman.tex} Update: Thanks Willie for pointing out \subimport which seems to be the better command to use here over \import. The commands \import{full_path}{file} and ...


31

Here's a case where \endinput might be useful. Suppose I'm writing a textbook and that each chapter ends with problems followed by their solutions. I want to build two separate editions: one for students, without solutions, one for teachers, with solutions. I can define a conditional, say \ifstudent, and prepare my chapters as <text> ...


29

The snapshot package gives you a list of the external dependencies of a LaTeX document. Use it by saying \RequirePackage{snapshot} before the \documentclass command (to have the information written to a .dep file), or by saying \RequirePackage[log]{snapshot} before the \documentclass command (to have the information written to the .log file).


27

\graphicspath comes from LaTeX's \input@path, just using the paths for graphics files. \input@path can be set independently, e.g.: \makeatletter \def\input@path{{path1/}{path2/}} \makeatother Internally package graphics stores its path of \graphicspath in \Ginput@path and locally sets \input@path to \Ginput@path, if it looks for files via \IfFileExists. ...


24

No, you don't need it. \endinput is used for terminating the input process in the middle of a file. A \endinput at the end of a file is useless (and harmless). Some people like to use \endinput to show the end of file explicitly. IMHO, it make no sense.


21

Advantages It is a good trick, if someone wants to put TeX code before. Examples: pdflatex '\def\foo{bar}\input{filename}' pdflatex '\includeonly{introduction}\input{filename}' or inside \write18 (shell escape feature): \immediate\write18{\detokenize{pdflatex '\def\foo{bar}\input{filename}'}} \immediate\write18{\detokenize{pdflatex ...


20

You can define the internal macro \input@path to hold a list of base directories: \makeatletter \def\input@path{{/path/to/folder/}} %or: \def\input@path{{/path/to/folder/}{/path/to/other/folder/}} \makeatother Then you can use \input{fileinthatfolder} everywhere. It also works for \includegraphics IIRC. But I don't think this is supported by the ...


18

TestInput.out probably contains a new line at the end of the file (text files usually do, even when created with echo 'abc' > file). TeX interprets new lines as spaces. To remove that space, simply add \unskip directly afterwards, i.e. use A\input{TestInput.out}\unskip B (this will also remove any intentional space at the end of the file, should there ...


18

The best thing is probably to leave out the document preamble and the \begin{document} and \end{document} from the included files and have one master file that sets up the style. Master file: \documentclass{article} % preamble. \begin{document} \input{file1} \input{file2} \end{document} First included file: \section{Blah} % more stuff. ...


17

My suggestion is to create one file with all the \input lines automatically and use \input to include this file (and hence, all desired files) into your main document. The best way to keep everything up to date would be a Makefile. On a Unix system you can use this command line to create the file with the input lines: ls dir/*.tex | awk '{printf ...


17

In addition to listings, the fancyvrb package is equally suitable for this purpose. This package provides the \VerbatimInput command (similar to \verbatiminput), which can be customised using various parameters (e.g., reducing font size). \documentclass{article} \usepackage[dvipsnames]{xcolor} \usepackage{fancyvrb} % redefine \VerbatimInput ...


16

So I had one answer (which is preserved below for posterity) but I think I understand the question a little better now. What you want is to write \input{foo} and have LaTeX know where to search for foo. Martin's answer offers one way to do this. Here are some others. One way is to make a directory in your local texmf tree and put files you want to use in ...


16

Here is an approach in pure TeX (well, e-TeX). The main idea is: to select a range of lines in a file, sed is overkill, TeX is more than enough. As a bonus, no temporary file is needed. \documentclass[a4paper]{article} \usepackage[ascii]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \makeatletter \newread\pin@file \newcounter{pinlineno} ...


16

TeX only processes the input line by line, so there is a limit on the number of characters in a line, but not on the total size of the file. Your editor however probably does need to read the entire file into memory so may have limits on the file size. The editor I use warns if the file is more than 10MB but will open files larger than that, up to the ...


15

One way is to use \read which reads a file a line at a time \documentclass{article} \newcounter{cnt} \newread\myread \openin\myread=numberfile \begin{document} \read \myread to \zz \setcounter{cnt}{\zz} \arabic{cnt} \end{document} assuming numberfile.tex looks like 33


15

You could split every report into two files: a main file holding only the preamble and an \input as document body, and a second file holding all the actual content. Then you are able to \input or \include all the content files in another main file for the book. % Main file of one report, e.g. `report01.tex` \documentclass{report} \title{...} ...


15

Use the package import, which does exactly one thing: to solve this problem. See http://www.ctan.org/pkg/import Basically the package defines two commands: \import and \subimport. \import needs an absolute path, while subimport needs a relative path. They both look at the current folder and TEXINPUTS first. If you want to avoid checking TEXINPUTS, use ...


15

This is what has been working great for me for about two years now. create a .sty file containing your universal preamble. A .sty file, basically, is a regular TeX file starting with \ProvidesPackage{mystyle}, ending with \endinput, and everything else inbetween.*) in your Dropbox (or similar), create a directory named texmf-local, and a subdirectory such ...


14

You can read the content of a file into a macro with Heiko Oberdiek's catchfile package: \CatchFileDef{\sometext}{somefile.txt}{<setup>} This will read the file like a normal TeX file, i.e. it can include macros etc. The <setup> argument can be empty for files read normally but can include special code to e.g. read the file content verbatim or ...


14

You could use package bashful to do it from within LaTeX, e.g., using gniourf_gniourf suggestion, you would write \documentclass{minimal} \usepackage{bashful} \begin{document} \bash[stdoutFile=inputs.tex] { shopt -s nullglob; for file in dir/*.tex; do echo "\\input{$file}"; done; } \END \input{inputs.tex} \end{document}


14

I replaced your if-if-if-if construct with a simple \ifcase test. \moon works just fine now. Though the actual problem was another one. The counter assignments \global\advance\<counter> by 1 should be finished with a \relax. This also applies to the \ifnum but in this instance, it is not needed as math-mode is introduces right away. Without the \relax ...


13

The LaTeX \input command, by Lamport's choice, must support both \input{file} and \input file so it's necessary to define it in that way: a test on the following character is necessary as the primitive \input scans its argument in a very peculiar way. If you don't want to support the original syntax inside your environment, then putting ...


13

\input is trying to be intelligent, and this seems to be upsetting LaTeX's picky tabular definition. But you can access the original \input primitive from TeX which is less dangerous at this point. After defining \makeatletter \newcommand\primitiveinput[1] {\@@input #1 } \makeatother using \primitiveinput inside the tabular should work.



Only top voted, non community-wiki answers of a minimum length are eligible