summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/import/import.tex
blob: afa323d504a929b369719d33a0779d86b27882ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
\documentclass[DIV=8, parskip=half, pagesize=auto]{scrartcl}

\usepackage{fixltx2e}
\usepackage{etex}
\usepackage{xspace}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{booktabs}
\usepackage{microtype}
\usepackage{hyperref}

\newcommand*{\mail}[1]{\href{mailto:#1}{\texttt{#1}}}
\newcommand*{\pkg}[1]{\textsf{#1}}
\newcommand*{\cls}[1]{\textsf{#1}}
\newcommand*{\cs}[1]{\texttt{\textbackslash#1}}
\makeatletter
\newcommand*{\cmd}[1]{\cs{\expandafter\@gobble\string#1}}
\makeatother
\newcommand*{\env}[1]{\texttt{#1}}
\newcommand*{\opt}[1]{\texttt{#1}}
\newcommand*{\meta}[1]{\textlangle\textsl{#1}\textrangle}
\newcommand*{\marg}[1]{\texttt{\{}\meta{#1}\texttt{\}}}
\newcommand*{\oarg}[1]{\texttt{[}\meta{#1}\texttt{]}}
\newcommand*{\BibTeX}{Bib\kern-0.08em\TeX\@\xspace}
\newcommand*{\BigTeX}{Big\kern-0.08em\TeX\@\xspace}

\pdfstringdefDisableCommands{%
  \def\BibTeX{BibTeX\xspace}%
  \def\BigTeX{BigTeX\space}%
}

\addtokomafont{title}{\rmfamily}

\title{The \pkg{import} package\thanks{This manual corresponds to \pkg{import}~v5.1, dated~23--Mar--2009.}}
\author{Donald Arseneau  (\mail{asnd@triumf.ca})}
\date{23--Mar--2009}


\begin{document}

\maketitle

This software is in the public domain; free of any restrictions.

Two new \LaTeX\ commands, ``\cmd{\import}\marg{full\_path}\marg{file}''\\ and
``\cmd{\subimport}\-\marg{path\_extension}\marg{file}'' are defined to input a file 
from another directory, allowing that file to find its own inputs
(using ``\cmd{\input}'', ``\cmd{\includegraphics}'' etc.)\ in that directory.

Alias command names are ``\cmd{\inputfrom}'' and ``\cmd{\subinputfrom}''.

Also provided are ``\cmd{\includefrom}'' and ``\cmd{\subincludefrom}'', which are
based on the ``\cmd{\include}'' command, rather than ``\cmd{\input}''.  There are
also ``\texttt{*}'' variants described below.

For example, if a remote file ``\texttt{/usr5/friend/work/report.tex}'' has contents:
%
\begin{verbatim}
My graph: \includegraphics{picture}
\input{explanation}
\end{verbatim}
%
then you can safely input that file in your own document with the command
``\verb+\import{/usr5/friend/work/}{report}+''; the explanation and picture will 
be taken from the ``\texttt{/usr5/friend/work/}'' directory.

The ``\cmd{\subimport}'' command takes a relative path instead of a full absolute
file path, and it allows imported files to import files themselves, using
their own directory as the root of another ``\meta{path\_extension}''. Do not use
both ``\cmd{\import}'' and ``\cmd{\subimport}'' in the same file.

For example, if a file is imported (using either command) from directory
``\texttt{abc/}'' and that file contains the command ``\verb+\subimport{lmn/}{xyz}+'' then
file ``\texttt{abc/lmn/xyz.tex}'' is input, and any ``\cmd{\input}'' commands in that file
will read files from directory ``\texttt{abc/lmn/}''. 

Note that the sub-import path is merely appended to the current import
path.  Mistakes from this method must be rectified by ``\cmd{\import@path@fix}''.

Depending on on how your \TeX\ system is configured, if a file with the 
same name as the import file exists in the current directory or in the 
\texttt{TEXINPUTS} path, that other file will be read in preference to one in the 
import directory.  So here is the real behavior of the previous example:
Given the sequence ``\verb+\import{abc/}{one}+'', ``\verb+\subimport{lmn/uvw/}{two}+'' (in
file \texttt{one}), ``\verb+\input{three}+'' (in file \texttt{two}), \LaTeX\ first looks for \texttt{three.tex}
in the \texttt{TEXINPUTS} search path; if not found, it tries ``\texttt{abc/lmn/uvw/three}'';
if that doesn't exist, it tries ``\texttt{abc/three}''; if still not found, it tries
the defined ``\cmd{\input@path}'', if there is one.

To avoid searching the \texttt{TEXINPUTS} path when importing files, use the `star'
versions of the commands: ``\cmd{\import*}'' and ``\cmd{\subimport*}''.

A hook ``\cmd{\import@path@fix}'' is provided to reformat the import path
to fit the syntax of a particular operating system.  It \emph{could} be
defined to convert unix-style path names to the local format, but 
all it does now is remove ``\texttt{][}'' from VMS sub-import directories.

Presently, the paths are defined ``locally'' so input files must have 
balanced grouping.

\end{document}