Tag Info

Hot answers tagged

351

\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 ...


129

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 ...


47

\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 ...


41

You can use the following tools to do this. All of them are on CTAN but are not part of either TeXLive nor MikTeX, so you 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. latexpand Perl ...


38

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>


38

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 ...


30

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 ...


30

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 ...


21

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> ...


20

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).


20

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 ...


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 ...


16

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 ones like to use \endinput to show the end of file explicitly. IMHO, it make no sence.


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

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} ...


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

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

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


14

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 ...


14

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 mentioned ...


13

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. ...


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

The check if a file exists is not expandable, because the file is opened using \openin\somefilehandle=<filename> which makes an assignment to \somefilehandle. Then \ifeof\somefilehandle is used to check if the end-of-file (EOF) is already reached, which is immediately true for non-existing files. Empty files, I think, need to be read at least once ...


13

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 ...


13

Normally this is done using the listings package. It provides a lstlisting environment for verbatim code and also a \lstinputlisting[<options,...>]{<file name>} to include an external file verbatim. As options you can select language=C++ to get specific syntax highlighting. I also usually use basicstyle=\ttfamily. See the listings package manual ...


13

I did not understand where do you want to put the text: in the main file jobname.aux or in the separate file. If the former, this works (basically modelled after the standard \ref-\label mechanism): \documentclass{article} \makeatletter % The command reference writes \newreference into the aux file \def\createreference#1#2{\@bsphack ...


12

There is as far as I know no way to get around the problem. How TeX handles files with unusual numbers of dots (where "unusual" is any number unequal to 1) is quite inpredictable and also has changed over time. In miktex 2.4 e.g. \input{file.cfg} would have tried at first file.cfg then file.cfg.tex, in miktex 2.5 it tried only file.cfg, in the current 2.9 ...


12

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 ...


12

\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.


12

This is exactly the purpose of the docmute package. Another one with more options is the package and document class standalone.



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