summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/verbatimcopy/verbatimcopy.sty
blob: d495d865bc7b0b0b64292c93570c5a0a542eee82 (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
\ProvidesPackage{verbatimcopy}[2007/05/10 v0.03 by Lars Madsen]


% This package be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Lars Madsen (daleif@imf.au.dk).
%%

\RequirePackage{verbatim}


% addition by Ulrich Diez, automatically adds a trailing /
\@ifdefinable\@setOutputDir{%
  \def\@setOutputDir#1/\@nil#2\@nil/{%
    \ifx\@nil#2\@nil
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi
  }%
}%
\newcommand\setOutputDir[1]{%
  \@setOutputDir#1\@nil/\@nil\@nil/%
  {\def\VC@outputdir{#1/}}%
  {\def\VC@outputdir{#1}}%
}%

% memoir defines this one, verbatim does not
\@ifundefined{verbatim@out}{\newwrite\verbatim@out}{}


% the following is basically based on an idea 
% by Ulrich Diez on comp.text.tex
% (http://groups.google.com/group/comp.text.tex/msg/153e3dc7a8d0e548?hl=en&) 

% be very carefull, this will overwrite without asking

% the idea is simply to mess with \verbatiminput such that it write
% instead of read
\newcommand*\VerbatimCopy[2]{% {from file}{to file}
  \edef\VC@target{\VC@outputdir#2}%
   \@bsphack
   \IfFileExists{#1}%
   {%
     \bgroup
     \def\@verbatim{%
       \obeylines
       \let\do\@makeother
       \dospecials
     }%
     \let\endtrivlist\relax
     \def\verbatim@processline{%
       \immediate\write\verbatim@out{\the\verbatim@line}%
     }%
     \immediate\openout\verbatim@out\VC@target\relax
     \verbatiminput{#1}%
     \immediate\closeout\verbatim@out%
     \egroup%
   }%
   {%
     \PackageError{verbatimcopy}%
     {Source-file cannot be found}%
     {%
       For copying source-file to target-file it would be nice to
       have the source-file available.%
     }%
   }%
   \@esphack
}%