2 ## ----------------------------------------------------------------------
3 ## DebianDoc_SGML/Format/LaTeX: SGML conversion specification for LaTeX output format
4 ## ----------------------------------------------------------------------
5 ## Copyright (C) 1998-2001 Ardo van Rangelrooij
6 ## Copyright (C) 1997 Christian Leutloff
8 ## This is free software; see the GNU General Public Licence
9 ## version 2 or later for copying conditions. There is NO warranty.
10 ## ----------------------------------------------------------------------
12 ## ----------------------------------------------------------------------
13 ## package interface definition
14 package DebianDoc_SGML::Format::LaTeX;
16 use vars qw( @ISA @EXPORT );
18 @ISA = ( 'Exporter' );
21 ## ----------------------------------------------------------------------
25 ## ----------------------------------------------------------------------
26 ## paper size definitions
27 my @paper = split( /\s/, `2>/dev/null paperconf -N` );
31 if ( $paper[0] =~ m/[ABC][0-9]/ )
33 $pagespec = $paper[0];
35 elsif ( $paper[0] =~ m/[letter|legal|executive]/ )
37 $paper[0] =~ tr/A-Z/a-z/;
38 $pagespec = "US" . $paper[0];
42 ## ----------------------------------------------------------------------
44 $DebianDoc_SGML::Format::Driver::indent_level = 1;
46 ## ----------------------------------------------------------------------
48 use vars qw( $set_appendix $set_arabic );
50 ## ----------------------------------------------------------------------
51 ## book output subroutines
52 ## ----------------------------------------------------------------------
53 sub _output_start_book
55 my $babel = $DebianDoc_SGML::Format::Driver::i18n{'babel'};
56 output( "\\documentclass[11pt,$babel]{book}\n" );
57 output( "\\usepackage{t1enc}\n" );
58 output( "\\usepackage[$DebianDoc_SGML::Format::Driver::i18n{'inputenc'}]{inputenc}\n" )
59 if length( $DebianDoc_SGML::Format::Driver::i18n{'inputenc'} );
60 output( "\\usepackage{babel}\n" );
62 output( "\\usepackage{helvet}\n" );
63 ## NOTE: below is a temporary solution !!!!!!!!!
64 output( "\\usepackage{times}\n" )
65 if $DebianDoc_SGML::Format::Driver::i18n{ 'inputenc' } ne 'latin2';
67 output( "\\usepackage{vmargin}\n" );
68 output( "\\setpapersize{$pagespec}\n" );
69 output( "\\setmarginsrb{25.4mm}{25.4mm}{25.4mm}{25.4mm}{15pt}{11mm}{0pt}{11mm}\n" );
71 output( "\\usepackage{fancyhdr}\n" );
72 output( "\\pagestyle{fancy}\n" );
73 output( "\\renewcommand{\\chaptermark}[1]{%\n" );
74 output( "\\markboth{\\chaptername\\ \\thechapter.\\ #1}{}}\n" );
75 output( "\\lhead{\\leftmark}\n" );
76 output( "\\chead{}\n" );
77 output( "\\rhead{\\thepage}\n" );
78 output( "\\lfoot{}\n" );
79 output( "\\cfoot{}\n" );
80 output( "\\rfoot{}\n" );
81 output( "\\renewcommand{\\headrulewidth}{0.4pt}\n" );
82 output( "\\renewcommand{\\footrulewidth}{0pt}\n" );
83 output( "\\fancypagestyle{plain}{%\n" );
84 output( "\\lhead{}\n" );
85 output( "\\chead{}\n" );
86 output( "\\rhead{\\thepage}\n" );
87 output( "\\lfoot{}\n" );
88 output( "\\cfoot{}\n" );
89 output( "\\rfoot{}\n" );
90 output( "\\renewcommand{\\headrulewidth}{0.4pt}\n" );
91 output( "\\renewcommand{\\footrulewidth}{0pt}}\n" );
93 output( "\\usepackage{paralist}" );
94 output( "\\usepackage{alltt}\n" );
96 output( "\\usepackage[multiple]{footmisc}\n" );
97 output( "\\usepackage{url}\n" );
98 output( "\\usepackage{varioref}\n" );
99 output( "\\vrefwarning\n" );
100 output( "\\usepackage{hyperref}\n" );
102 output( "\\parindent=0pt\n" );
103 output( "\\setlength{\\parskip}{%\n" );
104 output( "0.5\\baselineskip plus0.1\\baselineskip minus0.1\\baselineskip}\n" );
106 output( "\\begin{document}\n" );
111 output( "\\end{document}\n");
115 ## ----------------------------------------------------------------------
116 ## title page output subroutines
117 ## ----------------------------------------------------------------------
121 output( "\\begin{titlepage}\n" );
123 output( "\\thispagestyle{empty}\n" );
125 output( "\\begin{center}\n" );
126 output( "{\\Huge \\vspace*{2ex} $DebianDoc_SGML::Format::Driver::title \\\\[2ex]}\n" );
127 grep( output( "{\\large $_ } \\\\\n" ), @DebianDoc_SGML::Format::Driver::authors );
128 output( "\\vspace*{1ex} $DebianDoc_SGML::Format::Driver::version \\\\\n" )
129 if length( $DebianDoc_SGML::Format::Driver::version );
130 output( "\\end{center}\n" );
131 if ( length( $DebianDoc_SGML::Format::Driver::abstract ) )
134 output( "\\vspace*{1ex}\n" );
135 output( "\\begin{center}\n" );
136 output( "\\section*{$DebianDoc_SGML::Format::Driver::i18n{ 'abstract' }}\n" );
137 output( "\\end{center}\n" );
138 output( "$DebianDoc_SGML::Format::Driver::abstract\n" );
140 if ( length($DebianDoc_SGML::Format::Driver::copyright ) )
143 output( "\\newpage\n" );
145 output( "\\thispagestyle{empty}\n" );
147 output( "\\vspace*{1ex}\n" );
148 output( "\\vfill\n" );
149 output( "\\section*{$DebianDoc_SGML::Format::Driver::i18n{ 'copyright notice' }}\n" );
151 output( "$DebianDoc_SGML::Format::Driver::copyright\n" );
154 output( "\\end{titlepage}\n" );
156 sub _output_copyrightsummaries
158 output( join( " \\\\\n", @_ ), "\n" );
161 ## ----------------------------------------------------------------------
162 ## table of contents output subroutines
163 ## ----------------------------------------------------------------------
167 output( "\\pagenumbering{roman}\n" );
168 output( "\\tableofcontents\n" );
174 ## ----------------------------------------------------------------------
175 ## section output subroutines
176 ## ----------------------------------------------------------------------
187 if ( $_[1] == -2 && ! $set_appendix )
191 output( "\\appendix\n" );
196 output( "\\chapter" );
200 output( "\\section" );
204 output( "\\subsection" );
208 output( "\\subsubsection" );
212 output( "\\paragraph" );
216 output( "\\subparagraph" );
218 output( "{$_[0]}\n" );
219 output( "\\label{$_[3]}\n" ) if length( $_[3] );
223 output( "\\pagenumbering{arabic}\n" );
227 ## ----------------------------------------------------------------------
228 ## paragraph output subroutines
229 ## ----------------------------------------------------------------------
232 if ( length( $_[0] ) )
234 # Before a new paragraph and after a non-compact example
236 if ! $DebianDoc_SGML::Format::Driver::is_compact
237 && ! $DebianDoc_SGML::Format::Driver::was_compact;
238 $_[0] =~ s/^\s+//gm; # remove leading spaces
239 $_[0] =~ s/\n\n+/\n/g; # no blank lines in paragraphs
244 # This puts a newline between adjacent specials, which doesn't
245 # do anything, but more importantly ensures that there is a
246 # newline before a paragraph which begins with a compact special
248 if ( $DebianDoc_SGML::Format::Driver::is_special
249 && ! $DebianDoc_SGML::Format::Driver::is_compact
250 && $DebianDoc_SGML::Format::Driver::will_be_compact );
253 # The logic here is a bit hairy. Basically, we only change the
254 # \parskip setting if the following is the case:
255 # set to >0 if we're not currently compact, but we're coming out
256 # of a compact state, but we're not about to enter
258 if ( ! $DebianDoc_SGML::Format::Driver::is_compact &&
259 $DebianDoc_SGML::Format::Driver::was_compact &&
260 ( ( $DebianDoc_SGML::Format::Driver::is_special &&
261 ! $DebianDoc_SGML::Format::Driver::will_be_compact) ||
262 ! $DebianDoc_SGML::Format::Driver::is_special ) )
264 output( "\\setlength{\\parskip}{%\n" );
265 output( "0.5\\baselineskip plus0.1\\baselineskip minus0.1\\baselineskip}\n" );
267 # and set to 0 if we're about to enter a compact state, but we aren't
268 # currently compact or leaving a compact state
269 if ( $DebianDoc_SGML::Format::Driver::is_special &&
270 $DebianDoc_SGML::Format::Driver::will_be_compact &&
271 ! $DebianDoc_SGML::Format::Driver::is_compact &&
272 ! $DebianDoc_SGML::Format::Driver::was_compact )
274 output( "\\setlength{\\parskip}{0ex}\n" );
278 ## ----------------------------------------------------------------------
279 ## example output subroutines
280 ## ----------------------------------------------------------------------
283 my $space = $DebianDoc_SGML::Format::Driver::indent_level > 0 ?
284 " " x $DebianDoc_SGML::Format::Driver::indent_level : " ";
285 $_[0] = " $space" . $_[0];
286 $_[0] =~ s/\n/\n $space/g;
288 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
289 output( "\\begin{alltt}\n" );
291 output( "\\end{alltt}\n" );
294 ## ----------------------------------------------------------------------
295 ## footnote output subroutines
296 ## ----------------------------------------------------------------------
299 output( "\\footnote{$_[0]}" );
302 ## ----------------------------------------------------------------------
303 ## comment output subroutines
304 ## ----------------------------------------------------------------------
309 ## ----------------------------------------------------------------------
310 ## list output subroutines
311 ## ----------------------------------------------------------------------
314 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
315 output( $DebianDoc_SGML::Format::Driver::is_compact
316 ? "\\begin{compactitem}\n" : "\\begin{itemize}\n" );
318 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
319 output( $DebianDoc_SGML::Format::Driver::is_compact
320 ? "\\end{compactitem}\n" : "\\end{itemize}\n" );
324 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
325 output( $DebianDoc_SGML::Format::Driver::is_compact
326 ? "\\begin{compactenum}\n" : "\\begin{enumerate}\n" );
328 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
329 output( $DebianDoc_SGML::Format::Driver::is_compact
330 ? "\\end{compactenum}\n" : "\\end{enumerate}\n" );
334 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
335 output( $DebianDoc_SGML::Format::Driver::is_compact
336 ? "\\begin{compactdesc}\n" : "\\begin{description}\n" );
338 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
339 output( $DebianDoc_SGML::Format::Driver::is_compact
340 ? "\\end{compactdesc}\n" : "\\end{description}\n" );
345 sub _output_enumlist_tag
348 sub _output_taglist_tag
351 sub _output_list_item
354 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
355 output( "\\item\n" );
358 sub _output_enumlist_item
361 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
362 output( "\\item\n" );
365 sub _output_taglist_item
368 output( "\n" ) if ! $DebianDoc_SGML::Format::Driver::is_compact;
371 output( "\\item[$_]\n" );
376 ## ----------------------------------------------------------------------
377 ## emph output subroutines
378 ## ----------------------------------------------------------------------
381 output( "\\textit{$_[0]}" );
385 output( "\\textbf{$_[0]}" );
389 output( "\\textit{$_[0]}" );
393 output( "\\texttt{$_[0]}" );
397 output( "\\texttt{$_[0]}" );
401 output( "\\path{$_[0]}" );
405 # Double dashes should be written as --- to get a double dash in
406 # the font. Strange or what?
408 output( "\\texttt{$_[0]}" );
415 ## ----------------------------------------------------------------------
416 ## xref output subroutines
417 ## ----------------------------------------------------------------------
420 output( "`$_[0]' \\vpageref{$_[3]}" );
424 output( "\\texttt{" );
425 output( _sani( $_[0] ) );
426 output( "($_[1])}" );
430 output( ' ' ) if ( $DebianDoc_SGML::Format::Driver::in_author );
431 output( "\\texttt{<$_[0]>}" );
435 output( "\\url{$_[0]}" );
439 output( "\\path{$_[1]}" );
443 output( "\\url{$_[0]}" );
447 output( "\\path{$_[1]}" );
451 output( _sani( $_[1] ) ) if $_[1] ne "";
452 output( " (" ) if $_[1] ne "";
456 output( ")" ) if $_[1] ne "";
459 ## ----------------------------------------------------------------------
460 ## data output subroutines
461 ## ----------------------------------------------------------------------
464 output( _sani( $_[0] ) );
468 output( $DebianDoc_SGML::Format::Driver::sdata_mapping{ $_[0] } )
469 if defined( $DebianDoc_SGML::Format::Driver::sdata_mapping{ $_[0] } );
477 # replace backslash character
478 s/\\/\\(\\backslash\\)/g;
480 # escape command characters
485 # escape command characters
493 # no further replacement in examples
494 return $_ if $DebianDoc_SGML::Format::Driver::is_example;
496 # Don't want this to happen; we can use – and &mdash if we
497 # really want dashes.
503 if ($in_quote && /\"/) {
507 s/\"(.*?)\"/\`\`$1\'\'/g;
508 if (/\"/) { # quotes left
513 # dots should be ellipsis "..."
519 ## ----------------------------------------------------------------------
523 ## ----------------------------------------------------------------------