blib/lib/Pod/LaTeX.pm

filter: Statementstmt 82.0% 283 / 345 Branchbran 64.8% 122 / 188 Conditioncond 42.4% 14 / 33 MC/DCmcdc 10.0% 2 / 20 Subroutinesub 97.2% 35 / 36 Podpod 95.8% 23 / 24 totaltotal 74.1% 479 / 646 CC 110 SCAR 24.8
CC
110
Cov
74%
interior_sequence
34.7
command
23.6
initialize
16.9
CRAP 12.0
↑ Summary
1 package Pod::LaTeX;
2  
3 =head1 NAME
4  
5 Pod::LaTeX - Convert Pod data to formatted Latex
6  
7 =head1 SYNOPSIS
8  
9 use Pod::LaTeX;
10 my $parser = Pod::LaTeX->new ( );
11  
12 $parser->parse_from_filehandle;
13  
14 $parser->parse_from_file ('file.pod', 'file.tex');
15  
16 =head1 DESCRIPTION
17  
18 C<Pod::LaTeX> is a module to convert documentation in the Pod format
19 into Latex. The L<B<pod2latex>|pod2latex> X<pod2latex> command uses
20 this module for translation.
21  
22 C<Pod::LaTeX> is a derived class from L<Pod::Select|Pod::Select>.
23  
24 =cut
25  
26  
27 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 require Pod::ParseUtils;
29 3 ▶use base qw/ Pod::Select /;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 3 ▶use if $] > 5.017, 'deprecate';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 # use Data::Dumper; # for debugging
34 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 3 ▶use vars qw/ $VERSION %HTML_Escapes @LatexSections /;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 3 $VERSION = '0.61';
39  
40 # Definitions of =headN -> latex mapping
41 3 @LatexSections = (qw/
42 chapter
43 section
44 subsection
45 subsubsection
46 paragraph
47 subparagraph
48 /);
49  
50 # Standard escape sequences converted to Latex.
51 # The Unicode name of each character is given in the comments.
52 # Complete LaTeX set added by Peter Acklam.
53  
54 3 %HTML_Escapes = (
55 'sol' => '\textfractionsolidus{}', # xxx - or should it be just '/'
56 'verbar' => '|',
57  
58 # The stuff below is based on the information available at
59 # http://www.w3.org/TR/html401/sgml/entities.html
60  
61 # All characters in the range 0xA0-0xFF of the ISO 8859-1 character set.
62 # Several of these characters require the `textcomp' LaTeX package.
63 'nbsp' => q|~|, # 0xA0 - no-break space = non-breaking space
64 'iexcl' => q|\textexclamdown{}|, # 0xA1 - inverted exclamation mark
65 'cent' => q|\textcent{}|, # 0xA2 - cent sign
66 'pound' => q|\textsterling{}|, # 0xA3 - pound sign
67 'curren' => q|\textcurrency{}|, # 0xA4 - currency sign
68 'yen' => q|\textyen{}|, # 0xA5 - yen sign = yuan sign
69 'brvbar' => q|\textbrokenbar{}|, # 0xA6 - broken bar = broken vertical bar
70 'sect' => q|\textsection{}|, # 0xA7 - section sign
71 'uml' => q|\textasciidieresis{}|, # 0xA8 - diaeresis = spacing diaeresis
72 'copy' => q|\textcopyright{}|, # 0xA9 - copyright sign
73 'ordf' => q|\textordfeminine{}|, # 0xAA - feminine ordinal indicator
74 'laquo' => q|\guillemotleft{}|, # 0xAB - left-pointing double angle quotation mark = left pointing guillemet
75 'not' => q|\textlnot{}|, # 0xAC - not sign
76 'shy' => q|\-|, # 0xAD - soft hyphen = discretionary hyphen
77 'reg' => q|\textregistered{}|, # 0xAE - registered sign = registered trade mark sign
78 'macr' => q|\textasciimacron{}|, # 0xAF - macron = spacing macron = overline = APL overbar
79 'deg' => q|\textdegree{}|, # 0xB0 - degree sign
80 'plusmn' => q|\textpm{}|, # 0xB1 - plus-minus sign = plus-or-minus sign
81 'sup2' => q|\texttwosuperior{}|, # 0xB2 - superscript two = superscript digit two = squared
82 'sup3' => q|\textthreesuperior{}|, # 0xB3 - superscript three = superscript digit three = cubed
83 'acute' => q|\textasciiacute{}|, # 0xB4 - acute accent = spacing acute
84 'micro' => q|\textmu{}|, # 0xB5 - micro sign
85 'para' => q|\textparagraph{}|, # 0xB6 - pilcrow sign = paragraph sign
86 'middot' => q|\textperiodcentered{}|, # 0xB7 - middle dot = Georgian comma = Greek middle dot
87 'cedil' => q|\c{}|, # 0xB8 - cedilla = spacing cedilla
88 'sup1' => q|\textonesuperior{}|, # 0xB9 - superscript one = superscript digit one
89 'ordm' => q|\textordmasculine{}|, # 0xBA - masculine ordinal indicator
90 'raquo' => q|\guillemotright{}|, # 0xBB - right-pointing double angle quotation mark = right pointing guillemet
91 'frac14' => q|\textonequarter{}|, # 0xBC - vulgar fraction one quarter = fraction one quarter
92 'frac12' => q|\textonehalf{}|, # 0xBD - vulgar fraction one half = fraction one half
93 'frac34' => q|\textthreequarters{}|, # 0xBE - vulgar fraction three quarters = fraction three quarters
94 'iquest' => q|\textquestiondown{}|, # 0xBF - inverted question mark = turned question mark
95 'Agrave' => q|\`A|, # 0xC0 - latin capital letter A with grave = latin capital letter A grave
96 'Aacute' => q|\'A|, # 0xC1 - latin capital letter A with acute
97 'Acirc' => q|\^A|, # 0xC2 - latin capital letter A with circumflex
98 'Atilde' => q|\~A|, # 0xC3 - latin capital letter A with tilde
99 'Auml' => q|\"A|, # 0xC4 - latin capital letter A with diaeresis
100 'Aring' => q|\AA{}|, # 0xC5 - latin capital letter A with ring above = latin capital letter A ring
101 'AElig' => q|\AE{}|, # 0xC6 - latin capital letter AE = latin capital ligature AE
102 'Ccedil' => q|\c{C}|, # 0xC7 - latin capital letter C with cedilla
103 'Egrave' => q|\`E|, # 0xC8 - latin capital letter E with grave
104 'Eacute' => q|\'E|, # 0xC9 - latin capital letter E with acute
105 'Ecirc' => q|\^E|, # 0xCA - latin capital letter E with circumflex
106 'Euml' => q|\"E|, # 0xCB - latin capital letter E with diaeresis
107 'Igrave' => q|\`I|, # 0xCC - latin capital letter I with grave
108 'Iacute' => q|\'I|, # 0xCD - latin capital letter I with acute
109 'Icirc' => q|\^I|, # 0xCE - latin capital letter I with circumflex
110 'Iuml' => q|\"I|, # 0xCF - latin capital letter I with diaeresis
111 'ETH' => q|\DH{}|, # 0xD0 - latin capital letter ETH
112 'Ntilde' => q|\~N|, # 0xD1 - latin capital letter N with tilde
113 'Ograve' => q|\`O|, # 0xD2 - latin capital letter O with grave
114 'Oacute' => q|\'O|, # 0xD3 - latin capital letter O with acute
115 'Ocirc' => q|\^O|, # 0xD4 - latin capital letter O with circumflex
116 'Otilde' => q|\~O|, # 0xD5 - latin capital letter O with tilde
117 'Ouml' => q|\"O|, # 0xD6 - latin capital letter O with diaeresis
118 'times' => q|\texttimes{}|, # 0xD7 - multiplication sign
119 'Oslash' => q|\O{}|, # 0xD8 - latin capital letter O with stroke = latin capital letter O slash
120 'Ugrave' => q|\`U|, # 0xD9 - latin capital letter U with grave
121 'Uacute' => q|\'U|, # 0xDA - latin capital letter U with acute
122 'Ucirc' => q|\^U|, # 0xDB - latin capital letter U with circumflex
123 'Uuml' => q|\"U|, # 0xDC - latin capital letter U with diaeresis
124 'Yacute' => q|\'Y|, # 0xDD - latin capital letter Y with acute
125 'THORN' => q|\TH{}|, # 0xDE - latin capital letter THORN
126 'szlig' => q|\ss{}|, # 0xDF - latin small letter sharp s = ess-zed
127 'agrave' => q|\`a|, # 0xE0 - latin small letter a with grave = latin small letter a grave
128 'aacute' => q|\'a|, # 0xE1 - latin small letter a with acute
129 'acirc' => q|\^a|, # 0xE2 - latin small letter a with circumflex
130 'atilde' => q|\~a|, # 0xE3 - latin small letter a with tilde
131 'auml' => q|\"a|, # 0xE4 - latin small letter a with diaeresis
132 'aring' => q|\aa{}|, # 0xE5 - latin small letter a with ring above = latin small letter a ring
133 'aelig' => q|\ae{}|, # 0xE6 - latin small letter ae = latin small ligature ae
134 'ccedil' => q|\c{c}|, # 0xE7 - latin small letter c with cedilla
135 'egrave' => q|\`e|, # 0xE8 - latin small letter e with grave
136 'eacute' => q|\'e|, # 0xE9 - latin small letter e with acute
137 'ecirc' => q|\^e|, # 0xEA - latin small letter e with circumflex
138 'euml' => q|\"e|, # 0xEB - latin small letter e with diaeresis
139 'igrave' => q|\`i|, # 0xEC - latin small letter i with grave
140 'iacute' => q|\'i|, # 0xED - latin small letter i with acute
141 'icirc' => q|\^i|, # 0xEE - latin small letter i with circumflex
142 'iuml' => q|\"i|, # 0xEF - latin small letter i with diaeresis
143 'eth' => q|\dh{}|, # 0xF0 - latin small letter eth
144 'ntilde' => q|\~n|, # 0xF1 - latin small letter n with tilde
145 'ograve' => q|\`o|, # 0xF2 - latin small letter o with grave
146 'oacute' => q|\'o|, # 0xF3 - latin small letter o with acute
147 'ocirc' => q|\^o|, # 0xF4 - latin small letter o with circumflex
148 'otilde' => q|\~o|, # 0xF5 - latin small letter o with tilde
149 'ouml' => q|\"o|, # 0xF6 - latin small letter o with diaeresis
150 'divide' => q|\textdiv{}|, # 0xF7 - division sign
151 'oslash' => q|\o{}|, # 0xF8 - latin small letter o with stroke, = latin small letter o slash
152 'ugrave' => q|\`u|, # 0xF9 - latin small letter u with grave
153 'uacute' => q|\'u|, # 0xFA - latin small letter u with acute
154 'ucirc' => q|\^u|, # 0xFB - latin small letter u with circumflex
155 'uuml' => q|\"u|, # 0xFC - latin small letter u with diaeresis
156 'yacute' => q|\'y|, # 0xFD - latin small letter y with acute
157 'thorn' => q|\th{}|, # 0xFE - latin small letter thorn
158 'yuml' => q|\"y|, # 0xFF - latin small letter y with diaeresis
159  
160 # Latin Extended-B
161 'fnof' => q|\textflorin{}|, # latin small f with hook = function = florin
162  
163 # Greek
164 'Alpha' => q|$\mathrm{A}$|, # greek capital letter alpha
165 'Beta' => q|$\mathrm{B}$|, # greek capital letter beta
166 'Gamma' => q|$\Gamma$|, # greek capital letter gamma
167 'Delta' => q|$\Delta$|, # greek capital letter delta
168 'Epsilon' => q|$\mathrm{E}$|, # greek capital letter epsilon
169 'Zeta' => q|$\mathrm{Z}$|, # greek capital letter zeta
170 'Eta' => q|$\mathrm{H}$|, # greek capital letter eta
171 'Theta' => q|$\Theta$|, # greek capital letter theta
172 'Iota' => q|$\mathrm{I}$|, # greek capital letter iota
173 'Kappa' => q|$\mathrm{K}$|, # greek capital letter kappa
174 'Lambda' => q|$\Lambda$|, # greek capital letter lambda
175 'Mu' => q|$\mathrm{M}$|, # greek capital letter mu
176 'Nu' => q|$\mathrm{N}$|, # greek capital letter nu
177 'Xi' => q|$\Xi$|, # greek capital letter xi
178 'Omicron' => q|$\mathrm{O}$|, # greek capital letter omicron
179 'Pi' => q|$\Pi$|, # greek capital letter pi
180 'Rho' => q|$\mathrm{R}$|, # greek capital letter rho
181 'Sigma' => q|$\Sigma$|, # greek capital letter sigma
182 'Tau' => q|$\mathrm{T}$|, # greek capital letter tau
183 'Upsilon' => q|$\Upsilon$|, # greek capital letter upsilon
184 'Phi' => q|$\Phi$|, # greek capital letter phi
185 'Chi' => q|$\mathrm{X}$|, # greek capital letter chi
186 'Psi' => q|$\Psi$|, # greek capital letter psi
187 'Omega' => q|$\Omega$|, # greek capital letter omega
188  
189 'alpha' => q|$\alpha$|, # greek small letter alpha
190 'beta' => q|$\beta$|, # greek small letter beta
191 'gamma' => q|$\gamma$|, # greek small letter gamma
192 'delta' => q|$\delta$|, # greek small letter delta
193 'epsilon' => q|$\epsilon$|, # greek small letter epsilon
194 'zeta' => q|$\zeta$|, # greek small letter zeta
195 'eta' => q|$\eta$|, # greek small letter eta
196 'theta' => q|$\theta$|, # greek small letter theta
197 'iota' => q|$\iota$|, # greek small letter iota
198 'kappa' => q|$\kappa$|, # greek small letter kappa
199 'lambda' => q|$\lambda$|, # greek small letter lambda
200 'mu' => q|$\mu$|, # greek small letter mu
201 'nu' => q|$\nu$|, # greek small letter nu
202 'xi' => q|$\xi$|, # greek small letter xi
203 'omicron' => q|$o$|, # greek small letter omicron
204 'pi' => q|$\pi$|, # greek small letter pi
205 'rho' => q|$\rho$|, # greek small letter rho
206 # 'sigmaf' => q||, # greek small letter final sigma
207 'sigma' => q|$\sigma$|, # greek small letter sigma
208 'tau' => q|$\tau$|, # greek small letter tau
209 'upsilon' => q|$\upsilon$|, # greek small letter upsilon
210 'phi' => q|$\phi$|, # greek small letter phi
211 'chi' => q|$\chi$|, # greek small letter chi
212 'psi' => q|$\psi$|, # greek small letter psi
213 'omega' => q|$\omega$|, # greek small letter omega
214 # 'thetasym' => q||, # greek small letter theta symbol
215 # 'upsih' => q||, # greek upsilon with hook symbol
216 # 'piv' => q||, # greek pi symbol
217  
218 # General Punctuation
219 'bull' => q|\textbullet{}|, # bullet = black small circle
220 # bullet is NOT the same as bullet operator
221 'hellip' => q|\textellipsis{}|, # horizontal ellipsis = three dot leader
222 'prime' => q|\textquotesingle{}|, # prime = minutes = feet
223 'Prime' => q|\textquotedbl{}|, # double prime = seconds = inches
224 'oline' => q|\textasciimacron{}|, # overline = spacing overscore
225 'frasl' => q|\textfractionsolidus{}|, # fraction slash
226  
227 # Letterlike Symbols
228 'weierp' => q|$\wp$|, # script capital P = power set = Weierstrass p
229 'image' => q|$\Re$|, # blackletter capital I = imaginary part
230 'real' => q|$\Im$|, # blackletter capital R = real part symbol
231 'trade' => q|\texttrademark{}|, # trade mark sign
232 # 'alefsym' => q||, # alef symbol = first transfinite cardinal
233 # alef symbol is NOT the same as hebrew letter alef, although the same
234 # glyph could be used to depict both characters
235  
236 # Arrows
237 'larr' => q|\textleftarrow{}|, # leftwards arrow
238 'uarr' => q|\textuparrow{}|, # upwards arrow
239 'rarr' => q|\textrightarrow{}|, # rightwards arrow
240 'darr' => q|\textdownarrow{}|, # downwards arrow
241 'harr' => q|$\leftrightarrow$|, # left right arrow
242 # 'crarr' => q||, # downwards arrow with corner leftwards = carriage return
243 'lArr' => q|$\Leftarrow$|, # leftwards double arrow
244 # ISO 10646 does not say that lArr is the same as the 'is implied by'
245 # arrow but also does not have any other character for that function. So
246 # lArr can be used for 'is implied by' as ISOtech suggests
247 'uArr' => q|$\Uparrow$|, # upwards double arrow
248 'rArr' => q|$\Rightarrow$|, # rightwards double arrow
249 # ISO 10646 does not say this is the 'implies' character but does not
250 # have another character with this function so ? rArr can be used for
251 # 'implies' as ISOtech suggests
252 'dArr' => q|$\Downarrow$|, # downwards double arrow
253 'hArr' => q|$\Leftrightarrow$|, # left right double arrow
254  
255 # Mathematical Operators.
256 # Some of these require the `amssymb' package.
257 'forall' => q|$\forall$|, # for all
258 'part' => q|$\partial$|, # partial differential
259 'exist' => q|$\exists$|, # there exists
260 'empty' => q|$\emptyset$|, # empty set = null set = diameter
261 'nabla' => q|$\nabla$|, # nabla = backward difference
262 'isin' => q|$\in$|, # element of
263 'notin' => q|$\notin$|, # not an element of
264 'ni' => q|$\ni$|, # contains as member
265 'prod' => q|$\prod$|, # n-ary product = product sign
266 # prod is NOT the same character as 'greek capital letter pi' though the
267 # same glyph might be used for both
268 'sum' => q|$\sum$|, # n-ary summation
269 # sum is NOT the same character as 'greek capital letter sigma' though
270 # the same glyph might be used for both
271 'minus' => q|$-$|, # minus sign
272 'lowast' => q|$\ast$|, # asterisk operator
273 'radic' => q|$\surd$|, # square root = radical sign
274 'prop' => q|$\propto$|, # proportional to
275 'infin' => q|$\infty$|, # infinity
276 'ang' => q|$\angle$|, # angle
277 'and' => q|$\wedge$|, # logical and = wedge
278 'or' => q|$\vee$|, # logical or = vee
279 'cap' => q|$\cap$|, # intersection = cap
280 'cup' => q|$\cup$|, # union = cup
281 'int' => q|$\int$|, # integral
282 'there4' => q|$\therefore$|, # therefore
283 'sim' => q|$\sim$|, # tilde operator = varies with = similar to
284 # tilde operator is NOT the same character as the tilde
285 'cong' => q|$\cong$|, # approximately equal to
286 'asymp' => q|$\asymp$|, # almost equal to = asymptotic to
287 'ne' => q|$\neq$|, # not equal to
288 'equiv' => q|$\equiv$|, # identical to
289 'le' => q|$\leq$|, # less-than or equal to
290 'ge' => q|$\geq$|, # greater-than or equal to
291 'sub' => q|$\subset$|, # subset of
292 'sup' => q|$\supset$|, # superset of
293 # note that nsup, 'not a superset of' is not covered by the Symbol font
294 # encoding and is not included.
295 'nsub' => q|$\not\subset$|, # not a subset of
296 'sube' => q|$\subseteq$|, # subset of or equal to
297 'supe' => q|$\supseteq$|, # superset of or equal to
298 'oplus' => q|$\oplus$|, # circled plus = direct sum
299 'otimes' => q|$\otimes$|, # circled times = vector product
300 'perp' => q|$\perp$|, # up tack = orthogonal to = perpendicular
301 'sdot' => q|$\cdot$|, # dot operator
302 # dot operator is NOT the same character as middle dot
303  
304 # Miscellaneous Technical
305 'lceil' => q|$\lceil$|, # left ceiling = apl upstile
306 'rceil' => q|$\rceil$|, # right ceiling
307 'lfloor' => q|$\lfloor$|, # left floor = apl downstile
308 'rfloor' => q|$\rfloor$|, # right floor
309 'lang' => q|$\langle$|, # left-pointing angle bracket = bra
310 # lang is NOT the same character as 'less than' or 'single left-pointing
311 # angle quotation mark'
312 'rang' => q|$\rangle$|, # right-pointing angle bracket = ket
313 # rang is NOT the same character as 'greater than' or 'single
314 # right-pointing angle quotation mark'
315  
316 # Geometric Shapes
317 'loz' => q|$\lozenge$|, # lozenge
318  
319 # Miscellaneous Symbols
320 'spades' => q|$\spadesuit$|, # black spade suit
321 'clubs' => q|$\clubsuit$|, # black club suit = shamrock
322 'hearts' => q|$\heartsuit$|, # black heart suit = valentine
323 'diams' => q|$\diamondsuit$|, # black diamond suit
324  
325 # C0 Controls and Basic Latin
326 'quot' => q|"|, # quotation mark = APL quote ["]
327 'amp' => q|\&|, # ampersand
328 'lt' => q|<|, # less-than sign
329 'gt' => q|>|, # greater-than sign
330 'OElig' => q|\OE{}|, # latin capital ligature OE
331 'oelig' => q|\oe{}|, # latin small ligature oe
332 'Scaron' => q|\v{S}|, # latin capital letter S with caron
333 'scaron' => q|\v{s}|, # latin small letter s with caron
334 'Yuml' => q|\"Y|, # latin capital letter Y with diaeresis
335 'circ' => q|\textasciicircum{}|, # modifier letter circumflex accent
336 'tilde' => q|\textasciitilde{}|, # small tilde
337 'ensp' => q|\phantom{n}|, # en space
338 'emsp' => q|\hspace{1em}|, # em space
339 'thinsp' => q|\,|, # thin space
340 'zwnj' => q|{}|, # zero width non-joiner
341 # 'zwj' => q||, # zero width joiner
342 # 'lrm' => q||, # left-to-right mark
343 # 'rlm' => q||, # right-to-left mark
344 'ndash' => q|--|, # en dash
345 'mdash' => q|---|, # em dash
346 'lsquo' => q|\textquoteleft{}|, # left single quotation mark
347 'rsquo' => q|\textquoteright{}|, # right single quotation mark
348 'sbquo' => q|\quotesinglbase{}|, # single low-9 quotation mark
349 'ldquo' => q|\textquotedblleft{}|, # left double quotation mark
350 'rdquo' => q|\textquotedblright{}|, # right double quotation mark
351 'bdquo' => q|\quotedblbase{}|, # double low-9 quotation mark
352 'dagger' => q|\textdagger{}|, # dagger
353 'Dagger' => q|\textdaggerdbl{}|, # double dagger
354 'permil' => q|\textperthousand{}|, # per mille sign
355 'lsaquo' => q|\guilsinglleft{}|, # single left-pointing angle quotation mark
356 'rsaquo' => q|\guilsinglright{}|, # single right-pointing angle quotation mark
357 'euro' => q|\texteuro{}|, # euro sign
358 );
359  
360 =head1 OBJECT METHODS
361  
362 The following methods are provided in this module. Methods inherited
363 from C<Pod::Select> are not described in the public interface.
364  
365 =over 4
366  
367 =begin __PRIVATE__
368  
369 =item C<initialize>
370  
371 Initialise the object. This method is subclassed from C<Pod::Parser>.
372 The base class method is invoked. This method defines the default
373 behaviour of the object unless overridden by supplying arguments to
374 the constructor.
375  
376 Internal settings are defaulted as well as the public instance data.
377 Internal hash values are accessed directly (rather than through
378 a method) and start with an underscore.
379  
380 This method should not be invoked by the user directly.
381  
382 =end __PRIVATE__
383  
384 =cut
385  
386  
387  
388 # - An array for nested lists
389  
390 # Arguments have already been read by this point
391  
392 2 ▶sub initialize {
Subroutine initialize: called CC=13 SCAR=28.3
Pod documented
393 2 my $self = shift;
394  
395 # print Dumper($self);
396  
397 # Internals
398 2 $self->{_Lists} = []; # For nested lists
399 2 $self->{_suppress_all_para} = 0; # For =begin blocks
400 2 $self->{_dont_modify_any_para}=0; # For =begin blocks
401 2 $self->{_CURRENT_HEAD1} = ''; # Name of current HEAD1 section
402  
403 # Options - only initialise if not already set
404  
405 # Cause the '=head1 NAME' field to be treated specially
406 # The contents of the NAME paragraph will be converted
407 # to a section title. All subsequent =head1 will be converted
408 # to =head2 and down. Will not affect =head1's prior to NAME
409 # Assumes: 'Module - purpose' format
410 # Also creates a purpose field
411 # The name is used for Labeling of the subsequent subsections
412 $self->{ReplaceNAMEwithSection} = 0
413 2 ▶ unless exists $self->{ReplaceNAMEwithSection};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"ReplaceNAMEwithSection"} 2 0 2
414 $self->{AddPreamble} = 1 # make full latex document
415 2 ▶ unless exists $self->{AddPreamble};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"AddPreamble"} 2 0 2
416 $self->{StartWithNewPage} = 0 # Start new page for pod section
417 2 ▶ unless exists $self->{StartWithNewPage};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"StartWithNewPage"} 2 0 2
418 $self->{TableOfContents} = 0 # Add table of contents
419 2 ▶ unless exists $self->{TableOfContents}; # only relevant if AddPreamble=1
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"TableOfContents"} 2 0 2
420 $self->{AddPostamble} = 1 # Add closing latex code at end
421 2 ▶ unless exists $self->{AddPostamble}; # effectively end{document} and index
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"AddPostamble"} 2 0 2
422 $self->{MakeIndex} = 1 # Add index (only relevant AddPostamble
423 2 ▶ unless exists $self->{MakeIndex}; # and AddPreamble)
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"MakeIndex"} 2 0 2
424  
425 $self->{UniqueLabels} = 1 # Use label unique for each pod
426 2 ▶ unless exists $self->{UniqueLabels}; # either based on the filename
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"UniqueLabels"} 2 0 2
427 # or supplied
428  
429 # Control the level of =head1. default is \section
430 #
431 $self->{Head1Level} = 1 # Offset in latex sections
432 2 ▶ unless exists $self->{Head1Level}; # 0 is chapter, 2 is subsection
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"Head1Level"} 2 0 2
433  
434 # Control at which level numbering of sections is turned off
435 # ie subsection becomes subsection*
436 # The numbering is relative to the latex sectioning commands
437 # and is independent of Pod heading level
438 # default is to number \section but not \subsection
439 $self->{LevelNoNum} = 2
440 2 ▶ unless exists $self->{LevelNoNum};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"LevelNoNum"} 2 0 2
441  
442 # Label to be used as prefix to all internal section names
443 # If not defined will attempt to derive it from the filename
444 # This can not happen when running parse_from_filehandle though
445 # hence the ability to set the label externally
446 # The label could then be Pod::Parser_DESCRIPTION or somesuch
447  
448 $self->{Label} = undef # label to be used as prefix
449 2 ▶ unless exists $self->{Label}; # to all internal section names
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"Label"} 2 0 2
450  
451 # These allow the caller to add arbitrary latex code to
452 # start and end of document. AddPreamble and AddPostamble are ignored
453 # if these are set.
454 # Also MakeIndex and TableOfContents are also ignored.
455 $self->{UserPreamble} = undef # User supplied start (AddPreamble =1)
456 2 ▶ unless exists $self->{Label};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"Label"} 0 2 2
457 $self->{UserPostamble} = undef # Use supplied end (AddPostamble=1)
458 2 ▶ unless exists $self->{Label};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"Label"} 0 2 2
459  
460 # Run base initialize
461 2 $self->SUPER::initialize;
462  
463 }
464  
465 =back
466  
467 =head2 Data Accessors
468  
469 The following methods are provided for accessing instance data. These
470 methods should be used for accessing configuration parameters rather
471 than assuming the object is a hash.
472  
473 Default values can be supplied by using these names as keys to a hash
474 of arguments when using the C<new()> constructor.
475  
476 =over 4
477  
478 =item B<AddPreamble>
479  
480 Logical to control whether a C<latex> preamble is to be written.
481 If true, a valid C<latex> preamble is written before the pod data is written.
482 This is similar to:
483  
484 \documentclass{article}
485 \usepackage[T1]{fontenc}
486 \usepackage{textcomp}
487 \begin{document}
488  
489 but will be more complicated if table of contents and indexing are required.
490 Can be used to set or retrieve the current value.
491  
492 $add = $parser->AddPreamble();
493 $parser->AddPreamble(1);
494  
495 If used in conjunction with C<AddPostamble> a full latex document will
496 be written that could be immediately processed by C<latex>.
497  
498 For some pod escapes it may be necessary to include the amsmath
499 package. This is not yet added to the preamble automatically.
500  
501 =cut
502  
503 3 ▶sub AddPreamble {
Subroutine AddPreamble: called CC=2 SCAR=6.9
Pod documented
504 3 my $self = shift;
505 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
506 1 $self->{AddPreamble} = shift;
507 }
508 3 return $self->{AddPreamble};
509 }
510  
511 =item B<AddPostamble>
512  
513 Logical to control whether a standard C<latex> ending is written to the output
514 file after the document has been processed.
515 In its simplest form this is simply:
516  
517 \end{document}
518  
519 but can be more complicated if a index is required.
520 Can be used to set or retrieve the current value.
521  
522 $add = $parser->AddPostamble();
523 $parser->AddPostamble(1);
524  
525 If used in conjunction with C<AddPreaamble> a full latex document will
526 be written that could be immediately processed by C<latex>.
527  
528 =cut
529  
530 3 ▶sub AddPostamble {
Subroutine AddPostamble: called CC=2 SCAR=6.9
Pod documented
531 3 my $self = shift;
532 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
533 1 $self->{AddPostamble} = shift;
534 }
535 3 return $self->{AddPostamble};
536 }
537  
538 =item B<Head1Level>
539  
540 The C<latex> sectioning level that should be used to correspond to
541 a pod C<=head1> directive. This can be used, for example, to turn
542 a C<=head1> into a C<latex> C<subsection>. This should hold a number
543 corresponding to the required position in an array containing the
544 following elements:
545  
546 [0] chapter
547 [1] section
548 [2] subsection
549 [3] subsubsection
550 [4] paragraph
551 [5] subparagraph
552  
553 Can be used to set or retrieve the current value:
554  
555 $parser->Head1Level(2);
556 $sect = $parser->Head1Level;
557  
558 Setting this number too high can result in sections that may not be reproducible
559 in the expected way. For example, setting this to 4 would imply that C<=head3>
560 do not have a corresponding C<latex> section (C<=head1> would correspond to
561 a C<paragraph>).
562  
563 A check is made to ensure that the supplied value is an integer in the
564 range 0 to 5.
565  
566 Default is for a value of 1 (i.e. a C<section>).
567  
568 =cut
569  
570 7 ▶sub Head1Level {
Subroutine Head1Level: called CC=4 SCAR=14.8
Pod documented
571 7 my $self = shift;
572 7 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 6 7
573 1 my $arg = shift;
574 1 ▶ if ($arg =~ /^\d$/ && $arg <= $#LatexSections) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^\d$/ and $arg <= $#Pod::LaTeX::LatexSections) { } 1 0 1
Condition33%1/3
$arg =~ /^\d$/ and $arg <= $#Pod::LaTeX::LatexSections
!ll&&!rl&&r
001
MC/DC0%0/2
$arg =~ /^\d$/ and $arg <= $#Pod::LaTeX::LatexSections
$arg =~ /^\d$/ $arg <= $#Pod::LaTeX::LatexSections
Truth table33%1/3
A and B
A= $arg =~ /^\d$/B= $arg <= $#Pod::LaTeX::LatexSections
ABresult
0X0
100
111
575 1 $self->{Head1Level} = $arg;
576 } else {
577 0 carp "Head1Level supplied ($arg) must be integer in range 0 to ".$#LatexSections . "- Ignoring\n";
578 }
579 }
580 7 return $self->{Head1Level};
581 }
582  
583 =item B<Label>
584  
585 This is the label that is prefixed to all C<latex> label and index
586 entries to make them unique. In general, pods have similarly titled
587 sections (NAME, DESCRIPTION etc) and a C<latex> label will be multiply
588 defined if more than one pod document is to be included in a single
589 C<latex> file. To overcome this, this label is prefixed to a label
590 whenever a label is required (joined with an underscore) or to an
591 index entry (joined by an exclamation mark which is the normal index
592 separator). For example, C<\label{text}> becomes C<\label{Label_text}>.
593  
594 Can be used to set or retrieve the current value:
595  
596 $label = $parser->Label;
597 $parser->Label($label);
598  
599 This label is only used if C<UniqueLabels> is true.
600 Its value is set automatically from the C<NAME> field
601 if C<ReplaceNAMEwithSection> is true. If this is not the case
602 it must be set manually before starting the parse.
603  
604 Default value is C<undef>.
605  
606 =cut
607  
608 12 ▶sub Label {
Subroutine Label: called CC=2 SCAR=7.6
Pod documented
609 12 my $self = shift;
610 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 12 12
611 0 $self->{Label} = shift;
612 }
613 12 return $self->{Label};
614 }
615  
616 =item B<LevelNoNum>
617  
618 Control the point at which C<latex> section numbering is turned off.
619 For example, this can be used to make sure that C<latex> sections
620 are numbered but subsections are not.
621  
622 Can be used to set or retrieve the current value:
623  
624 $lev = $parser->LevelNoNum;
625 $parser->LevelNoNum(2);
626  
627 The argument must be an integer between 0 and 5 and is the same as the
628 number described in C<Head1Level> method description. The number has
629 nothing to do with the pod heading number, only the C<latex> sectioning.
630  
631 Default is 2. (i.e. C<latex> subsections are written as C<subsection*>
632 but sections are numbered).
633  
634 =cut
635  
636 6 ▶sub LevelNoNum {
Subroutine LevelNoNum: called CC=2 SCAR=7.6
Pod documented
637 6 my $self = shift;
638 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 6 6
639 0 $self->{LevelNoNum} = shift;
640 }
641 6 return $self->{LevelNoNum};
642 }
643  
644 =item B<MakeIndex>
645  
646 Controls whether C<latex> commands for creating an index are to be inserted
647 into the preamble and postamble
648  
649 $makeindex = $parser->MakeIndex;
650 $parser->MakeIndex(0);
651  
652 Irrelevant if both C<AddPreamble> and C<AddPostamble> are false (or equivalently,
653 C<UserPreamble> and C<UserPostamble> are set).
654  
655 Default is for an index to be created.
656  
657 =cut
658  
659 2 ▶sub MakeIndex {
Subroutine MakeIndex: called CC=2 SCAR=7.6
Pod documented
660 2 my $self = shift;
661 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
662 0 $self->{MakeIndex} = shift;
663 }
664 2 return $self->{MakeIndex};
665 }
666  
667 =item B<ReplaceNAMEwithSection>
668  
669 This controls whether the C<NAME> section in the pod is to be translated
670 literally or converted to a slightly modified output where the section
671 name is the pod name rather than "NAME".
672  
673 If true, the pod segment
674  
675 =head1 NAME
676  
677 pod::name - purpose
678  
679 =head1 SYNOPSIS
680  
681 is converted to the C<latex>
682  
683 \section{pod::name\label{pod_name}\index{pod::name}}
684  
685 Purpose
686  
687 \subsection*{SYNOPSIS\label{pod_name_SYNOPSIS}%
688 \index{pod::name!SYNOPSIS}}
689  
690 (dependent on the value of C<Head1Level> and C<LevelNoNum>). Note that
691 subsequent C<head1> directives translate to subsections rather than
692 sections and that the labels and index now include the pod name (dependent
693 on the value of C<UniqueLabels>).
694  
695 The C<Label> is set from the pod name regardless of any current value
696 of C<Label>.
697  
698 $mod = $parser->ReplaceNAMEwithSection;
699 $parser->ReplaceNAMEwithSection(0);
700  
701 Default is to translate the pod literally.
702  
703 =cut
704  
705 0 ▶sub ReplaceNAMEwithSection {
Subroutine ReplaceNAMEwithSection: not called CC=2 SCAR=17.9
Pod documented
706 0 my $self = shift;
707 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
708 0 $self->{ReplaceNAMEwithSection} = shift;
709 }
710 0 return $self->{ReplaceNAMEwithSection};
711 }
712  
713 =item B<StartWithNewPage>
714  
715 If true, each pod translation will begin with a C<latex>
716 C<\clearpage>.
717  
718 $parser->StartWithNewPage(1);
719 $newpage = $parser->StartWithNewPage;
720  
721 Default is false.
722  
723 =cut
724  
725 2 ▶sub StartWithNewPage {
Subroutine StartWithNewPage: called CC=2 SCAR=7.6
Pod documented
726 2 my $self = shift;
727 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
728 0 $self->{StartWithNewPage} = shift;
729 }
730 2 return $self->{StartWithNewPage};
731 }
732  
733 =item B<TableOfContents>
734  
735 If true, a table of contents will be created.
736 Irrelevant if C<AddPreamble> is false or C<UserPreamble>
737 is set.
738  
739 $toc = $parser->TableOfContents;
740 $parser->TableOfContents(1);
741  
742 Default is false.
743  
744 =cut
745  
746 2 ▶sub TableOfContents {
Subroutine TableOfContents: called CC=2 SCAR=6.9
Pod documented
747 2 my $self = shift;
748 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
749 1 $self->{TableOfContents} = shift;
750 }
751 2 return $self->{TableOfContents};
752 }
753  
754 =item B<UniqueLabels>
755  
756 If true, the translator will attempt to make sure that
757 each C<latex> label or index entry will be uniquely identified
758 by prefixing the contents of C<Label>. This allows
759 multiple documents to be combined without clashing
760 common labels such as C<DESCRIPTION> and C<SYNOPSIS>
761  
762 $parser->UniqueLabels(1);
763 $unq = $parser->UniqueLabels;
764  
765 Default is true.
766  
767 =cut
768  
769 12 ▶sub UniqueLabels {
Subroutine UniqueLabels: called CC=2 SCAR=7.6
Pod documented
770 12 my $self = shift;
771 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 12 12
772 0 $self->{UniqueLabels} = shift;
773 }
774 12 return $self->{UniqueLabels};
775 }
776  
777 =item B<UserPreamble>
778  
779 User supplied C<latex> preamble. Added before the pod translation
780 data.
781  
782 If set, the contents will be prepended to the output file before the translated
783 data regardless of the value of C<AddPreamble>.
784 C<MakeIndex> and C<TableOfContents> will also be ignored.
785  
786 =cut
787  
788 3 ▶sub UserPreamble {
Subroutine UserPreamble: called CC=2 SCAR=7.6
Pod documented
789 3 my $self = shift;
790 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 3 3
791 0 $self->{UserPreamble} = shift;
792 }
793 3 return $self->{UserPreamble};
794 }
795  
796 =item B<UserPostamble>
797  
798 User supplied C<latex> postamble. Added after the pod translation
799 data.
800  
801 If set, the contents will be prepended to the output file after the translated
802 data regardless of the value of C<AddPostamble>.
803 C<MakeIndex> will also be ignored.
804  
805 =cut
806  
807 3 ▶sub UserPostamble {
Subroutine UserPostamble: called CC=2 SCAR=7.6
Pod documented
808 3 my $self = shift;
809 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 3 3
810 0 $self->{UserPostamble} = shift;
811 }
812 3 return $self->{UserPostamble};
813 }
814  
815 =begin __PRIVATE__
816  
817 =item B<Lists>
818  
819 Contains details of the currently active lists.
820 The array contains C<Pod::List> objects. A new C<Pod::List>
821 object is created each time a list is encountered and it is
822 pushed onto this stack. When the list context ends, it
823 is popped from the stack. The array will be empty if no
824 lists are active.
825  
826 Returns array of list information in list context
827 Returns array ref in scalar context
828  
829 =cut
830  
831  
832  
833 76 ▶sub lists {
Subroutine lists: called CC=2 SCAR=7.6
Pod undocumented
834 76 my $self = shift;
835 0 ▶ return @{ $self->{_Lists} } if wantarray();
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 76 76
836 76 return $self->{_Lists};
837 }
838  
839 =end __PRIVATE__
840  
841 =back
842  
843 =begin __PRIVATE__
844  
845 =head2 Subclassed methods
846  
847 The following methods override methods provided in the C<Pod::Select>
848 base class. See C<Pod::Parser> and C<Pod::Select> for more information
849 on what these methods require.
850  
851 =over 4
852  
853 =cut
854  
855 ######### END ACCESSORS ###################
856  
857 # Opening pod
858  
859 =item B<begin_pod>
860  
861 Writes the C<latex> preamble if requested. Only writes something
862 if AddPreamble is true. Writes a standard header unless a UserPreamble
863 is defined.
864  
865 =cut
866  
867 2 ▶sub begin_pod {
Subroutine begin_pod: called CC=7 SCAR=20.0
Pod documented
868 2 my $self = shift;
869  
870 # Get the pod identification
871 # This should really come from the '=head1 NAME' paragraph
872  
873 2 my $infile = $self->input_file;
874 2 my $class = ref($self);
875 2 my $date = gmtime(time);
876  
877 # Comment message to say where this came from
878 2 my $comment = << "__TEX_COMMENT__";
879 %% Latex generated from POD in document $infile
880 %% Using the perl module $class
881 %% Converted on $date
882 __TEX_COMMENT__
883  
884 # Write the preamble
885 # If the caller has supplied one then we just use that
886  
887 2 my $preamble = '';
888  
889 2 ▶ if ($self->AddPreamble) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->AddPreamble) 2 0 2
890  
891 2 ▶ if (defined $self->UserPreamble) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->UserPreamble) { } 1 1 2
892  
893 1 $preamble = $self->UserPreamble;
894  
895 # Add the description of where this came from
896 1 $preamble .= "\n$comment\n%% Preamble supplied by user.\n\n";
897  
898 } else {
899  
900 # Write our own preamble
901  
902 # Code to initialise index making
903 # Use an array so that we can prepend comment if required
904 1 my @makeidx = (
905 '\usepackage{makeidx}',
906 '\makeindex',
907 );
908  
909 1 ▶ unless ($self->MakeIndex) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->MakeIndex) 0 1 1
910 0 foreach (@makeidx) {
911 0 $_ = '%% ' . $_;
912 }
913 }
914 1 my $makeindex = join("\n",@makeidx) . "\n";
915  
916 # Table of contents
917 1 my $tableofcontents = '\tableofcontents';
918  
919 1 ▶ $tableofcontents = '%% ' . $tableofcontents
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TableOfContents 0 1 1
920 unless $self->TableOfContents;
921  
922 # Roll our own
923 1 $preamble = << "__TEX_HEADER__";
924 \\documentclass{article}
925 \\usepackage[T1]{fontenc}
926 \\usepackage{textcomp}
927  
928 $comment
929  
930 $makeindex
931  
932 \\begin{document}
933  
934 $tableofcontents
935  
936 __TEX_HEADER__
937  
938 }
939 }
940  
941 # Write the header (blank if none)
942 2 $self->_output($preamble);
943  
944 # Start on new page if requested
945 2 ▶ $self->_output("\\clearpage\n") if $self->StartWithNewPage;
Branch: 1 branch
BranchTrueFalseTotal
if $self->StartWithNewPage 0 2 2
946  
947 }
948  
949  
950 =item B<end_pod>
951  
952 Write the closing C<latex> code. Only writes something if AddPostamble
953 is true. Writes a standard header unless a UserPostamble is defined.
954  
955 =cut
956  
957 2 ▶sub end_pod {
Subroutine end_pod: called CC=4 SCAR=14.0
Pod documented
958 2 my $self = shift;
959  
960 # End string
961 2 my $end = '';
962  
963 # Use the user version of the postamble if defined
964 2 ▶ if ($self->AddPostamble) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->AddPostamble) 2 0 2
965  
966 2 ▶ if (defined $self->UserPostamble) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->UserPostamble) { } 1 1 2
967 1 $end = $self->UserPostamble;
968  
969 } else {
970  
971 # Check for index
972 1 my $makeindex = '\printindex';
973  
974 1 ▶ $makeindex = '%% '. $makeindex unless $self->MakeIndex;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->MakeIndex 0 1 1
975  
976 1 $end = "$makeindex\n\n\\end{document}\n";
977 }
978 }
979  
980 2 $self->_output($end);
981  
982 }
983  
984 =item B<command>
985  
986 Process basic pod commands.
987  
988 =cut
989  
990 32 ▶sub command {
Subroutine command: called CC=17 SCAR=31.6
Pod documented
991 32 my $self = shift;
992 32 my ($command, $paragraph, $line_num, $parobj) = @_;
993  
994 # return if we dont care
995 32 ▶ return if $command eq 'pod';
Branch: 1 branch
BranchTrueFalseTotal
if $command eq "pod" 0 32 32
996  
997 # Store a copy of the raw text in case we are in a =for
998 # block and need to preserve the existing latex
999 32 my $rawpara = $paragraph;
1000  
1001 # Do the latex escapes
1002 32 $paragraph = $self->_replace_special_chars($paragraph);
1003  
1004 # Interpolate pod sequences in paragraph
1005 32 $paragraph = $self->interpolate($paragraph, $line_num);
1006 32 $paragraph =~ s/\s+$//;
1007  
1008 # Replace characters that can only be done after
1009 # interpolation of interior sequences
1010 32 $paragraph = $self->_replace_special_chars_late($paragraph);
1011  
1012 # Now run the command
1013 32 ▶ if ($command eq 'over') {
Branch: 13 branches
BranchTrueFalseTotal
if ($command eq 'over') { } 4 28 32
elsif ($command eq 'item') { } 14 14 28
elsif ($command eq 'back') { } 4 10 14
elsif ($command eq 'head1') { } 6 4 10
elsif ($command eq 'head2') { } 0 4 4
elsif ($command eq 'head3') { } 0 4 4
elsif ($command eq 'head4') { } 0 4 4
elsif ($command eq 'head5') { } 0 4 4
elsif ($command eq 'head6') { } 0 4 4
elsif ($command eq 'begin') { } 1 3 4
elsif ($command eq 'for') { } 2 1 3
elsif ($command eq 'end') { } 1 0 1
elsif ($command eq 'pod') { } 0 0 0
1014  
1015 4 $self->begin_list($paragraph, $line_num);
1016  
1017 } elsif ($command eq 'item') {
1018  
1019 14 $self->add_item($paragraph, $line_num);
1020  
1021 } elsif ($command eq 'back') {
1022  
1023 4 $self->end_list($line_num);
1024  
1025 } elsif ($command eq 'head1') {
1026  
1027 # Store the name of the section
1028 6 $self->{_CURRENT_HEAD1} = $paragraph;
1029  
1030 # Print it
1031 6 $self->head(1, $paragraph, $parobj);
1032  
1033 } elsif ($command eq 'head2') {
1034  
1035 0 $self->head(2, $paragraph, $parobj);
1036  
1037 } elsif ($command eq 'head3') {
1038  
1039 0 $self->head(3, $paragraph, $parobj);
1040  
1041 } elsif ($command eq 'head4') {
1042  
1043 0 $self->head(4, $paragraph, $parobj);
1044  
1045 } elsif ($command eq 'head5') {
1046  
1047 0 $self->head(5, $paragraph, $parobj);
1048  
1049 } elsif ($command eq 'head6') {
1050  
1051 0 $self->head(6, $paragraph, $parobj);
1052  
1053 } elsif ($command eq 'begin') {
1054  
1055 # pass through if latex
1056 1 ▶ if ($paragraph =~ /^latex/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($paragraph =~ /^latex/i) { } 1 0 1
1057 # Make sure that subsequent paragraphs are not modfied before printing
1058 1 $self->{_dont_modify_any_para} = 1;
1059  
1060 } else {
1061 # Suppress all subsequent paragraphs unless
1062 # it is explicitly intended for latex
1063 0 $self->{_suppress_all_para} = 1;
1064 }
1065  
1066 } elsif ($command eq 'for') {
1067  
1068 # =for latex
1069 # some latex
1070  
1071 # With =for we will get the text for the full paragraph
1072 # as well as the format name.
1073 # We do not get an additional paragraph later on. The next
1074 # paragraph is not governed by the =for
1075  
1076 # The first line contains the format and the rest is the
1077 # raw code.
1078 2 my ($format, $chunk) = split(/\n/, $rawpara, 2);
1079  
1080 # If we have got some latex code print it out immediately
1081 # unmodified. Else do nothing.
1082 2 ▶ if ($format =~ /^latex/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /^latex/i) 1 1 2
1083 # Make sure that next paragraph is not modfied before printing
1084 1 $self->_output( $chunk );
1085  
1086 }
1087  
1088 } elsif ($command eq 'end') {
1089  
1090 # Reset suppression
1091 1 $self->{_suppress_all_para} = 0;
1092 1 $self->{_dont_modify_any_para} = 0;
1093  
1094 } elsif ($command eq 'pod') {
1095  
1096 # Do nothing
1097  
1098 } else {
1099 0 carp "Command $command not recognised at line $line_num\n";
1100 }
1101  
1102 }
1103  
1104 =item B<verbatim>
1105  
1106 Verbatim text
1107  
1108 =cut
1109  
1110 3 ▶sub verbatim {
Subroutine verbatim: called CC=5 SCAR=16.2
Pod documented
1111 3 my $self = shift;
1112 3 my ($paragraph, $line_num, $parobj) = @_;
1113  
1114 # Expand paragraph unless in =begin block
1115 3 ▶ if ($self->{_dont_modify_any_para}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_dont_modify_any_para'}) { } 0 3 3
1116 # Just print as is
1117 0 $self->_output($paragraph);
1118  
1119 } else {
1120  
1121 3 ▶ return if $paragraph =~ /^\s+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $paragraph =~ /^\s+$/ 1 2 3
1122  
1123 # Clean trailing space
1124 2 $paragraph =~ s/\s+$//;
1125  
1126 # Clean tabs. Routine taken from Tabs.pm
1127 # by David Muir Sharnoff muir@idiom.com,
1128 # slightly modified by hsmyers@sdragons.com 10/22/01
1129 2 my @l = split("\n",$paragraph);
1130 2 foreach (@l) {
1131 3 ▶ 1 while s/(^|\n)([^\t\n]*)(\t+)/
Branch: 1 branch
BranchTrueFalseTotal
s/(^|\n)([^\t\n]*)(\t+)/$1 . $2 . " " x (8 * length($3) - length($2) % 8);/sex and do { '???' } 1 3 4
1132 1 $1. $2 . (" " x
1133 (8 * length($3)
1134 - (length($2) % 8)))
1135 /sex;
1136 }
1137 2 $paragraph = join("\n",@l);
1138 # End of change.
1139  
1140  
1141  
1142 2 $self->_output('\begin{verbatim}' . "\n$paragraph\n". '\end{verbatim}'."\n");
1143 }
1144 }
1145  
1146 =item B<textblock>
1147  
1148 Plain text paragraph.
1149  
1150 =cut
1151  
1152 29 ▶sub textblock {
Subroutine textblock: called CC=5 SCAR=20.6
Pod documented
1153 29 my $self = shift;
1154 29 my ($paragraph, $line_num, $parobj) = @_;
1155  
1156 # print Dumper($self);
1157  
1158 # Expand paragraph unless in =begin block
1159 29 ▶ if ($self->{_dont_modify_any_para}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_dont_modify_any_para"}) 3 26 29
1160 # Just print as is
1161 3 $self->_output($paragraph);
1162  
1163 3 return;
1164 }
1165  
1166  
1167 # Escape latex special characters
1168 26 $paragraph = $self->_replace_special_chars($paragraph);
1169  
1170 # Interpolate interior sequences
1171 26 my $expansion = $self->interpolate($paragraph, $line_num);
1172 26 $expansion =~ s/\s+$//;
1173  
1174 # Escape special characters that can not be done earlier
1175 26 $expansion = $self->_replace_special_chars_late($expansion);
1176  
1177 # If we are replacing 'head1 NAME' with a section
1178 # we need to look in the paragraph and rewrite things
1179 # Need to make sure this is called only on the first paragraph
1180 # following 'head1 NAME' and not on subsequent paragraphs that may be
1181 # present.
1182 26 ▶ if ($self->{_CURRENT_HEAD1} =~ /^NAME/i && $self->ReplaceNAMEwithSection()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_CURRENT_HEAD1'} =~ /^NAME/i and $self->ReplaceNAMEwithSection) { } 0 26 26
Condition33%1/3
$self->{"_CURRENT_HEAD1"} =~ /^NAME/i and $self->ReplaceNAMEwithSection
!ll&&!rl&&r
2600
MC/DC0%0/2
$self->{"_CURRENT_HEAD1"} =~ /^NAME/i and $self->ReplaceNAMEwithSection
$self->{"_CURRENT_HEAD1"} =~ /^NAME/i $self->ReplaceNAMEwithSection
Truth table33%1/3
A and B
A= $self->{"_CURRENT_HEAD1"} =~ /^NAME/iB= $self->ReplaceNAMEwithSection
ABresult
0X0
100
111
1183  
1184 # Strip white space from start and end
1185 0 $paragraph =~ s/^\s+//;
1186 0 $paragraph =~ s/\s$//;
1187  
1188 # Split the string into 2 parts
1189 0 my ($name, $purpose) = split(/\s+-\s+/, $expansion,2);
1190  
1191 # Now prevent this from triggering until a new head1 NAME is set
1192 0 $self->{_CURRENT_HEAD1} = '_NAME';
1193  
1194 # Might want to clear the Label() before doing this (CHECK)
1195  
1196 # Print the heading
1197 0 $self->head(1, $name, $parobj);
1198  
1199 # Set the labeling in case we want unique names later
1200 0 $self->Label( $self->_create_label( $name, 1 ) );
1201  
1202 # Raise the Head1Level by one so that subsequent =head1 appear
1203 # as subsections of the main name section unless we are already
1204 # at maximum [Head1Level() could check this itself - CHECK]
1205 0 ▶ $self->Head1Level( $self->Head1Level() + 1)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->Head1Level == $#Pod::LaTeX::LatexSections 0 0 0
1206 unless $self->Head1Level == $#LatexSections;
1207  
1208 # Now write out the new latex paragraph
1209 0 $purpose = ucfirst($purpose);
1210 0 $self->_output("\n\n$purpose\n\n");
1211  
1212 } else {
1213 # Just write the output
1214 26 $self->_output("\n\n$expansion\n\n");
1215 }
1216  
1217 }
1218  
1219 =item B<interior_sequence>
1220  
1221 Interior sequence expansion
1222  
1223 =cut
1224  
1225 24 ▶sub interior_sequence {
Subroutine interior_sequence: called CC=17 SCAR=35.5
Pod documented
1226 24 my $self = shift;
1227  
1228 24 my ($seq_command, $seq_argument, $pod_seq) = @_;
1229  
1230 24 ▶ if ($seq_command eq 'B') {
Branch: 11 branches
BranchTrueFalseTotal
if ($seq_command eq 'B') { } 1 23 24
elsif ($seq_command eq 'I') { } 2 21 23
elsif ($seq_command eq 'E') { } 7 14 21
elsif ($seq_command eq 'Z') { } 0 14 14
elsif ($seq_command eq 'C') { } 5 9 14
elsif ($seq_command eq 'F') { } 0 9 9
elsif ($seq_command eq 'S') { } 0 9 9
elsif ($seq_command eq 'L') { } 4 5 9
elsif ($seq_command eq 'P') { } 2 3 5
elsif ($seq_command eq 'Q') { } 3 0 3
elsif ($seq_command eq 'X') { } 0 0 0
1231 1 return "\\textbf{$seq_argument}";
1232  
1233 } elsif ($seq_command eq 'I') {
1234 2 return "\\textit{$seq_argument}";
1235  
1236 } elsif ($seq_command eq 'E') {
1237  
1238 # If it is simply a number
1239 7 ▶ if ($seq_argument =~ /^\d+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($seq_argument =~ /^\d+$/) { } 0 7 7
elsif (exists $Pod::LaTeX::HTML_Escapes{$seq_argument}) { } 7 0 7
1240 0 return chr($seq_argument);
1241 # Look up escape in hash table
1242 } elsif (exists $HTML_Escapes{$seq_argument}) {
1243 7 return $HTML_Escapes{$seq_argument};
1244  
1245 } else {
1246 0 my ($file, $line) = $pod_seq->file_line();
1247 0 warn "Escape sequence $seq_argument not recognised at line $line of file $file\n";
1248 0 return;
1249 }
1250  
1251 } elsif ($seq_command eq 'Z') {
1252  
1253 # Zero width space
1254 0 return '{}';
1255  
1256 } elsif ($seq_command eq 'C') {
1257 5 return "\\texttt{$seq_argument}";
1258  
1259 } elsif ($seq_command eq 'F') {
1260 0 return "\\emph{$seq_argument}";
1261  
1262 } elsif ($seq_command eq 'S') {
1263 # non breakable spaces
1264 0 my $nbsp = '~';
1265  
1266 0 $seq_argument =~ s/\s/$nbsp/g;
1267 0 return $seq_argument;
1268  
1269 } elsif ($seq_command eq 'L') {
1270 4 my $link = new Pod::Hyperlink($seq_argument);
1271  
1272 # undef on failure
1273 4 ▶ unless (defined $link) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $link) 0 4 4
1274 0 carp $@;
1275 0 return;
1276 }
1277  
1278 # Handle internal links differently
1279 4 my $type = $link->type;
1280 4 my $page = $link->page;
1281  
1282 4 ▶ if ($type eq 'section' && $page eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'section' and $page eq '') { } 0 4 4
Condition66%2/3
$type eq "section" and $page eq ""
!ll&&!rl&&r
310
MC/DC0%0/2
$type eq "section" and $page eq ""
$type eq "section" $page eq ""
Truth table66%2/3
A and B
A= $type eq "section"B= $page eq ""
ABresult
0X0
100
111
1283 # Use internal latex reference
1284 0 my $node = $link->node;
1285  
1286 # Convert to a label
1287 0 $node = $self->_create_label($node);
1288  
1289 0 return "\\S\\ref{$node}";
1290  
1291 } else {
1292 # Use default markup for external references
1293 # (although Starlink would use \xlabel)
1294 4 my $markup = $link->markup;
1295 4 my ($file, $line) = $pod_seq->file_line();
1296  
1297 4 return $self->interpolate($link->markup, $line);
1298 }
1299  
1300  
1301  
1302 } elsif ($seq_command eq 'P') {
1303 # Special markup for Pod::Hyperlink
1304 # Replace :: with / - but not sure if I want to do this
1305 # any more.
1306 2 my $link = $seq_argument;
1307 2 $link =~ s|::|/|g;
1308  
1309 2 my $ref = "\\emph{$seq_argument}";
1310 2 return $ref;
1311  
1312 } elsif ($seq_command eq 'Q') {
1313 # Special markup for Pod::Hyperlink
1314 3 return "\\textsf{$seq_argument}";
1315  
1316 } elsif ($seq_command eq 'X') {
1317 # Index entries
1318  
1319 # use \index command
1320 # I will let '!' go through for now
1321 # not sure how sub categories are handled in X<>
1322 0 my $index = $self->_create_index($seq_argument);
1323 0 return "\\index{$index}\n";
1324  
1325 } else {
1326 0 carp "Unknown sequence $seq_command<$seq_argument>";
1327 }
1328  
1329 }
1330  
1331 =back
1332  
1333 =head2 List Methods
1334  
1335 Methods used to handle lists.
1336  
1337 =over 4
1338  
1339 =item B<begin_list>
1340  
1341 Called when a new list is found (via the C<over> directive).
1342 Creates a new C<Pod::List> object and stores it on the
1343 list stack.
1344  
1345 $parser->begin_list($indent, $line_num);
1346  
1347 =cut
1348  
1349 4 ▶sub begin_list {
Subroutine begin_list: called CC=1 SCAR=0.0
Pod documented
1350 4 my $self = shift;
1351 4 my $indent = shift;
1352 4 my $line_num = shift;
1353  
1354 # Indicate that a list should be started for the next item
1355 # need to do this to work out the type of list
1356 4 push ( @{$self->lists}, new Pod::List(-indent => $indent,
1357 -start => $line_num,
1358 -file => $self->input_file,
1359 )
1360 );
1361  
1362 }
1363  
1364 =item B<end_list>
1365  
1366 Called when the end of a list is found (the C<back> directive).
1367 Pops the C<Pod::List> object off the stack of lists and writes
1368 the C<latex> code required to close a list.
1369  
1370 $parser->end_list($line_num);
1371  
1372 =cut
1373  
1374 4 ▶sub end_list {
Subroutine end_list: called CC=4 SCAR=16.3
Pod documented
1375 4 my $self = shift;
1376 4 my $line_num = shift;
1377  
1378 4 ▶ unless (defined $self->lists->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->lists->[-1]) 0 4 4
1379 0 my $file = $self->input_file;
1380 0 warn "No list is active at line $line_num (file=$file). Missing =over?\n";
1381 0 return;
1382 }
1383  
1384 # What to write depends on list type
1385 4 my $type = $self->lists->[-1]->type;
1386  
1387 # Don't write anything if the list type is not set
1388 # iomplying that a list was created but no entries were
1389 # placed in it (eg because of a =begin/=end combination)
1390 4 ▶ $self->_output("\\end{$type}\n")
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and length $type > 0 4 0 4
Condition33%1/3
defined $type and length $type > 0
!ll&&!rl&&r
004
MC/DC0%0/2
defined $type and length $type > 0
defined $type length $type > 0
Truth table33%1/3
A and B
A= defined $typeB= length $type > 0
ABresult
0X0
100
111
1391 if (defined $type && length($type) > 0);
1392
1393 # Clear list
1394 4 pop(@{ $self->lists});
1395  
1396 }
1397  
1398 =item B<add_item>
1399  
1400 Add items to the list. The first time an item is encountered
1401 (determined from the state of the current C<Pod::List> object)
1402 the type of list is determined (ordered, unnumbered or description)
1403 and the relevant latex code issued.
1404  
1405 $parser->add_item($paragraph, $line_num);
1406  
1407 =cut
1408  
1409 14 ▶sub add_item {
Subroutine add_item: called CC=8 SCAR=21.0
Pod documented
1410 14 my $self = shift;
1411 14 my $paragraph = shift;
1412 14 my $line_num = shift;
1413  
1414 14 ▶ unless (defined $self->lists->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->lists->[-1]) 0 14 14
1415 0 my $file = $self->input_file;
1416 0 warn "List has already ended by line $line_num of file $file. Missing =over?\n";
1417 # Replace special chars
1418 # $paragraph = $self->_replace_special_chars($paragraph);
1419 0 $self->_output("$paragraph\n\n");
1420 0 return;
1421 }
1422  
1423 # If paragraphs printing is turned off via =begin/=end or whatever
1424 # simply return immediately
1425 14 ▶ return if $self->{_suppress_all_para};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_suppress_all_para"} 0 14 14
1426  
1427 # Check to see whether we are starting a new lists
1428 14 ▶ if (scalar($self->lists->[-1]->item) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $self->lists->[-1]->item == 0) 4 10 14
1429  
1430 # Examine the paragraph to determine what type of list
1431 # we have
1432 4 $paragraph =~ s/\s+$//;
1433 4 $paragraph =~ s/^\s+//;
1434  
1435 4 my $type;
1436 4 ▶ if (substr($paragraph, 0,1) eq '*') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($paragraph, 0, 1) eq '*') { } 2 2 4
elsif ($paragraph =~ /^\d/) { } 1 1 2
1437 2 $type = 'itemize';
1438 } elsif ($paragraph =~ /^\d/) {
1439 1 $type = 'enumerate';
1440 } else {
1441 1 $type = 'description';
1442 }
1443 4 $self->lists->[-1]->type($type);
1444  
1445 4 $self->_output("\\begin{$type}\n");
1446  
1447 }
1448  
1449 14 my $type = $self->lists->[-1]->type;
1450  
1451 14 ▶ if ($type eq 'description') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'description') { } 5 9 14
1452 # Handle long items - long items do not wrap
1453 # If the string is longer than 40 characters we split
1454 # it into a real item header and some bold text.
1455 5 my $maxlen = 40;
1456 5 my ($hunk1, $hunk2) = $self->_split_delimited( $paragraph, $maxlen );
1457  
1458 # Print the first hunk
1459 5 $self->_output("\n\\item[{$hunk1}] ");
1460  
1461 # and the second hunk if it is defined
1462 5 ▶ if ($hunk2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hunk2) { } 2 3 5
1463 2 $self->_output("\\textbf{$hunk2}");
1464 } else {
1465 # Not there so make sure we have a new line
1466 3 $self->_output("\\mbox{}");
1467 }
1468  
1469 } else {
1470 # If the item was '* Something' or '\d+ something' we still need to write
1471 # out the something. Also allow 1) and 1.
1472 9 my $extra_info = $paragraph;
1473 9 $extra_info =~ s/^(\*|\d+[\.\)]?)\s*//;
1474 9 $self->_output("\n\\item $extra_info");
1475 }
1476  
1477 # Store the item name in the object. Required so that
1478 # we can tell if the list is new or not
1479 14 $self->lists->[-1]->item($paragraph);
1480  
1481 }
1482  
1483 =back
1484  
1485 =head2 Methods for headings
1486  
1487 =over 4
1488  
1489 =item B<head>
1490  
1491 Print a heading of the required level.
1492  
1493 $parser->head($level, $paragraph, $parobj);
1494  
1495 The first argument is the pod heading level. The second argument
1496 is the contents of the heading. The 3rd argument is a Pod::Paragraph
1497 object so that the line number can be extracted.
1498  
1499 =cut
1500  
1501 6 ▶sub head {
Subroutine head: called CC=5 SCAR=18.4
Pod documented
1502 6 my $self = shift;
1503 6 my $num = shift;
1504 6 my $paragraph = shift;
1505 6 my $parobj = shift;
1506  
1507 # If we are replace 'head1 NAME' with a section
1508 # we return immediately if we get it
1509 return
1510 6 ▶ if ($self->{_CURRENT_HEAD1} =~ /^NAME/i && $self->ReplaceNAMEwithSection());
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_CURRENT_HEAD1"} =~ /^NAME/i and $self->ReplaceNAMEwithSection 0 6 6
Condition33%1/3
$self->{"_CURRENT_HEAD1"} =~ /^NAME/i and $self->ReplaceNAMEwithSection
!ll&&!rl&&r
600
MC/DC0%0/2
$self->{"_CURRENT_HEAD1"} =~ /^NAME/i and $self->ReplaceNAMEwithSection
$self->{"_CURRENT_HEAD1"} =~ /^NAME/i $self->ReplaceNAMEwithSection
Truth table33%1/3
A and B
A= $self->{"_CURRENT_HEAD1"} =~ /^NAME/iB= $self->ReplaceNAMEwithSection
ABresult
0X0
100
111
1511  
1512 # Create a label
1513 6 my $label = $self->_create_label($paragraph);
1514  
1515 # Create an index entry
1516 6 my $index = $self->_create_index($paragraph);
1517  
1518 # Work out position in the above array taking into account
1519 # that =head1 is equivalent to $self->Head1Level
1520  
1521 6 my $level = $self->Head1Level() - 1 + $num;
1522  
1523 # Warn if heading to large
1524 6 ▶ if ($num > $#LatexSections) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num > $#Pod::LaTeX::LatexSections) 0 6 6
1525 0 my $line = $parobj->file_line;
1526 0 my $file = $self->input_file;
1527 0 warn "Heading level too large ($level) for LaTeX at line $line of file $file\n";
1528 0 $level = $#LatexSections;
1529 }
1530  
1531 # Check to see whether section should be unnumbered
1532 6 ▶ my $star = ($level >= $self->LevelNoNum ? '*' : '');
Branch: 1 branch
BranchTrueFalseTotal
$level >= $self->LevelNoNum ? : 0 6 6
1533  
1534 # Section
1535 6 $self->_output("\\" .$LatexSections[$level] .$star ."{$paragraph\\label{".$label ."}\\index{".$index."}}\n");
1536  
1537 }
1538  
1539  
1540 =back
1541  
1542 =end __PRIVATE__
1543  
1544 =begin __PRIVATE__
1545  
1546 =head2 Internal methods
1547  
1548 Internal routines are described in this section. They do not form part of the
1549 public interface. All private methods start with an underscore.
1550  
1551 =over 4
1552  
1553 =item B<_output>
1554  
1555 Output text to the output filehandle. This method must be always be called
1556 to output parsed text.
1557  
1558 $parser->_output($text);
1559  
1560 Does not write anything if a =begin is active that should be
1561 ignored.
1562  
1563 =cut
1564  
1565 69 ▶sub _output {
Subroutine _output: called CC=2 SCAR=7.0
1566 69 my $self = shift;
1567 69 my $text = shift;
1568  
1569 69 print { $self->output_handle } $text
1570 69 ▶ unless $self->{_suppress_all_para};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_suppress_all_para"} 69 0 69
1571  
1572 }
1573  
1574  
1575 =item B<_replace_special_chars>
1576  
1577 Subroutine to replace characters that are special in C<latex>
1578 with the escaped forms
1579  
1580 $escaped = $parser->_replace_special_chars($paragraph);
1581  
1582 Need to call this routine before interior_sequences are munged but not
1583 if verbatim. It must be called before interpolation of interior
1584 sequences so that curly brackets and special latex characters inserted
1585 during interpolation are not themselves escaped. This means that < and
1586 > can not be modified here since the text still contains interior
1587 sequences.
1588  
1589 Special characters and the C<latex> equivalents are:
1590  
1591 } \}
1592 { \{
1593 _ \_
1594 $ \$
1595 % \%
1596 & \&
1597 \ $\backslash$
1598 ^ \^{}
1599 ~ \~{}
1600 # \#
1601  
1602 =cut
1603  
1604 58 ▶sub _replace_special_chars {
Subroutine _replace_special_chars: called CC=1 SCAR=0.0
1605 58 my $self = shift;
1606 58 my $paragraph = shift;
1607  
1608 # Replace a \ with $\backslash$
1609 # This is made more complicated because the dollars will be escaped
1610 # by the subsequent replacement. Easiest to add \backslash
1611 # now and then add the dollars
1612 58 $paragraph =~ s/\\/\\backslash/g;
1613  
1614 # Must be done after escape of \ since this command adds latex escapes
1615 # Replace characters that can be escaped
1616 58 $paragraph =~ s/([\$\#&%_{}])/\\$1/g;
1617  
1618 # Replace ^ characters with \^{} so that $^F works okay
1619 58 $paragraph =~ s/(\^)/\\$1\{\}/g;
1620  
1621 # Replace tilde (~) with \texttt{\~{}}
1622 58 $paragraph =~ s/~/\\texttt\{\\~\{\}\}/g;
1623  
1624 # Now add the dollars around each \backslash
1625 58 $paragraph =~ s/(\\backslash)/\$$1\$/g;
1626  
1627 # Convert ------ to -{}-{}-{}-{}-{}-
1628 58 $paragraph =~ s/-(?=-)/-{}/g;
1629  
1630 58 return $paragraph;
1631 }
1632  
1633 =item B<_replace_special_chars_late>
1634  
1635 Replace special characters that can not be replaced before interior
1636 sequence interpolation. See C<_replace_special_chars> for a routine
1637 to replace special characters prior to interpolation of interior
1638 sequences.
1639  
1640 Does the following transformation:
1641  
1642 < $<$
1643 > $>$
1644 | $|$
1645  
1646  
1647 =cut
1648  
1649 58 ▶sub _replace_special_chars_late {
Subroutine _replace_special_chars_late: called CC=1 SCAR=0.0
1650 58 my $self = shift;
1651 58 my $paragraph = shift;
1652  
1653 # < and >
1654 58 $paragraph =~ s/(<|>)/\$$1\$/g;
1655  
1656 # Replace | with $|$
1657 58 $paragraph =~ s'\|'$|$'g;
1658  
1659  
1660 58 return $paragraph;
1661 }
1662  
1663  
1664 =item B<_create_label>
1665  
1666 Return a string that can be used as an internal reference
1667 in a C<latex> document (i.e. accepted by the C<\label> command)
1668  
1669 $label = $parser->_create_label($string)
1670  
1671 If UniqueLabels is true returns a label prefixed by Label()
1672 This can be suppressed with an optional second argument.
1673  
1674 $label = $parser->_create_label($string, $suppress);
1675  
1676 If a second argument is supplied (of any value including undef)
1677 the Label() is never prefixed. This means that this routine can
1678 be called to create a Label() without prefixing a previous setting.
1679  
1680 =cut
1681  
1682 6 ▶sub _create_label {
Subroutine _create_label: called CC=5 SCAR=18.3
1683 6 my $self = shift;
1684 6 my $paragraph = shift;
1685 6 ▶ my $suppress = (@_ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 6 6
1686  
1687 # Remove latex commands
1688 6 $paragraph = $self->_clean_latex_commands($paragraph);
1689  
1690 # Remove non alphanumerics from the label and replace with underscores
1691 # want to protect '-' though so use negated character classes
1692 6 $paragraph =~ s/[^-:\w]/_/g;
1693  
1694 # Multiple underscores will look unsightly so remove repeats
1695 # This will also have the advantage of tidying up the end and
1696 # start of string
1697 6 $paragraph =~ s/_+/_/g;
1698  
1699 # If required need to make sure that the label is unique
1700 # since it is possible to have multiple pods in a single
1701 # document
1702 6 ▶ if (!$suppress && $self->UniqueLabels() && defined $self->Label) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $suppress and $self->UniqueLabels and defined $self->Label) 0 6 6
Condition33%2/6
not $suppress and $self->UniqueLabels and defined $self->Label
!ll&&!rl&&r
060
not $suppress and $self->UniqueLabels
!ll&&!rl&&r
006
MC/DC0%0/3
not $suppress and $self->UniqueLabels and defined $self->Label
not $suppress $self->UniqueLabels defined $self->Label
Truth table25%1/4
not(A) and B and C
A= not $suppressB= $self->UniqueLabelsC= defined $self->Label
ABCresult
0XX0
10X0
1100
1111
1703 0 $paragraph = $self->Label() .'_'. $paragraph;
1704 }
1705  
1706 6 return $paragraph;
1707 }
1708  
1709  
1710 =item B<_create_index>
1711  
1712 Similar to C<_create_label> except an index entry is created.
1713 If C<UniqueLabels> is true, the index entry is prefixed by
1714 the current C<Label> and an exclamation mark.
1715  
1716 $ind = $parser->_create_index($paragraph);
1717  
1718 An exclamation mark is used by C<makeindex> to generate
1719 sub-entries in an index.
1720  
1721 =cut
1722  
1723 6 ▶sub _create_index {
Subroutine _create_index: called CC=5 SCAR=18.7
1724 6 my $self = shift;
1725 6 my $paragraph = shift;
1726 6 ▶ my $suppress = (@_ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 6 6
1727  
1728 # Remove latex commands
1729 6 $paragraph = $self->_clean_latex_commands($paragraph);
1730  
1731 # If required need to make sure that the index entry is unique
1732 # since it is possible to have multiple pods in a single
1733 # document
1734 6 ▶ if (!$suppress && $self->UniqueLabels() && defined $self->Label) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $suppress and $self->UniqueLabels and defined $self->Label) 0 6 6
Condition33%2/6
not $suppress and $self->UniqueLabels and defined $self->Label
!ll&&!rl&&r
060
not $suppress and $self->UniqueLabels
!ll&&!rl&&r
006
MC/DC0%0/3
not $suppress and $self->UniqueLabels and defined $self->Label
not $suppress $self->UniqueLabels defined $self->Label
Truth table25%1/4
not(A) and B and C
A= not $suppressB= $self->UniqueLabelsC= defined $self->Label
ABCresult
0XX0
10X0
1100
1111
1735 0 $paragraph = $self->Label() .'!'. $paragraph;
1736 }
1737  
1738 # Need to replace _ with space
1739 6 $paragraph =~ s/_/ /g;
1740  
1741 6 return $paragraph;
1742  
1743 }
1744  
1745 =item B<_clean_latex_commands>
1746  
1747 Removes latex commands from text. The latex command is assumed to be of the
1748 form C<\command{ text }>. "C<text>" is retained
1749  
1750 $clean = $parser->_clean_latex_commands($text);
1751  
1752 =cut
1753  
1754 12 ▶sub _clean_latex_commands {
Subroutine _clean_latex_commands: called CC=1 SCAR=0.0
1755 12 my $self = shift;
1756 12 my $paragraph = shift;
1757  
1758 # Remove latex commands of the form \text{ }
1759 # and replace with the contents of the { }
1760 # need to make this non-greedy so that it can handle
1761 # "\text{a} and \text2{b}"
1762 # without converting it to
1763 # "a} and \text2{b"
1764 # This match will still get into trouble if \} is present
1765 # This is not vital since the subsequent replacement of non-alphanumeric
1766 # characters will tidy it up anyway
1767 12 $paragraph =~ s/\\\w+{(.*?)}/$1/g;
1768  
1769 12 return $paragraph
1770 }
1771  
1772 =item B<_split_delimited>
1773  
1774 Split the supplied string into two parts at approximately the
1775 specified word boundary. Special care is made to make sure that it
1776 does not split in the middle of some curly brackets.
1777  
1778 e.g. "this text is \textbf{very bold}" would not be split into
1779 "this text is \textbf{very" and " bold".
1780  
1781 ($hunk1, $hunk2) = $self->_split_delimited( $para, $length);
1782  
1783 The length indicates the maximum length of hunk1.
1784  
1785 =cut
1786  
1787 # initially Supplied by hsmyers@sdragons.com
1788 # 10/25/01, utility to split \hbox
1789 # busting lines. Reformatted by TimJ to match module style.
1790 5 ▶sub _split_delimited {
Subroutine _split_delimited: called CC=11 SCAR=24.0
1791 5 my $self = shift;
1792 5 my $input = shift;
1793 5 my $limit = shift;
1794  
1795 # Return immediately if already small
1796 5 ▶ return ($input, '') if length($input) < $limit;
Branch: 1 branch
BranchTrueFalseTotal
if length $input < $limit 3 2 5
1797  
1798 2 my @output;
1799 2 my $s = '';
1800 2 my $t = '';
1801 2 my $depth = 0;
1802 2 my $token;
1803  
1804 2 $input =~ s/\n/ /gm;
1805 2 $input .= ' ';
1806 2 foreach ( split ( //, $input ) ) {
1807 126 $token .= $_;
1808 126 ▶ if (/\{/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/\{/) { } 1 125 126
elsif (/}/) { } 1 124 125
elsif (/ / and $depth == 0) { } 20 207 227
1809 1 $depth++;
1810 } elsif ( /}/ ) {
1811 1 $depth--;
1812 ▶ } elsif ( / / and $depth == 0) {
Condition100%3/3
/ / and $depth == 0
!ll&&!rl&&r
103120
MC/DC100%2/2
/ / and $depth == 0
/ / $depth == 0
Truth table100%3/3
A and B
A= / /B= $depth == 0
ABresult
0X0
100
111
1813 20 ▶ push @output, $token if ( $token and $token ne ' ' );
Branch: 1 branch
BranchTrueFalseTotal
if $token and $token ne " " 20 0 20
Condition33%1/3
$token and $token ne " "
!ll&&!rl&&r
0020
MC/DC0%0/2
$token and $token ne " "
$token $token ne " "
Truth table33%1/3
A and B
A= $tokenB= $token ne " "
ABresult
0X0
100
111
1814 20 $token = '';
1815 }
1816 }
1817  
1818 2 foreach (@output) {
1819 20 ▶ if (length($s) < $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $s < $limit) { } 14 6 20
1820 14 $s .= $_;
1821 } else {
1822 6 $t .= $_;
1823 }
1824 }
1825  
1826 # Tidy up
1827 2 $s =~ s/\s+$//;
1828 2 $t =~ s/\s+$//;
1829 2 return ($s,$t);
1830 }
1831  
1832 =back
1833  
1834 =end __PRIVATE__
1835  
1836 =head1 NOTES
1837  
1838 Compatible with C<latex2e> only. Can not be used with C<latex> v2.09
1839 or earlier.
1840  
1841 A subclass of C<Pod::Select> so that specific pod sections can be
1842 converted to C<latex> by using the C<select> method.
1843  
1844 Some HTML escapes are missing and many have not been tested.
1845  
1846 =head1 SEE ALSO
1847  
1848 L<Pod::Parser>, L<Pod::Select>, L<pod2latex>, L<Pod::Simple>.
1849  
1850 =head1 AUTHORS
1851  
1852 Tim Jenness E<lt>tjenness@cpan.orgE<gt>
1853  
1854 Bug fixes and improvements have been received from: Simon Cozens
1855 E<lt>simon@cozens.netE<gt>, Mark A. Hershberger
1856 E<lt>mah@everybody.orgE<gt>, Marcel Grunauer
1857 E<lt>marcel@codewerk.comE<gt>, Hugh S Myers
1858 E<lt>hsmyers@sdragons.comE<gt>, Peter J Acklam
1859 E<lt>jacklam@math.uio.noE<gt>, Sudhi Herle E<lt>sudhi@herle.netE<gt>,
1860 Ariel Scolnicov E<lt>ariels@compugen.co.ilE<gt>,
1861 Adriano Rodrigues Ferreira E<lt>ferreira@triang.com.brE<gt>,
1862 R. de Vries E<lt>r.de.vries@dutchspace.nlE<gt> and
1863 Dave Mitchell E<lt>davem@iabyn.comE<gt>.
1864  
1865 =head1 COPYRIGHT
1866  
1867 Copyright (C) 2011 Tim Jenness.
1868 Copyright (C) 2000-2004 Tim Jenness. All Rights Reserved.
1869  
1870 This program is free software; you can redistribute it and/or modify
1871 it under the same terms as Perl itself.
1872  
1873 =begin __PRIVATE__
1874  
1875 =head1 REVISION
1876  
1877 $Id$
1878  
1879 =end __PRIVATE__
1880  
1881 =cut
1882  
1883 3 1;
↑ Summary