Tag Info

Hot answers tagged

289

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


105

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


44

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


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


35

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>


33

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


29

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


26

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


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


19

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


17

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


15

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.


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

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


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

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


12

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

Here's how it goes in texlive (and presumably other web2c distros): The changefile tex.ch removes the Knuth definition of input_ln; The underscore gets lost in the conversion of web to c; The resulting C code #includes texmfmp.h which does #define inputln(stream, flag) input_line (stream) The function input_line() gets defined in texmfmp.c where the ...


12

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


12

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


12

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


12

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


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

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


11

Without a \read: \documentclass{article} \usepackage{catchfile} \newcommand{\setcounterfromfile}[2]{% #1 = counter, #2 = file name \CatchFileDef{\scfftemp}{#2}{\endlinechar=-1 }% \setcounter{#1}{\scfftemp}} \newcounter{cnt} \setcounterfromfile{cnt}{numberfile} \showthe\value{cnt} If numberfile.tex contains the only line 12345 (a very difficult ...


11

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


11

In TeX Live, the formats for pdf(la)tex and lua(la)tex are built loading the tcx translation file cp227.tcx that makes ^^I "printable". This means that a category code 12 ^^I is written out as a real tab character. On the other hand, xetex ignores tcx translation requests and behaves, in this respect, like Knuth's TeX (but it writes UTF-8, of course). A ...


11

It's easy to see where the loop comes from as \Bigr is defined in terms of \Big which is (by default) \def\Big#1{{\hbox{$\left#1\vbox to11.5\p@{}\right.\n@space$}}} so defined in terms of \left It is probably safer just to do a replace/edit on the incoming file If you wanted to do this in TeX you'd neeed \let\oldleft\left \let\oldright\right and ...



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