summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/inversepath/inversepath.dtx
blob: 61d617fe5dcc5f259e497b560577778562c245d7 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
% \iffalse meta-comment
%
% Copyright 2007 by Will Robertson <wspr81@gmail.com>
% 
% Distributable under the LaTeX Project Public License,
% version 1.3c or higher (your choice). The latest version of
% this license is at: http://www.latex-project.org/lppl.txt
%
% This work is "maintained" (as per LPPL maintenance status) 
% by Will Robertson.
% 
% This work consists of the file  inversepath.dtx
%           and the derived files inversepath.sty and inversepath.pdf.
%
%
%<*internalbatchfile>
\begingroup
%</internalbatchfile>
%<*batchfile>
\input docstrip.tex
\keepsilent
\preamble

  __________________________________
  Copyright (C) 2007  Will Robertson

  License information appended.


\endpreamble
\postamble

Copyright (C) 2006 by Will Robertson <wspr81@gmail.com>

Distributable under the LaTeX Project Public License,
version 1.3c or higher (your choice). The latest version of
this license is at: http://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) 
by Will Robertson.

This work consists of the file  \jobname.dtx
          and the derived files \jobname.sty and \jobname.pdf.

\endpostamble
\askforoverwritefalse
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
%</batchfile>
%<batchfile>\endbatchfile
%<*internalbatchfile>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
\nopreamble\nopostamble
\generate{\file{README.txt}{\from{\jobname.dtx}{readme}}}
\generate{\file{dtx-style.sty}{\from{\jobname.dtx}{dtx-style}}}
\endgroup
\immediate\write18{mv README.txt README}
\immediate\write18{makeindex -s gind.ist -o \jobname.ind  \jobname.idx}
\immediate\write18{makeindex -s gglo.ist -o \jobname.gls  \jobname.glo}
%</internalbatchfile>
%
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
\usepackage{dtx-style}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
%
%<*readme>
_______________________
The INVERSEPATH package
v0.1

Calculate inverse relative paths in LaTeX. E.g., from 
"/one/two/three.tex" or "/one/two/" to "../../". 
Could be easily converted to Plain TeX if I wasn't lazy.

______________
Will Robertson
2007
%</readme>
%
% \fi
%
% \GetFileInfo{\jobname.sty}
% \CheckSum{0}
% \makeatletter
%
% \title{Relative inverse path calculation}
% \author{Will Robertson}
% \date{\filedate \qquad \fileversion}
%
% \maketitle
%
% \noindent
% \pkg{inversepath} is a simple package to calculate inverse relative paths.
% For example, when writing to an auxiliary file in a subdirectory
% (or a series of nested subdirectories), it can be useful to know
% how to get back to the original file.
%
% If the absolute path of the original file is specified, this package
% can also calculate the relative path of a file in parent or sibling
% directories.
%
% \bigskip
% {\centering\noindent
% \cmd\inversepath\marg{path} --- expands to the inverse of \meta{path}.\par}
%
% \bigskip
% {\raggedleft\noindent
% \cmd\absolutepath\marg{abs.\ path} --- specifies the absolute
% path for calculating parent/sibling relative paths.\par}
%
% \noindent Regular usage:
% \begin{example}{}
% \inversepath{one/two/three/four.tex}\par
% \ip@lastelement\par
% \ip@directpath
% \end{example}
% 
% \noindent Expands to \meta{empty} if the relative path is the same directory:
% \begin{example}{}
% [\inversepath{one.tex}]\par
% \ip@lastelement\par
% [\ip@directpath]
% \end{example}
%
% \noindent For `back-relative' paths, the absolute path needs to be specified:
% \begin{example}{}
% \absolutepath{/xyz/here/there/everywhere/}
%
% \inversepath{../../one/two/three.tex}\par
% \ip@lastelement\par
% \ip@directpath
% \end{example}
%
% \noindent That's it!
%
% \StopEventually{}
%
% \part{\pkg{\jobname} implementation}
%\iffalse
%<*package>
%\fi
% This is the package.
%    \begin{macrocode}
\ProvidesPackage{inversepath}
  [26/04/2007 v0.1 Inverse relative paths]
%    \end{macrocode}
% \begin{macro}{\inversepath}
% \darg{Path to invert}
%    \begin{macrocode}
\newcommand\inversepath[1]{%  
%    \end{macrocode}
% \cmd\ip@jobpath\ is preserved to restore after truncation for
% back-relative paths.
%    \begin{macrocode}
  \let\ip@origjobpath\ip@jobpath
  \let\ip@directpath\@empty
  \let\ip@inversepath\@empty
  \ip@strippath#1/\@nil/%
  \let\ip@jobpath\ip@origjobpath
  \ip@inversepath}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\absolutepath}
% \darg{Absolute path used for calculating parent/sibling relative paths.}
%    \begin{macrocode}
% macro to define the absolute path of where we are:
\newcommand\absolutepath[1]{\def\ip@jobpath{#1}}
%    \end{macrocode}
% \end{macro}
% For \cs{ifx} comparisons for relative back-paths:
%    \begin{macrocode}
\def\ip@literaldotdot{..}
%    \end{macrocode}
% \begin{macro}{\ip@strippath}
% This is the macro that does all the work.
% It takes input like |a/b/c/...x/y/z/\@nil/| and
% expands to \cmd\ip@inversepath, the inverse path of \cmd\ip@directpath\
% (|a/b/.../y/|).
%    \begin{macrocode}
\def\ip@strippath#1/#2/{%
  \ifx\@nil#2\relax
%    \end{macrocode}
% If input is |z/\@nil/| then we've reached the end:
%    \begin{macrocode}    
    \def\ip@lastelement{#1}%
  \else
%    \end{macrocode}
% If we're in the middle of the slash-separated list;
% build up \cmd\ip@directpath:
%    \begin{macrocode}    
    \edef\ip@directpath{\ip@directpath#1/}
    \def\@tempa{#1}%
    \ifx\@tempa\ip@literaldotdot
      \unless\ifdefined\ip@jobpath
        \PackageError{inversepath}
          {No absolute path specified}
          {You must declare the file path of the main 
           file with \protect\absolutepath{} to be able to 
           resolve back-relative paths}%
      \fi
%    \end{macrocode}
% If the path is a back-relative path, things are more complex.
% to get the inverse of |../|, we need the absolute file path.
% this requires using \cmd\ip@strippath\ on \cmd\ip@jobpath\ itself, so save out
% our current definitions of \cmd\ip@directpath/\cmd\ip@inversepath\ and
% (re-)initialise them:
%    \begin{macrocode}
      \let\ip@olddirectpath\ip@directpath
      \let\ip@oldinversepath\ip@inversepath
      \let\ip@directpath\@empty
      \let\ip@inversepath\@empty
%    \end{macrocode}
% \cmd\ip@strippath on \cmd\ip@jobpath\ gives us the topmost directory in
% \cmd\ip@lastelement:
%    \begin{macrocode}
      \expandafter\ip@strippath\ip@jobpath\@nil/
      \let\@tempa\ip@lastelement
%    \end{macrocode}
% \cmd\ip@jobpath is now truncated so \cmd\iplastelement\ in the next
% iteration is one folder up the hierarchy.
%    \begin{macrocode}
      \let\ip@jobpath\ip@directpath
%    \end{macrocode}
% Now we restore everything to how it was: (this would be better
% with grouping, but I don't want to use \cmd\global)
%    \begin{macrocode}
      \let\ip@directpath\ip@olddirectpath
      \let\ip@inversepath\ip@oldinversepath
%    \end{macrocode}
% Build up the inverse path:
%    \begin{macrocode}
      \ifx\@tempa\@empty
        \PackageError{inversepath}
          {Absolute path too shallow to resolve 
            such a deep relative path}
          {You're trying to go back more directories than you have!}
      \fi
      \edef\ip@inversepath{\@tempa/\ip@inversepath}%
    \else
%    \end{macrocode}
% If the path is a simple relative path, 
% then build up the inverse path by prepending |../|:
%    \begin{macrocode}
      \edef\ip@inversepath{../\ip@inversepath}%
    \fi
%    \end{macrocode}
% Iterate:
%    \begin{macrocode}
    \def\@tempa{\ip@strippath#2/}%
    \expandafter\@tempa
  \fi}
%    \end{macrocode}
% \end{macro}
%
%\iffalse
%</package>
%\fi
%
%
%\iffalse
%<*dtx-style>
%    \begin{macrocode}
\ProvidesPackage{dtx-style}

\errorcontextlines=999

\def\@dotsep{1000}
\setcounter{tocdepth}{2}
\setlength\columnseprule{0.4pt}
\renewcommand\tableofcontents{\relax
  \begin{multicols}{2}[\section*{\contentsname}]\relax
    \@starttoc{toc}\relax
  \end{multicols}}

\setcounter{IndexColumns}{2}
\renewenvironment{theglossary}
  {\small\list{}{}
     \item\relax
     \glossary@prologue\GlossaryParms 
     \let\item\@idxitem \ignorespaces 
     \def\pfill{\hspace*{\fill}}}
  {\endlist}

\usepackage[svgnames]{xcolor}
\usepackage{amsmath,array,bm,booktabs,calc,enumitem,fancyvrb,graphicx,ifthen,longtable,refstyle,subfig,topcapt,varioref,\jobname,url}

\usepackage[sc,osf]{mathpazo}

\linespread{1.069}      % A bit more space between lines
\frenchspacing         % Remove ugly extra space after punctuation
  
\definecolor{niceblue}{rgb}{0.2,0.4,0.8}
\newenvironment{example}[1]
  {\VerbatimEnvironment
   \def\Options{#1}%
   \begin{VerbatimOut}[gobble=2]{\examplefilename}}
  {\end{VerbatimOut}\relax
   \typesetexample}

\fvset{formatcom=\color{niceblue}}
\DefineShortVerb{\|}

\def\theCodelineNo{\textcolor{niceblue}{\sffamily\tiny\arabic{CodelineNo}}}

\let\examplesize\normalsize
\let\auxwidth\relax

\newlength\examplewidth\newlength\verbatimwidth
\newlength\exoutdent   \newlength\exverbgap
\setlength\exverbgap{1em}
\setlength\exoutdent{-0.15\textwidth}
\newsavebox\verbatimbox
\edef\examplefilename{\jobname.example}

\newcommand\typesetexample{\relax
   \smallskip
   \noindent
   \begin{minipage}{\linewidth}
   \color{niceblue}
   \hrulefill\par
   \edef\@tempa{[gobble=0,fontsize=\noexpand\small,\Options]}%
   \begin{lrbox}{\verbatimbox}\relax
     \expandafter\BVerbatimInput\@tempa{\examplefilename}%
   \end{lrbox}
   \begin{list}{}{\setlength\itemindent{0pt}
                  \setlength\leftmargin\exoutdent
                  \setlength\rightmargin{0pt}}\item
   \ifx\auxwidth\relax
     \setlength\verbatimwidth{\wd\verbatimbox}%
   \else
     \setlength\verbatimwidth{\auxwidth}%
   \fi
   \begin{minipage}[c]{\textwidth-\exoutdent-\verbatimwidth-\exverbgap}
     \catcode`\%=14\centering\linespread{1.6}\input\examplefilename\relax
   \end{minipage}\hfill
   \begin{minipage}[c]{\verbatimwidth}
     \usebox\verbatimbox
   \end{minipage}
   \end{list}
   \par\noindent\hrulefill
   \end{minipage}
   \smallskip}

\newcommand*\setverbwidth[1]{\def\auxwidth{#1}}

\newcommand*\name[1]{{#1}}
\newcommand*\pkg[1]{\textsf{#1}}
\newcommand*\feat[1]{\texttt{#1}}
\newcommand*\opt[1]{\texttt{#1}}

\newcommand*\note[1]{\unskip\footnote{#1}}

\let\latin\textit
\def\eg{\latin{e.g.}}
\def\Eg{\latin{E.g.}}
\def\ie{\latin{i.e.}}
\def\etc{\@ifnextchar.{\latin{etc}}{\latin{etc.}\@}}

\def\STIX{\textsc{stix}}
\def\MacOSX{Mac~OS~X}
\def\ascii{\textsc{ascii}}
\def\OMEGA{Omega}
\def\CTAN{\textsc{ctan}}

\newcounter{argument}
\g@addto@macro\endmacro{\setcounter{argument}{0}}
\newcommand*\darg[1]{%
  \stepcounter{argument}%
  {\ttfamily\char`\#\theargument~:~}#1\par\noindent\ignorespaces}
\newcommand*\doarg[1]{%
  \stepcounter{argument}%
  {\ttfamily\makebox[0pt][r]{[}\char`\#\theargument]:~}#1\par\noindent\ignorespaces}

\def\codeline{\par\hspace{2\parindent}}

\newcommand\unichar[2]{\textsc{\MakeLowercase{u+#1: #2}}}

\setlength\parindent{2em}

%    \end{macrocode}
%</dtx-style>
%\fi
%
% \typeout{*************************************************************}
% \typeout{*}
% \typeout{* To finish the installation you have to move the following}
% \typeout{* file into a directory searched by XeTeX:}
% \typeout{*}
% \typeout{* \space\space\space inversepath.sty}
% \typeout{*}
% \typeout{*************************************************************}
%
\endinput