Expanded SCons.Scanner.LaTeX.comment_re to not break on \%
[scons.git] / test / TEX / multiple_include_subdir.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 Tex document with nested includes in a 
29 subdir that needs to create a fig.pdf.
30
31 Test courtesy Rob Managan.
32 """
33
34 import TestSCons
35
36 test = TestSCons.TestSCons()
37
38 latex = test.where_is('latex')
39 epstopdf = test.where_is('epstopdf')
40 if not latex:
41     test.skip_test("Could not find 'latex'; skipping test.\n")
42
43 if not epstopdf:
44     test.skip_test("Could not find 'epstopdf'; skipping test.\n")
45
46 test.subdir(['docs'])
47
48
49 test.write(['SConstruct'], """\
50 import os
51
52 env = Environment(ENV = { 'PATH' : os.environ['PATH'] })
53
54 env.PDF('docs/Fig1.eps')
55 test = env.PDF(source='docs/test.tex')
56 """)
57
58
59 test.write(['docs','Fig1.eps'], """\
60 %!PS-Adobe-2.0 EPSF-2.0
61 %%Title: Fig1.fig
62 %%Creator: fig2dev Version 3.2 Patchlevel 4
63 %%CreationDate: Tue Apr 25 09:56:11 2006
64 %%For: managan@mangrove.llnl.gov (Rob Managan)
65 %%BoundingBox: 0 0 98 98
66 %%Magnification: 1.0000
67 %%EndComments
68 /$F2psDict 200 dict def
69 $F2psDict begin
70 $F2psDict /mtrx matrix put
71 /col-1 {0 setgray} bind def
72 /col0 {0.000 0.000 0.000 srgb} bind def
73
74 end
75 save
76 newpath 0 98 moveto 0 0 lineto 98 0 lineto 98 98 lineto closepath clip newpath
77 -24.9 108.2 translate
78 1 -1 scale
79
80 /cp {closepath} bind def
81 /ef {eofill} bind def
82 /gr {grestore} bind def
83 /gs {gsave} bind defThe Oxygen Isotopic Composition of Captured Solar Wind: First Results\rfrom the GENESIS Mission
84 /rs {restore} bind def
85 /l {lineto} bind def
86 /m {moveto} bind def
87 /rm {rmoveto} bind def
88 /n {newpath} bind def
89 /s {stroke} bind def
90 /slc {setlinecap} bind def
91 /slj {setlinejoin} bind def
92 /slw {setlinewidth} bind def
93 /srgb {setrgbcolor} bind def
94 /sc {scale} bind def
95 /sf {setfont} bind def
96 /scf {scalefont} bind def
97 /tr {translate} bind def
98  /DrawEllipse {
99         /endangle exch def
100         /startangle exch def
101         /yrad exch def
102         /xrad exch def
103         /y exch def
104         /x exch def
105         /savematrix mtrx currentmatrix def
106         x y tr xrad yrad sc 0 0 1 startangle endangle arc
107         closepath
108         savematrix setmatrix
109         } def
110
111 /$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def
112 /$F2psEnd {$F2psEnteredState restore end} def
113
114 $F2psBegin
115 10 setmiterlimit
116  0.06299 0.06299 sc
117 %
118 % Fig objects follow
119
120 7.500 slw
121 % Ellipse
122 n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
123
124 $F2psEnd
125 rs
126 """)
127
128
129 test.write(['docs','Fig1.tex'],
130 r"""\begin{picture}(0,0)%
131 \includegraphics{Fig1}%
132 \end{picture}%
133 \setlength{\unitlength}{4144sp}%
134 %
135 \begingroup\makeatletter\ifx\SetFigFont\undefined%
136 \gdef\SetFigFont#1#2#3#4#5{%
137   \reset@font\fontsize{#1}{#2pt}%
138   \fontfamily{#3}\fontseries{#4}\fontshape{#5}%
139   \selectfont}%
140 \fi\endgroup%
141 \begin{picture}(1548,1546)(397,-879)
142 \put(856,-196){\makebox(0,0)[lb]{\smash{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}center $r_0$}%
143 }}}
144 \end{picture}
145 """)
146
147
148 test.write(['docs','test.tex'],
149 r"""\documentclass{report}
150
151 \usepackage{graphicx}
152 \usepackage{epsfig,color} % for .tex version of figures if we go that way
153
154 \usepackage{makeidx}
155 \makeindex
156
157 \begin{document}
158  
159 \title{Report Title}
160
161 \author{A. N. Author}
162  
163 \maketitle 
164  
165 \begin{abstract}
166 there is no abstract
167 \end{abstract}
168
169 \tableofcontents
170 \listoffigures
171
172 \chapter{Introduction}
173
174 The introduction is short.
175
176 \index{Acknowledgements}
177
178 \section{Acknowledgements}
179
180 The Acknowledgements are shown as well.  
181
182 \index{Getting the Report}
183
184 \input{getReport}
185
186 \end{document}
187 """)
188
189 test.write(['docs','getReport.tex'],
190 r"""
191 To get a hard copy of this report call me.
192
193 \begin{figure}[htbp]
194 \begin{center}
195 \input{Fig1.tex} % testing figure variant that uses TeX labeling
196 \caption{Zone and Node indexing}
197 \label{fig1}
198 \end{center}
199 \end{figure}
200
201 All done now.
202
203 %\bibliographystyle{unsrt}
204 %\bibliography{test}
205 \newpage
206
207 \printindex
208 """)
209
210 # makeindex will write status messages to stderr (grrr...), so ignore it.
211 test.run(arguments = '.', stderr=None)
212
213
214 # All (?) the files we expect will get created in the subdir
215 # (mybuild/docs) and not in the srcdir (docs).
216 files = [
217     'docs/test.aux',
218     'docs/test.idx',
219     'docs/test.ilg',
220     'docs/test.ind',
221     'docs/test.lof',
222     'docs/test.log',
223     'docs/test.pdf',
224     'docs/test.toc',
225     'docs/Fig1.pdf'
226 ]
227
228 for f in files:
229     test.must_exist([ f])
230
231
232 test.pass_test()
233
234 # Local Variables:
235 # tab-width:4
236 # indent-tabs-mode:nil
237 # End:
238 # vim: set expandtab tabstop=4 shiftwidth=4: