anchors fix
[p5sagit/p5-mst-13.2.git] / lib / Pod / t / latex.t
CommitLineData
43c344fe 1
2BEGIN {
3 chdir 't' if -d 't';
4 @INC = '../lib';
5 require Test; import Test;
6 plan(tests => 154);
7}
8
9# Test that Pod::LaTeX works
10# This test relies on the DATA filehandle
11# DATA contains the latex that is used for comparison
12# and the pod that was used to generate it. The two
13# are separated by '=pod'
14# Note that if the translator is adjusted the output tex
15# will probably not match what is currently there. You
16# will need to adjust it to match (assuming it is correct).
17
18use strict;
19
20use Pod::LaTeX;
21
22# Set up an END block to remove the test output file
23END { unlink "test.tex" };
24
25ok(1);
26
27# First thing to do is to read the expected output from
28# the DATA filehandle and store it in a scalar.
29# Do this until we read an =pod
30my @reference;
31while (my $line = <DATA>) {
32 last if $line =~ /^=pod/;
33 push(@reference,$line);
34}
35
36# Create a new parser
37my $parser = Pod::LaTeX->new;
38ok($parser);
39$parser->Head1Level(1);
40# Add the preamble but remember not to compare the timestamps
41$parser->AddPreamble(1);
42$parser->AddPostamble(1);
43
44# For a laugh add a table of contents
45$parser->TableOfContents(1);
46
47# Create an output file
48open(OUTFH, "> test.tex" ) or die "Unable to open test tex file: $!\n";
49
50# Read from the DATA filehandle and write to a new output file
51# Really want to write this to a scalar
52$parser->parse_from_filehandle(\*DATA,\*OUTFH);
53
54close(OUTFH) or die "Error closing OUTFH test.tex: $!\n";
55
56# Now read in OUTFH and compare
57open(INFH, "< test.tex") or die "Unable to read test tex file: $!\n";
58my @output = <INFH>;
59
60ok(@output, @reference);
61for my $i (0..$#reference) {
62 next if $reference[$i] =~ /^%%/; # skip timestamp comments
63 ok($output[$i], $reference[$i]);
64}
65
66close(INFH) or die "Error closing INFH test.tex: $!\n";
67
68
69__DATA__
70\documentclass{article}
71
72%% Latex generated from POD in document ...
73%% Using the perl module Pod::LaTeX
74%% Converted on Tue Nov 20 20:43:05 2001
75
76
77\usepackage{makeidx}
78\makeindex
79
80
81\begin{document}
82
83\tableofcontents
84
85\section{Introduction\label{Introduction}\index{Introduction}}
86\begin{itemize}
87
88\item
89
90Always check the return codes of system calls. Good error messages should
91go to STDERR, include which program caused the problem, what the failed
92system call and arguments were, and (\textbf{very important}) should contain
93the standard system error message for what went wrong. Here's a simple
94but sufficient example:
95
96\begin{verbatim}
97 opendir(D, $dir) or die "can't opendir $dir: $!";
98\end{verbatim}
99
100\item
101
102Line up your transliterations when it makes sense:
103
104\begin{verbatim}
105 tr [abc]
106 [xyz];
107\end{verbatim}
108
109
110The above should be aligned since it includes an embedded tab.
111
112
113\item
114
115Think about reusability. Why waste brainpower on a one-shot when you
116might want to do something like it again? Consider generalizing your
117code. Consider writing a module or object class. Consider making your
118code run cleanly with \texttt{use strict} and \texttt{-w} (or \texttt{use warnings} in
119Perl 5.6) in effect. Consider giving away your code. Consider changing
120your whole world view. Consider... oh, never mind.
121
122
123\item
124
125Be consistent.
126
127
128\item
129
130Be nice.
131
132\end{itemize}
133\section{Links\label{Links}\index{Links}}
134
135
136This link should just include one word: \textsf{Pod::LaTeX}
137
138
139
140This link should include the text \texttt{test} even though
141it refers to \texttt{Pod::LaTeX}: \textsf{test}.
142
143
144
145Standard link: the \emph{Pod::LaTeX} manpage.
146
147
148
149Now refer to an external section: the section on \textsf{sec} in the \emph{Pod::LaTeX} manpage
150
151\section{Lists\label{Lists}\index{Lists}}
152
153
154Test description list with long lines
155
156\begin{description}
157
158\item[Some short text] \mbox{}
159
160Some additional para.
161
162\begin{itemize}
163
164\item
165
166Nested itemized list
167
168
169\item
170
171Second item
172
173\end{itemize}
174
175\item[some longer text than that] \mbox{}
176
177and again.
178
179
180\item[this text is even longer and greater than] \textbf{40 characters}
181
182Some more content for the item.
183
184
185\item[this is some text with \textit{something across}] \textbf{the 40 char boundary}
186
187This is item content.
188
189\end{description}
190\section{Escapes\label{Escapes}\index{Escapes}}
191
192
193Test some normal escapes such as $<$ (lt) and $>$ (gt) and $|$ (verbar) and
194\texttt{\~{}} (tilde) and \& (amp) as well as $<$ (Esc lt) and $|$ (Esc
195verbar) and / (Esc sol) and $>$ (Esc gt) and \& (Esc amp)
196and " (Esc quot) and even $\alpha$ (Esc alpha).
197
198\section{For blocks\label{For_blocks}\index{For blocks}}
199 Some latex code \textbf{here}.
200
201
202
203Some text that should appear.
204
205
206
207Some more text that should appear
208
209Some latex in a \textsf{begin block}
210
211and some more
212
213\begin{equation}
214a = \frac{3}{2}
215\end{equation}
216
217
218
219Back to pod.
220
221\printindex
222
223\end{document}
224=pod
225
226=head1 Introduction
227
228=over 4
229
230=item *
231
232Always check the return codes of system calls. Good error messages should
233go to STDERR, include which program caused the problem, what the failed
234system call and arguments were, and (B<very important>) should contain
235the standard system error message for what went wrong. Here's a simple
236but sufficient example:
237
238 opendir(D, $dir) or die "can't opendir $dir: $!";
239
240=item *
241
242Line up your transliterations when it makes sense:
243
244 tr [abc]
245 [xyz];
246
247The above should be aligned since it includes an embedded tab.
248
249=item *
250
251Think about reusability. Why waste brainpower on a one-shot when you
252might want to do something like it again? Consider generalizing your
253code. Consider writing a module or object class. Consider making your
254code run cleanly with C<use strict> and C<-w> (or C<use warnings> in
255Perl 5.6) in effect. Consider giving away your code. Consider changing
256your whole world view. Consider... oh, never mind.
257
258=item *
259
260Be consistent.
261
262=item *
263
264Be nice.
265
266=back
267
268=head1 Links
269
270This link should just include one word: L<Pod::LaTeX|Pod::LaTeX>
271
272This link should include the text C<test> even though
273it refers to C<Pod::LaTeX>: L<test|Pod::LaTeX>.
274
275Standard link: L<Pod::LaTeX>.
276
277Now refer to an external section: L<Pod::LaTeX/"sec">
278
279
280=head1 Lists
281
282Test description list with long lines
283
284=over 4
285
286=item Some short text
287
288Some additional para.
289
290=over 4
291
292=item *
293
294Nested itemized list
295
296=item *
297
298Second item
299
300=back
301
302=item some longer text than that
303
304and again.
305
306=item this text is even longer and greater than 40 characters
307
308Some more content for the item.
309
310=item this is some text with I<something across> the 40 char boundary
311
312This is item content.
313
314=back
315
316=head1 Escapes
317
318Test some normal escapes such as < (lt) and > (gt) and | (verbar) and
319~ (tilde) and & (amp) as well as E<lt> (Esc lt) and E<verbar> (Esc
320verbar) and E<sol> (Esc sol) and E<gt> (Esc gt) and E<amp> (Esc amp)
321and E<quot> (Esc quot) and even E<alpha> (Esc alpha).
322
323=head1 For blocks
324
325=for latex
326 Some latex code \textbf{here}.
327
328Some text that should appear.
329
330=for comment
331 Should not print anything
332
333Some more text that should appear
334
335=begin latex
336
337Some latex in a \textsf{begin block}
338
339and some more
340
341\begin{equation}
342a = \frac{3}{2}
343\end{equation}
344
345=end latex
346
347Back to pod.
348
349=cut