#!/usr/bin/perl -w
#
# $1.13 2007/09/16$
# setext -> LaTeX converter
#
# (C) 2001 Erik Oliver
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
use strict;
use Carp;
my $numargs = @ARGV;
my $infile;
my $outfile;
my %href;
### indexing and break options
my @command = ('','section','subsection*');
my @breaks = (0,1,0);
if (! -e $infile) {
print STDERR "error: Input, $infile, does not exist\n";
printf
exit -1;
}
if (! -r $infile) {
print STDERR "error: Input, $infile, not readable\n";
exit -1;
}
open INFILE, "<$infile" ||
die "Could not open $infile for reading, $!";
my @data = <INFILE>; # slurp input
chomp @data; # strip newlines
close INFILE;
open OUTFILE,">$outfile" ||
die "Could not open $outfile for writing, $!";
my ($latextitle, $latextitleset, $latexauthor, $latexauthorset, $latexdate, $latexdateset) =
("Title",0,"Author",0,"\\today",0);
my $loop=0;
# title-tt / subhead-tt / subject-tt search
# quote-tt / include-tt / indent-tt / bullet-tt handling
if (/^\.\. / ) {
$data[$loop] = "";
} elsif (/^Subject: (.*$)/) {
if(!$latextitleset) {
$latextitle = &texify($1);
$latextitleset++;
}
$data[$loop] = "";
} elsif (/^From: (.*$)/) {
if(!$latexauthorset) {
$latexauthor = &texify($1);
$latexauthorset++;
}
$data[$loop] = "";
} elsif (/^Date: (.*$)/) {
if(!$latexdateset) {
$latexdate = &texify($1);
$latexdateset++;
}
$data[$loop] = "";
} elsif (/^===/) {
&toc(1,$loop);
$data[$loop] = "";
} elsif (/^---/) {
&toc(2,$loop);
$data[$loop] = "";
} elsif (/^\s{0,2}\* /) {
&lookahead('list',$loop);
} elsif(/^\s{0,2}>\s*/) {
&lookahead('include',$loop);
} elsif (/^ ([^ ])/) {
&lookahead('indent',$loop);
} elsif(/`/) {
# if nothing else and has a `, assume
# multiline verbatim environment
&lookahead('quote',$loop);
} elsif (/\$\$/) {
next;
} elsif (/^\s*$/) {
$data[$loop] = "";
next;
} else {
# possibility of being here if next line
# is === or ---
next if ($loop == $#data);
next if ($data[$loop+1] =~ /^===/);
next if ($data[$loop+1] =~ /^---/);
carp "Unhandled typotag, line = $loop, \"$_\"\n";
}
}
print OUTFILE q|
\documentclass[12pt]{article}
\newif\ifpdf
\ifx\pdfoutput\undefined
\pdffalse % we are not running PDFLaTeX
\else
\pdfoutput=1 % we are running PDFLaTeX
\pdftrue
\fi