Expanded SCons.Scanner.LaTeX.comment_re to not break on \%
[scons.git] / test / TEX / variant_dir_dup0.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Test creation of a fully-featured TeX document (with bibliography
29 and index) in a variant_dir.
30
31 Also test that the target can be named differently than what
32 Latex produces by default.
33
34 Test courtesy Rob Managan.
35 """
36
37 import TestSCons
38
39 test = TestSCons.TestSCons()
40
41 latex = test.where_is('latex')
42 dvipdf = test.where_is('dvipdf')
43 makeindex = test.where_is('makeindex')
44 bibtex = test.where_is('bibtex')
45 if not latex or not makeindex or not bibtex or not dvipdf:
46     test.skip_test("Could not find 'latex', 'makeindex', 'bibtex', or dvipdf; skipping test.\n")
47
48 test.subdir(['docs'])
49
50
51 test.write(['SConstruct'], """\
52 import os
53
54 env = Environment(ENV = { 'PATH' : os.environ['PATH'] },
55                   TOOLS = ['tex', 'latex', 'dvipdf'])
56 Export(['env'])
57
58 SConscript(os.path.join('docs', 'SConscript'),
59            variant_dir=os.path.join('mybuild','docs'),
60            duplicate=0)
61 """)
62
63
64 test.write(['docs', 'SConscript'], """\
65 Import('env')
66
67 test_dvi = env.DVI(source='test.tex')
68 test2_dvi = env.DVI(target='result',source='test2.tex')
69 testpdf = env.PDF(target='pdfoutput',source=test_dvi)
70 test2pdf = env.PDF(target='pdfoutput.xyz',source=test2_dvi)
71 """)
72
73
74 test.write(['docs', 'Fig1.ps'], """\
75 %!PS-Adobe-2.0 EPSF-2.0
76 %%Title: Fig1.fig
77 %%Creator: fig2dev Version 3.2 Patchlevel 4
78 %%CreationDate: Tue Apr 25 09:56:11 2006
79 %%BoundingBox: 0 0 98 98
80 %%Magnification: 1.0000
81 %%EndComments
82 /$F2psDict 200 dict def
83 $F2psDict begin
84 $F2psDict /mtrx matrix put
85 /col-1 {0 setgray} bind def
86 /col0 {0.000 0.000 0.000 srgb} bind def
87
88 end
89 save
90 newpath 0 98 moveto 0 0 lineto 98 0 lineto 98 98 lineto closepath clip newpath
91 -24.9 108.2 translate
92 1 -1 scale
93
94 /cp {closepath} bind def
95 /ef {eofill} bind def
96 /gr {grestore} bind def
97 /gs {gsave} bind def
98 /rs {restore} bind def
99 /l {lineto} bind def
100 /m {moveto} bind def
101 /rm {rmoveto} bind def
102 /n {newpath} bind def
103 /s {stroke} bind def
104 /slc {setlinecap} bind def
105 /slj {setlinejoin} bind def
106 /slw {setlinewidth} bind def
107 /srgb {setrgbcolor} bind def
108 /sc {scale} bind def
109 /sf {setfont} bind def
110 /scf {scalefont} bind def
111 /tr {translate} bind def
112  /DrawEllipse {
113         /endangle exch def
114         /startangle exch def
115         /yrad exch def
116         /xrad exch def
117         /y exch def
118         /x exch def
119         /savematrix mtrx currentmatrix def
120         x y tr xrad yrad sc 0 0 1 startangle endangle arc
121         closepath
122         savematrix setmatrix
123         } def
124
125 /$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def
126 /$F2psEnd {$F2psEnteredState restore end} def
127
128 $F2psBegin
129 10 setmiterlimit
130  0.06299 0.06299 sc
131 %
132 % Fig objects follow
133
134 7.500 slw
135 % Ellipse
136 n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
137
138 $F2psEnd
139 rs
140 """)
141
142
143 test.write(['docs', 'Fig1.tex'],
144 r"""\begin{picture}(0,0)%
145 \includegraphics{Fig1.ps}%
146 \end{picture}%
147 \setlength{\unitlength}{4144sp}%
148 %
149 \begingroup\makeatletter\ifx\SetFigFont\undefined%
150 \gdef\SetFigFont#1#2#3#4#5{%
151   \reset@font\fontsize{#1}{#2pt}%
152   \fontfamily{#3}\fontseries{#4}\fontshape{#5}%
153   \selectfont}%
154 \fi\endgroup%
155 \begin{picture}(1548,1546)(397,-879)
156 \put(856,-196){\makebox(0,0)[lb]{\smash{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}center $r_0$}%
157 }}}
158 \end{picture}
159 """)
160
161
162 test.write(['docs', 'test.bib'], """\
163 %% This BibTeX bibliography file was created using BibDesk.
164 %% http://bibdesk.sourceforge.net/
165
166 %% Saved with string encoding Western (ASCII) 
167
168 @techreport{AnAuthor:2006fk,
169         Author = {A. N. Author},
170         Date-Added = {2006-11-15 12:51:30 -0800},
171         Date-Modified = {2006-11-15 12:52:35 -0800},
172         Institution = {none},
173         Month = {November},
174         Title = {A Test Paper},
175         Year = {2006}}
176 """)
177
178
179 test.write(['docs', 'test.tex'],
180 r"""\documentclass{report}
181
182 \usepackage{graphicx}
183 \usepackage{epsfig,color} % for .tex version of figures if we go that way
184
185 \usepackage{makeidx}
186 \makeindex
187
188 \begin{document}
189  
190 \title{Report Title}
191
192 \author{A. N. Author}
193  
194 \maketitle 
195  
196 \begin{abstract}
197 there is no abstract
198 \end{abstract}
199
200 \tableofcontents
201 \listoffigures
202
203 \chapter{Introduction}
204
205 The introduction is short.
206
207 \index{Acknowledgements}
208
209 \section{Acknowledgements}
210
211 The Acknowledgements are show as well \cite{AnAuthor:2006fk}.  
212
213 \index{Getting the Report}
214
215 To get a hard copy of this report call me.
216
217 \begin{figure}[htbp]
218 \begin{center}
219 \input{Fig1.tex} % testing figure variant that uses TeX labeling
220 \caption{Zone and Node indexing}
221 \label{fig1}
222 \end{center}
223 \end{figure}
224
225 All done now.
226
227 \bibliographystyle{unsrt}
228 \bibliography{test}
229 \newpage
230
231 \printindex
232
233 \end{document}
234 """)
235
236 test.write(['docs', 'test2.tex'],
237 r"""\documentclass{report}
238
239 \usepackage{graphicx}
240 \usepackage{epsfig,color} % for .tex version of figures if we go that way
241
242 \usepackage{makeidx}
243 \makeindex
244
245 \begin{document}
246  
247 \title{Report Title}
248
249 \author{A. N. Author}
250  
251 \maketitle 
252  
253 \begin{abstract}
254 there is no abstract
255 \end{abstract}
256
257 \tableofcontents
258 \listoffigures
259
260 \chapter{Introduction}
261
262 The introduction is short.
263
264 \index{Acknowledgements}
265
266 \section{Acknowledgements}
267
268 The Acknowledgements are show as well \cite{AnAuthor:2006fk}.  
269
270 \index{Getting the Report}
271
272 To get a hard copy of this report call me.
273
274 \begin{figure}[htbp]
275 \begin{center}
276 \input{Fig1.tex} % testing figure variant that uses TeX labeling
277 \caption{Zone and Node indexing}
278 \label{fig1}
279 \end{center}
280 \end{figure}
281
282 All done now.
283
284 \bibliographystyle{unsrt}
285 \bibliography{test}
286 \newpage
287
288 \printindex
289
290 \end{document}
291 """)
292
293
294 # makeindex will write status messages to stderr (grrr...), so ignore it.
295 test.run(arguments = '.', stderr=None)
296
297
298 # All (?) the files we expect will get created in the variant_dir
299 # (mybuild/docs) and not in the srcdir (docs).
300 files = [
301     'test.aux',
302     'test.bbl',
303     'test.blg',
304     'test.dvi',
305     'test.idx',
306     'test.ilg',
307     'test.ind',
308     'test.lof',
309     'test.log',
310     'test.toc',
311     'test2.aux',
312     'test2.bbl',
313     'test2.blg',
314     'test2.idx',
315     'test2.ilg',
316     'test2.ind',
317     'test2.lof',
318     'test2.log',
319     'test2.toc',
320     'result.dvi',
321     'pdfoutput.pdf',
322     'pdfoutput.xyz'
323 ]
324
325 for f in files:
326     test.must_exist(['mybuild', 'docs', f])
327     test.must_not_exist(['docs', f])
328
329
330 test.pass_test()
331
332 # Local Variables:
333 # tab-width:4
334 # indent-tabs-mode:nil
335 # End:
336 # vim: set expandtab tabstop=4 shiftwidth=4: