#!/usr/bin/perl -s

use utf8::all;

our($header,$title,$author);
$title //= 'Title \# FIXME';
$author//= 'Author \# FIXME';

 if($header){ print qq{
\\documentclass[twoside,twocolumn]{book}
\\usepackage[portuges]{babel}
\\usepackage[utf8]{inputenc}
\\usepackage{dici}

\\begin{document}
\\title{$title}
\\author{$author}
\\maketitle
\\chapter{Introduction \\#FIXME}
...
\\clearpage
}
  }

  print "\\begin{dictionary}\n";
  $fl="";
  while(<>){
      chomp();
      next unless /\w/;
      next if /^#/;
      s/(?<!\\)([#%&_])/\\$1/g;          ## protect # % & _
      s/\[/ [\\emph{/;                   ## [a] → [\emph{a}]
      s/\]/}]  /;
      if(/(.*)\t(.*)/){$k=$1; $inf=$2}
      else            {$k=$_; $inf=""}
      if($k =~ /([a-zA-Záéíóúà])/ and uc($1) ne $fl ) {
          $fl = uc($1); 
          print "\\bigletterc{$fl}\n";}
 
      print "\\term{$k}{$inf}\n";
  }
  print "\\end{dictionary}\n";

  if($header){ print '
\end{document}
'
  }

__END__

=head1 NAME

tab2dic - Perl scrit to translate tab separated dictionaries to LaTeX

=head1 SYNOPSIS

 tab2dic [-header]  dict > dict.tex
  option:
    -header           # latex documentclass and friends (def: just the dict.)
    -author="... \and .... \and ..."
    -title="English Rurrian dictionary"

=head1 DESCRIPTION

This command translates tab separated dictionaries to LaTeX.
In the input, each line is a term definition. 
Each term is separated by e tab from the information.

=head Use

  tad2dic -header d.tsv  > d.tex
  ... edit d.tex to add title, author, introdution if necessary
  pdflatex d

=head1 AUTHOR

J.Joao Almeida, jj@di.uminho.pt

=head1 SEE ALSO

perl(1).
dici.sty(1).
latex(1).

=cut      
