From a16c89d7793f3f99757220e4becd13e5eea7d37b Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 26 Feb 2020 22:10:12 +0000 Subject: import (26feb20) git-svn-id: svn://tug.org/texlive/trunk@53932 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/import/import.sty | 94 ++++++++++++++++----------- 1 file changed, 56 insertions(+), 38 deletions(-) (limited to 'Master/texmf-dist/tex/latex/import') diff --git a/Master/texmf-dist/tex/latex/import/import.sty b/Master/texmf-dist/tex/latex/import/import.sty index cce424c46ad..338fcc2b1cb 100644 --- a/Master/texmf-dist/tex/latex/import/import.sty +++ b/Master/texmf-dist/tex/latex/import/import.sty @@ -1,63 +1,48 @@ -% import.sty Ver 5.1 23-Mar-2009 Donald Arseneau (asnd@triumf.ca) +% import.sty Ver 6.0 22-Jan-2020 Donald Arseneau (asnd@triumf.ca) % % This software is in the public domain; free of any restrictions. % -% Two new \LaTeX\ commands, "\import {full_path} {file}" and -% "\subimport {path_extension} {file}" are defined to input a file +% Two new \LaTeX\ commands, "\import {} {}" and +% "\subimport {} {}" are defined to input a file % from another directory, allowing that file to find its own inputs % (using "\input", "\includegraphics" etc.) in that directory. -% % Alias command names are "\inputfrom" and "\subinputfrom". % % Also provided are "\includefrom" and "\subincludefrom", which are -% based on the "\include" command, rather than "\input". There are -% also "*" variants described below. +% based on the "\include" command, rather than "\input". % -% For example, if a remote file "/usr5/friend/work/report.tex" has contents: +% For example, if a remote file "/user/friend/work/report.tex" has contents: % % My graph: \includegraphics{picture} % \input{explanation} % % then you can safely input that file in your own document with the command -% "\import{/usr5/friend/work/}{report}"; the explanation and picture will -% be taken from the "/usr5/friend/work/" directory. +% "\import{/user/friend/work/}{report}"; the explanation and picture will +% be taken from the "/user/friend/work/" directory. % -% The "\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 "path_extension". Do not use -% both "\import" and "\subimport" in the same file. +% The argument for "\import" can be a full absolute path +% or a relative path starting from the main working directory for the document. +% The "\subimport" command facilitates nesting of file imports. It takes a +% relative based on the location of the current file. % % For example, if a file is imported (using either command) from directory % "abc/" and that file contains the command "\subimport{lmn/}{xyz}" then % file "abc/lmn/xyz.tex" is input, and any "\input" commands in that file -% will read files from directory "abc/lmn/". +% will read files from directory "abc/lmn/". % -% Note that the sub-import path is merely appended to the current import -% path. Mistakes from this method must be rectified by "\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 -% 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 "\import{abc/}{one}", "\subimport{lmn/uvw/}{two}" (in -% file one), "\input{three}" (in file two), \LaTeX\ first looks for three.tex -% in the TEXINPUTS search path; if not found, it tries "abc/lmn/uvw/three"; -% if that doesn't exist, it tries "abc/three"; if still not found, it tries -% the defined "\input@path", if there is one. -% -% To avoid searching the TEXINPUTS path when importing files, use the `star' -% versions of the commands: "\import*" and "\subimport*". +% Find more documentation in import.tex or import.pdf. % % A hook "\import@path@fix" is provided to reformat the import path % to fit the syntax of a particular operating system. It *could* be -% defined to convert unix-style path names to the local format, but -% all it does now is remove "][" from VMS sub-import directories. +% defined to convert unix-style path names to the local format. The default +% definition ensures paths end with "/" on most systems, but removes +% "][" from within sub-import directory paths on VMS systems. % % Presently, the paths are defined ``locally'' so input files must have % balanced grouping. %====================== END INSTRUCTIONS =========================== -\ProvidesPackage{import}[2009/03/23 \space v 5.1] +\ProvidesPackage{import}[2020/01/22 \space v 6.0] \ProcessOptions \@ifundefined{import}{% @@ -72,8 +57,9 @@ \newcommand{\includefrom}{\global\let\import@path\@empty \@doimport\include} \newcommand{\subincludefrom}{\@doimport\include} +% Consume now-meaningless "*" \def\@doimport#1{\@ifstar - {\@sub@import#1\@iffileonpath}{\@sub@import#1\IfFileExists}} + {\@sub@import#1\im@iffileexists}{\@sub@import#1\im@iffileexists}} % #1 = import command, #2 = switch for *, #3 = import path extension \def\@sub@import#1#2#3{% @@ -94,22 +80,54 @@ % #6 = previous \IfFileExists. #7 = file name. % \def\@import#1#2#3#4#5#6#7{% - \gdef\import@path{#4}% - \protected@edef\input@path{{\import@path@fix{#4}}#2}% - \protected@edef\Ginput@path{{\import@path@fix{#4}}#3}% - #1{#7}% + \protected@xdef\import@path{\import@path@fix{#4}}% + \protected@edef\input@path{{\import@path}#2}% + \protected@edef\Ginput@path{{\import@path}#3}% + \protected@edef\import@path@file{% use full path/file for non-* + \ifx\IfFileExists\@iffileonpath\else \import@path\fi #7}% +% + \expandafter#1\expandafter{\import@path@file}% +% \let\IfFileExists#6% restore after \import* \gdef\import@path{#5}% \def\input@path{#2}\ifx\input@path\@empty \let\input@path\@undefined \fi \def\Ginput@path{#3}\ifx\Ginput@path\@empty \let\Ginput@path\@undefined \fi } +% Our version of \IfFileExists that gives priority to files on \input@path, +% #1 = file name, #2 = action when exists, #3 = action when not exists +\long\def \im@iffileexists#1#2#3{% + \let\@filef@und\@undefined + \ifx\input@path\@undefined\else + \@iffileonpath{#1}{% (also defines \@filef@und) + \def\reserved@a{#2}% + }{}% no action yet for not found + \fi + \ifx\@filef@und\@undefined % not found on \input@path + \openin\@inputcheck#1 % + \ifeof\@inputcheck + \def\reserved@a{#3}% + \else + \closein\@inputcheck + \edef\@filef@und{#1 }% + \def\reserved@a{#2}% + \fi\fi + \reserved@a +} + \let\im@@IfFileExists\IfFileExists \gdef\import@path{} \let\import@path@fix\@firstofone % default -% Check for vms file names and set \import@path@fix appropriately +% Check for "./" currdir, and make \import@path@fix ensure trailing / +\gdef\@gtempa{./} +\ifx\@gtempa\@currdir % *x style paths + \gdef\import@path@fix#1{\@ensure@one@trailing@slash#1////\delimiter}% + \gdef\@ensure@one@trailing@slash#1////#2\delimiter{#1/}% +\fi + +% Check for "[]" currdir (VMS file names) and set \import@path@fix appropriately \gdef\@gtempa{[]} \ifx\@gtempa\@currdir % VMS directory syntax \gdef\import@path@fix#1{\@gobbleVMSbrack#1][>} -- cgit v1.2.3