summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/dtk/dtk-extern.sty
blob: 29d8672b70ead3191f202fbe2ecf240726361c60 (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
%% This is file `dtk-extern.sty',
%%
%% LaTeX package for ``Die TeXnische Komoedie''.
%%
%% Copyright (C) 2016-
%% Rolf Niepraschk, Herbert Voss
%%
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% 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.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.

\ProvidesFile{dtk-extern}%
  [2017/06/04 v0.06: dtk package for running external documents (HV)]

\RequirePackage{shellesc,filecontents,xkeyval,graphicx}

\newcounter{dtk@extern@runs}
\define@key{dtk}{compiler}[pdflatex]{\def\dtk@extern@compiler{#1}}
\define@key{dtk}{runsequence}[]{\def\dtk@extern@runsequence{#1}}
\define@key{dtk}{runs}[1]{\setcounter{dtk@extern@runs}{#1}}
\define@key{dtk}{grfOptions}[]{\def\dtk@extern@grfOptions{#1}}
\define@key{dtk}{lstOptions}[]{\def\dtk@extern@lstOptions{#1}}
\define@key{dtk}{docType}[latex]{\def\dtk@extern@docType{#1}}
\define@key{dtk}{caption}[]{\def\dtk@extern@caption{#1}}
\define@key{dtk}{label}[]{\def\dtk@extern@label{#1}}
\define@key{dtk}{pages}[1]{\def\dtk@extern@pages{#1}}
\define@boolkey{dtk}[dtk@extern@]{code}[true]{}
\define@boolkey{dtk}[dtk@extern@]{force}[true]{}
\define@boolkey{dtk}[dtk@extern@]{crop}[true]{}
\define@boolkey{dtk}[dtk@extern@]{biber}[true]{}
\define@boolkey{dtk}[dtk@extern@]{includegraphic}[true]{}
\define@boolkey{dtk}[dtk@extern@]{frame}[true]{}
\define@boolkey{dtk}[dtk@extern@]{float}[true]{}
\define@boolkey{dtk}[dtk@extern@]{cleanup}[true]{}

\def\ResetKeys{%
 \setkeys{dtk}{
  code=false,%          show Code
  crop=false,%		erzeugte PDF "croppen"
  compiler=pdflatex,%	zu verwendener Compiler
  grfOptions={},%	Optionen der einzubindenden Grafik
  lstOptions={},%	Optionen für das Listing
  includegraphic=true,% Grafik einbinden oder User überlassen
  runs=1,%		Anzahl Compiler-Durchläufe
  runsequence={},%	Im Moment nicht aktiv
  biber=false,%		Biber laufen lassen?
  force=false,%		Compiler, auch wenn PDF existiert?
  frame=false,%		keinen Rahmen um Abbildung
  float=false,%		nicht als Gleitumgebung
  caption=,%	        keine Caption
  label=,%		kein Label
  pages=1,%		welche Seiten auszugeben sind
  docType=latex,%	LaTeX example Code
  cleanup=false,%	Hilfsdateien nicht löschen
  }
}
\ResetKeys

{\catcode`\%=12 
 \gdef\perCent{%}
 \gdef\DoubleperCent{%%}
}

\newcommand\ExampleType[5]{%
   \@namedef{#1@initText}{linerange=#2-#3,includerangemarker=false}% text
   \@namedef{#1@initPreamble}{linerange=#4-#5,includerangemarker=false}% code
}

\ExampleType{latex}%               #1
  {begin\string{document\string}}%       #2
  {end\string{document\string}}%         #3
  {\perCent StartVisiblePreamble}% #4
  {\perCent StopVisiblePreamble}%  #5

\ExampleType{context}
  {\string\starttext}
  {\string\stoptext}
  {\perCent StartVisiblePreamble}
  {\perCent StopVisiblePreamble}

%%
%% [#1]: Optionen  #2: Dateiname
%%
\newenvironment{ErstelleGrafik}[2][]
  {\global\setkeys{dtk}{#1}%                   \begin
     \gdef\dtk@extern@dateiname{#2}%
   \begingroup
   \@nameuse{filecontents*}{#2.tex}
  }
  {\@nameuse{endfilecontents*}%         \end
   \endgroup
   \loop\ifnum\thedtk@extern@runs>0
     \typeout{Run: \thedtk@extern@runs\space \dtk@extern@compiler\space\dtk@extern@dateiname}%
     \ShellEscape{\dtk@extern@compiler\space\dtk@extern@dateiname}%
     \addtocounter{dtk@extern@runs}{-1}%
   \repeat
   \ifdtk@extern@code
      \expandafter\edef\expandafter\dtk@lst@options@preamble\expandafter{%
        \@nameuse{\dtk@extern@docType @initPreamble},
        \dtk@extern@lstOptions,
        backgroundcolor=\noexpand\color{black!12}}%
      \expandafter\lstinputlisting\expandafter[\dtk@lst@options@preamble]{\dtk@extern@dateiname}
%     
      \expandafter\edef\expandafter\dtk@lst@options@text\expandafter{%
        \@nameuse{\dtk@extern@docType @initText},
        \dtk@extern@lstOptions,
        backgroundcolor=\noexpand\color{black!8}}%
      \typeout{\dtk@lst@options@text}
      \expandafter\lstinputlisting\expandafter[\dtk@lst@options@text]{\dtk@extern@dateiname}
   \fi
   \expandafter\IfFileExists\expandafter{\dtk@extern@dateiname.pdf}%
     {\ifdtk@extern@force
        \ifdtk@extern@biber
          \ShellEscape{biber  \dtk@extern@dateiname}%  NAch biber nochmal latex
          \ShellEscape{\dtk@extern@compiler\space\dtk@extern@dateiname}%
        \fi
        \ifdtk@extern@crop
          \ShellEscape{pdfcrop \dtk@extern@dateiname}%
          \ShellEscape{mv \dtk@extern@dateiname-crop.pdf \dtk@extern@dateiname.pdf}%
        \fi
      \fi
     }{}
   \ifdtk@extern@includegraphic
     \ifdtk@extern@float\begin{figure}[!htb]\centering\fi
     \ifdtk@extern@frame
       \expandafter\@for\expandafter\next\expandafter:\expandafter=\dtk@extern@pages\do{%
          \fbox{\expandafter\includegraphics\expandafter[\dtk@extern@grfOptions,page=\next]{\dtk@extern@dateiname}}%
              \hspace{5pt}}\hspace*{-5pt}
%   \fbox{\expandafter\includegraphics\expandafter[\dtk@extern@grfOptions]{\dtk@extern@dateiname}}%
     \else
       \expandafter\@for\expandafter\next\expandafter:\expandafter=\dtk@extern@pages\do{%
          \expandafter\includegraphics\expandafter[\dtk@extern@grfOptions,page=\next]{\dtk@extern@dateiname}%
              \hspace{5pt}}\hspace*{-5pt}
%       \expandafter\includegraphics\expandafter[\dtk@extern@grfOptions]{\dtk@extern@dateiname}%
     \fi
     \ifx\dtk@extern@caption\@empty\else\caption{\dtk@extern@caption}\fi
     \ifx\dtk@extern@label\@empty\else\label{\dtk@extern@label}\fi
     \ifdtk@extern@float\end{figure}\fi
   \fi
   \ifdtk@extern@cleanup
      \ShellEscape{rm \dtk@extern@dateiname.log}%
      \ShellEscape{rm \dtk@extern@dateiname.aux}%
      \ShellEscape{rm \dtk@extern@dateiname.toc}%
%      \ShellEscape{rm \dtk@extern@dateiname.log}%
   \fi
   \global\ResetKeys}
%
\let\externalDocument\ErstelleGrafik
\let\endexternalDocument\endErstelleGrafik
%%
\endinput