#!/usr/bin/perl -w # Translate docbook to LaTeX. # This handles only a tiny subset of Docbook, but you may find it useful. # Usage: d2latex < filename.sgml > filename.tex # (C) 2001-2008 David A. Wheeler. Licensed under GNU GPL version 2 or later. # See the GNU General Public License (GPL) for more information. sub fix_comment { my $value = shift; chomp($value); $value = $value . "\n"; $value =~ s/([^\n]*)\n/% $1\n/migs; return $value; } # Read entire file into "$_". $old_sep = $/; undef $/; $_ = ; $/ = $old_sep; s/\s*\s*([^<]*)\s*<\/title>\s*/\\chapter{$1}/migs; s/<sect1>\s*<title>\s*([^<]*)\s*<\/title>\s*/\\section{$1}/migs; s/<sect2>\s*<title>\s*([^<]*)\s*<\/title>\s*/\\subsection{$1}/migs; s/<sect3>\s*<title>\s*([^<]*)\s*<\/title>\s*/\\subsubsection{$1}/migs; s/<sect4>\s*<title>\s*([^<]*)\s*<\/title>\s*/\\paragraph{$1}/migs; s/<sect5>\s*<title>\s*([^<]*)\s*<\/title>\s*/\\subparagraph{$1}/migs; s/<\/chapter>/\n/migs; s/<\/sect[1-9]>/\n/migs; s/<blockquote>/\\begin{quotation}/migs; s/<\/blockquote>/\\end{quotation}/migs; s/<itemizedlist>/\\begin{enumerate}/migs; s/<listitem>\s*/\\item\n/migs; s/<\/listitem>//migs; s/<\/itemizedlist>/\\end{enumerate}/migs; s/<emphasis>([^<]*)\s*<\/emphasis>\s*/\\emph{$1}/migs; s/<para>/\n/migs; s/<\/para>/\n/migs; s/<!--(.*?)-->/&fix_comment($1);/migse; # Compress multiple blank lines into a single blank line: s/\n\n\n+/\n\n/migs; print <<EOF;; \\documentclass[twocolumn,twoside,draft]{book} \\title{TITLE HERE} \\author{AUTHOR HERE} \\date{DATE HERE} \\begin{document} \\maketitle EOF print; print "\\end{document}\n"; print "\n";