Debian Codegraph @

texmf-dist/source/latex/inversepath/inversepath.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright 2007-2008 by Will Robertson <[email protected]>
4 %
5 % Distributable under the LaTeX Project Public License,
6 % version 1.3c or higher (your choice). The latest version of
7 % this license is at: http://www.latex-project.org/lppl.txt
8 %
9 % This work is "maintained" (as per LPPL maintenance status)
10 % by Will Robertson.
11 %
12 % This work consists of the file inversepath.dtx
13 % and the derived files inversepath.sty and inversepath.pdf.
14 %
15 %
16 %<*internalbatchfile>
17 \begingroup
18 %</internalbatchfile>
19 %<*batchfile>
20 \input docstrip.tex
21 \keepsilent
22 \preamble
23
24 _______________________________________
25 Copyright (C) 2007-2008 Will Robertson
26
27 License information appended.
28
29
30 \endpreamble
31 \postamble
32
33 Copyright (C) 2007-2008 by Will Robertson <[email protected]>
34
35 Distributable under the LaTeX Project Public License,
36 version 1.3c or higher (your choice). The latest version of
37 this license is at: http://www.latex-project.org/lppl.txt
38
39 This work is "maintained" (as per LPPL maintenance status)
40 by Will Robertson.
41
42 This work consists of the file \jobname.dtx
43 and the derived files \jobname.sty and \jobname.pdf.
44
45 \endpostamble
46 \askforoverwritefalse
47 \generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
48 %</batchfile>
49 %<batchfile>\endbatchfile
50 %<*internalbatchfile>
51 \generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
52 \nopreamble\nopostamble
53 \generate{\file{README.txt}{\from{\jobname.dtx}{readme}}}
54 \generate{\file{dtx-style.sty}{\from{\jobname.dtx}{dtx-style}}}
55 \endgroup
56 \immediate\write18{mv README.txt README}
57 \immediate\write18{makeindex -s gind.ist -o \jobname.ind \jobname.idx}
58 \immediate\write18{makeindex -s gglo.ist -o \jobname.gls \jobname.glo}
59 %</internalbatchfile>
60 %
61 %<*driver>
62 \documentclass{ltxdoc}
63 \EnableCrossrefs
64 \CodelineIndex
65 \RecordChanges
66 %\OnlyDescription
67 \usepackage{dtx-style}
68 \begin{document}
69 \DocInput{\jobname.dtx}
70 \end{document}
71 %</driver>
72 %
73 %<*readme>
74 _______________________
75 The INVERSEPATH package
76 v0.2
77
78 Calculate inverse relative paths in LaTeX. E.g., from
79 "/one/two/three.tex" or "/one/two/" to "../../".
80 Could be easily converted to Plain TeX if I wasn't lazy.
81
82 ______________
83 Will Robertson
84 2007-2008
85 %</readme>
86 %
87 % \fi
88 %
89 % \GetFileInfo{\jobname.sty}
90 % \CheckSum{0}
91 % \makeatletter
92 %
93 % \title{Relative inverse path calculation}
94 % \author{Will Robertson}
95 % \date{\filedate \qquad \fileversion}
96 %
97 % \maketitle
98 %
99 % \noindent
100 % \pkg{inversepath} is a simple package to calculate inverse relative paths.
101 % For example, when writing to an auxiliary file in a subdirectory
102 % (or a series of nested subdirectories), it can be useful to know
103 % how to get back to the original file.
104 %
105 % If the absolute path of the original file is specified, this package
106 % can also calculate the relative path of a file in parent or sibling
107 % directories.
108 %
109 % \bigskip
110 % {\centering\noindent
111 % \cmd\inversepath\marg{path} --- prints the inverse of \meta{path}.\par}
112 % {\centering\noindent
113 % \cmd{\inversepath*}\marg{path} --- calculates the inverse of \meta{path}.\par}
114 %
115 % \bigskip
116 % {\raggedleft\noindent
117 % \cmd\absolutepath\marg{abs.\ path} --- specifies the absolute
118 % path for calculating parent/sibling relative paths.\par}
119 %
120 % \noindent Regular usage:
121 % \begin{example}{}
122 % \inversepath*{one/two/three/four.tex}\par
123 % \ip@inversepath\par
124 % \ip@lastelement\par
125 % \ip@directpath
126 % \end{example}
127 %
128 % \noindent Expands to \meta{empty} if the relative path is the same directory:
129 % \begin{example}{}
130 % [\inversepath*{one.tex}]\par
131 % \ip@inversepath\par
132 % \ip@lastelement\par
133 % [\ip@directpath]
134 % \end{example}
135 %
136 % \noindent For `back-relative' paths, the absolute path needs to be specified:
137 % \begin{example}{}
138 % \absolutepath{/xyz/here/there/everywhere/}
139 %
140 % \inversepath*{../../one/two/three.tex}\par
141 % \ip@inversepath\par
142 % \ip@lastelement\par
143 % \ip@directpath
144 % \end{example}
145 %
146 %
147 % \StopEventually{}
148 %
149 % \part{\pkg{\jobname} implementation}
150 %\iffalse
151 %<*package>
152 %\fi
153 % This is the package.
154 % \begin{macrocode}
155 \ProvidesPackage{inversepath}
156 [2008/07/31 v0.2 Inverse relative paths]
157 % \end{macrocode}
158 % \begin{macro}{\inversepath}
159 % \darg{Path to invert}
160 % \begin{macrocode}
161 \newcommand\inversepath{%
162 \@ifstar{\inversepath@star}{\inversepath@nostar}}
163 \newcommand\inversepath@star[1]{%
164 % \end{macrocode}
165 % \cmd\ip@jobpath\ is preserved to restore after truncation for
166 % back-relative paths.
167 % \begin{macrocode}
168 \let\ip@origjobpath\ip@jobpath
169 \let\ip@directpath\@empty
170 \let\ip@inversepath\@empty
171 \ip@strippath#1/\@nil/%
172 \let\ip@jobpath\ip@origjobpath}
173 \newcommand\inversepath@nostar[1]{%
174 \inversepath@star{#1}%
175 \let\ip@jobpath\ip@origjobpath}
176 % \end{macrocode}
177 % \changes{v0.2}{2008/07/31}{Starred form to not print the output. What was I thinking?}
178 % \end{macro}
179 % \begin{macro}{\absolutepath}
180 % \darg{Absolute path used for calculating parent/sibling relative paths.}
181 % \begin{macrocode}
182 % macro to define the absolute path of where we are:
183 \newcommand\absolutepath[1]{\def\ip@jobpath{#1}}
184 % \end{macrocode}
185 % \end{macro}
186 % For \cs{ifx} comparisons for relative back-paths:
187 % \begin{macrocode}
188 \def\ip@literaldotdot{..}
189 % \end{macrocode}
190 % \begin{macro}{\ip@strippath}
191 % This is the macro that does all the work.
192 % It takes input like |a/b/c/...x/y/z/\@nil/| and
193 % expands to \cmd\ip@inversepath, the inverse path of \cmd\ip@directpath\
194 % (|a/b/.../y/|).
195 % \begin{macrocode}
196 \def\ip@strippath#1/#2/{%
197 \ifx\@nil#2\relax
198 % \end{macrocode}
199 % If input is |z/\@nil/| then we've reached the end:
200 % \begin{macrocode}
201 \def\ip@lastelement{#1}%
202 \else
203 % \end{macrocode}
204 % If we're in the middle of the slash-separated list;
205 % build up \cmd\ip@directpath:
206 % \begin{macrocode}
207 \edef\ip@directpath{\ip@directpath#1/}
208 \def\@tempa{#1}%
209 \ifx\@tempa\ip@literaldotdot
210 \unless\ifdefined\ip@jobpath
211 \PackageError{inversepath}
212 {No absolute path specified}
213 {You must declare the file path of the main
214 file with \protect\absolutepath{} to be able to
215 resolve back-relative paths}%
216 \fi
217 % \end{macrocode}
218 % If the path is a back-relative path, things are more complex.
219 % to get the inverse of |../|, we need the absolute file path.
220 % this requires using \cmd\ip@strippath\ on \cmd\ip@jobpath\ itself, so save out
221 % our current definitions of \cmd\ip@directpath/\cmd\ip@inversepath\ and
222 % (re-)initialise them:
223 % \begin{macrocode}
224 \let\ip@olddirectpath\ip@directpath
225 \let\ip@oldinversepath\ip@inversepath
226 \let\ip@directpath\@empty
227 \let\ip@inversepath\@empty
228 % \end{macrocode}
229 % \cmd\ip@strippath on \cmd\ip@jobpath\ gives us the topmost directory in
230 % \cmd\ip@lastelement:
231 % \begin{macrocode}
232 \expandafter\ip@strippath\ip@jobpath\@nil/
233 \let\@tempa\ip@lastelement
234 % \end{macrocode}
235 % \cmd\ip@jobpath is now truncated so \cmd\iplastelement\ in the next
236 % iteration is one folder up the hierarchy.
237 % \begin{macrocode}
238 \let\ip@jobpath\ip@directpath
239 % \end{macrocode}
240 % Now we restore everything to how it was: (this would be better
241 % with grouping, but I don't want to use \cmd\global)
242 % \begin{macrocode}
243 \let\ip@directpath\ip@olddirectpath
244 \let\ip@inversepath\ip@oldinversepath
245 % \end{macrocode}
246 % Build up the inverse path:
247 % \begin{macrocode}
248 \ifx\@tempa\@empty
249 \PackageError{inversepath}
250 {Absolute path too shallow to resolve
251 such a deep relative path}
252 {You're trying to go back more directories than you have!}
253 \fi
254 \edef\ip@inversepath{\@tempa/\ip@inversepath}%
255 \else
256 % \end{macrocode}
257 % If the path is a simple relative path,
258 % then build up the inverse path by prepending |../|:
259 % \begin{macrocode}
260 \edef\ip@inversepath{../\ip@inversepath}%
261 \fi
262 % \end{macrocode}
263 % Iterate:
264 % \begin{macrocode}
265 \def\@tempa{\ip@strippath#2/}%
266 \expandafter\@tempa
267 \fi}
268 % \end{macrocode}
269 % \end{macro}
270 %
271 %\iffalse
272 %</package>
273 %\fi
274 %
275 %
276 %\iffalse
277 %<*dtx-style>
278 % \begin{macrocode}
279 \ProvidesPackage{dtx-style}
280
281 \errorcontextlines=999
282
283 \def\@dotsep{1000}
284 \setcounter{tocdepth}{2}
285 \setlength\columnseprule{0.4pt}
286 \renewcommand\tableofcontents{\relax
287 \begin{multicols}{2}[\section*{\contentsname}]\relax
288 \@starttoc{toc}\relax
289 \end{multicols}}
290
291 \setcounter{IndexColumns}{2}
292 \renewenvironment{theglossary}
293 {\small\list{}{}
294 \item\relax
295 \glossary@prologue\GlossaryParms
296 \let\item\@idxitem \ignorespaces
297 \def\pfill{\hspace*{\fill}}}
298 {\endlist}
299
300 \usepackage[svgnames]{xcolor}
301 \usepackage{amsmath,array,bm,booktabs,calc,enumitem,fancyvrb,graphicx,ifthen,longtable,refstyle,subfig,topcapt,varioref,\jobname,url}
302
303 \usepackage[sc,osf]{mathpazo}
304
305 \linespread{1.069} % A bit more space between lines
306 \frenchspacing % Remove ugly extra space after punctuation
307
308 \definecolor{niceblue}{rgb}{0.2,0.4,0.8}
309 \newenvironment{example}[1]
310 {\VerbatimEnvironment
311 \def\Options{#1}%
312 \begin{VerbatimOut}[gobble=2]{\examplefilename}}
313 {\end{VerbatimOut}\relax
314 \typesetexample}
315
316 \fvset{formatcom=\color{niceblue}}
317 \DefineShortVerb{\|}
318
319 \def\theCodelineNo{\textcolor{niceblue}{\sffamily\tiny\arabic{CodelineNo}}}
320
321 \let\examplesize\normalsize
322 \let\auxwidth\relax
323
324 \newlength\examplewidth\newlength\verbatimwidth
325 \newlength\exoutdent \newlength\exverbgap
326 \setlength\exverbgap{1em}
327 \setlength\exoutdent{-0.15\textwidth}
328 \newsavebox\verbatimbox
329 \edef\examplefilename{\jobname.example}
330
331 \newcommand\typesetexample{\relax
332 \smallskip
333 \noindent
334 \begin{minipage}{\linewidth}
335 \color{niceblue}
336 \hrulefill\par
337 \edef\@tempa{[gobble=0,fontsize=\noexpand\small,\Options]}%
338 \begin{lrbox}{\verbatimbox}\relax
339 \expandafter\BVerbatimInput\@tempa{\examplefilename}%
340 \end{lrbox}
341 \begin{list}{}{\setlength\itemindent{0pt}
342 \setlength\leftmargin\exoutdent
343 \setlength\rightmargin{0pt}}\item
344 \ifx\auxwidth\relax
345 \setlength\verbatimwidth{\wd\verbatimbox}%
346 \else
347 \setlength\verbatimwidth{\auxwidth}%
348 \fi
349 \begin{minipage}[c]{\textwidth-\exoutdent-\verbatimwidth-\exverbgap}
350 \catcode`\%=14\centering\linespread{1.6}\input\examplefilename\relax
351 \end{minipage}\hfill
352 \begin{minipage}[c]{\verbatimwidth}
353 \usebox\verbatimbox
354 \end{minipage}
355 \end{list}
356 \par\noindent\hrulefill
357 \end{minipage}
358 \smallskip}
359
360 \newcommand*\setverbwidth[1]{\def\auxwidth{#1}}
361
362 \newcommand*\name[1]{{#1}}
363 \newcommand*\pkg[1]{\textsf{#1}}
364 \newcommand*\feat[1]{\texttt{#1}}
365 \newcommand*\opt[1]{\texttt{#1}}
366
367 \newcommand*\note[1]{\unskip\footnote{#1}}
368
369 \let\latin\textit
370 \def\eg{\latin{e.g.}}
371 \def\Eg{\latin{E.g.}}
372 \def\ie{\latin{i.e.}}
373 \def\etc{\@ifnextchar.{\latin{etc}}{\latin{etc.}\@}}
374
375 \def\STIX{\textsc{stix}}
376 \def\MacOSX{Mac~OS~X}
377 \def\ascii{\textsc{ascii}}
378 \def\OMEGA{Omega}
379 \def\CTAN{\textsc{ctan}}
380
381 \newcounter{argument}
382 \g@addto@macro\endmacro{\setcounter{argument}{0}}
383 \newcommand*\darg[1]{%
384 \stepcounter{argument}%
385 {\ttfamily\char`\#\theargument~:~}#1\par\noindent\ignorespaces}
386 \newcommand*\doarg[1]{%
387 \stepcounter{argument}%
388 {\ttfamily\makebox[0pt][r]{[}\char`\#\theargument]:~}#1\par\noindent\ignorespaces}
389
390 \def\codeline{\par\hspace{2\parindent}}
391
392 \newcommand\unichar[2]{\textsc{\MakeLowercase{u+#1: #2}}}
393
394 \setlength\parindent{2em}
395
396 % \end{macrocode}
397 %</dtx-style>
398 %\fi
399 %
400 % \typeout{*************************************************************}
401 % \typeout{*}
402 % \typeout{* To finish the installation you have to move the following}
403 % \typeout{* file into a directory searched by XeTeX:}
404 % \typeout{*}
405 % \typeout{* \space\space\space inversepath.sty}
406 % \typeout{*}
407 % \typeout{*************************************************************}
408 %
409 \endinput