Réindentation du code
authorHugo Villeneuve <hugo@hugovil.com>
Tue, 7 Dec 2021 03:08:55 +0000 (22:08 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Wed, 9 Mar 2022 22:14:43 +0000 (17:14 -0500)
gtx2tex.pl

index 3219060..6d3b2bd 100644 (file)
@@ -7,7 +7,7 @@ use Getopt::Long;
 GetOptions( "output=s" => \$output,
            "lyrics" => \$lyrics,
            "verbose" => \$verbose,
-                       "italian" => \$italian,
+           "italian" => \$italian,
          );
 
 $usage = "This is gtx2tex 2.8
@@ -20,9 +20,8 @@ options:
 --italian        changes chord output to italian notation
                  (La, Si, Do, Re, Mi, Fa, Sol)";
 
-
 if ( ! $ARGV[0] ){
-  die "$usage\n";
+    die "$usage\n";
 }
 
 $verbose && print "This is gtx2tex\n";
@@ -40,9 +39,9 @@ $workdir = cwd;
 $verbose && print "work directory: $workdir\n";
 
 if ( $ARGV[0] =~ /^\// ){
-  $filename = $ARGV[0];
+    $filename = $ARGV[0];
 }else{
-  $filename = $workdir . "/" . $ARGV[0];
+    $filename = $workdir . "/" . $ARGV[0];
 }
 
 $outfilename = basename($filename);
@@ -72,7 +71,7 @@ $define = "";
 
 #load language file
 do "/usr/local/lib/guitartex/language/$language.pl" or die "cannot load language
- file $language.pl\n";
   file $language.pl\n";
 
 
 # Leerzeichen im Dateinamen in Unterstriche ändern
@@ -88,228 +87,228 @@ $chaptercount = 0;
 
 # Eingabedatei zeilenweise bearbeiten
 while ( <CHORDPRO> ) {
-  # Zeichen für Zeilenende abschneiden
-  chomp;
-  # wenn am Anfang der Zeile { steht, handelt es sich um eine Direktive
-  if ( /^{/ ){ directive(); next; }
-       # Leerzeile
-       if ( /^$/ ){ print TEX "$empty_line\n"; next; }
-       # wenn am Anfang der Zeile % oder # steht = Kommentar
-       if ( /^[%#]/ ){ next; }
-              # wenn am Anfang der Zeile \ steht = Latex-Kommando
-              if ( /\\.*/ ){ print TEX "$_\n"; next; }
-              # innerhalb einer Tabulatur
-              if ( $env eq "tab" ) {
-          print TEX "\\footnotesize \\verb!$_! \\normalsize \\newline\n"; next;
-              }
-              crdpro();
-            }
-           # LaTeX-Footer ausgeben
-           latex_footer();
-
-           system ( "rm -f $outfilename.tmp" );
-
-           $output eq "ps" && create_ps();
-           $output eq "pdf" && create_pdf();
-
-
-           sub create_ps {
-             $verbose && print "creating postscript\n";
-             system ( "rm -f *.log *.aux *.ilg *.idx *.ind *.dvi *.toc *.mx1 *.mx2" );
-             system ( "latex --interaction batchmode $outfilename" ) && die "error in first LaTeX run";
-             if ( $document_class eq "book" ){
-                                       system ( "makeindex $outfilename.idx" ) && die "error while creating index";
-             }
-             if ( $musixtex eq "yes" ){
-                                       system ( "musixflx $outfilename" ) && die "error in musixflx run";
-             }
-             if ( $document_class eq "book" or $musixtex eq "yes" ){
-                                       system ( "latex --interaction batchmode $outfilename" ) && die "error in second LaTeX run";
-             }
-             system ( "dvips $outfilename" ) && die "error while converting from dvi to postscript";
-             system ( "rm -f *.log *.aux *.ilg *.idx *.ind *.dvi *.toc *.mx1 *.mx2 $outfilename.tex" );
-           }
-
-
-           sub create_pdf {
-             $verbose && print "creating pdf\n";
-             system ( "rm -f *.tpt *.log *.aux *.ilg *.idx *.ind *.dvi *.toc *.mx? *.mx2" );
-             system ( "pdflatex $outfilename" ) && die "error while creating pdf output";
-             if ( $document_class eq "book" ){
-                                       system ( "makeindex $outfilename.idx" ) && die "error while creating index";
-             }
-             if ( $musixtex eq "yes" ){
-                                       system ( "musixflx $outfilename" ) && die "error in musixflx run";
-             }
-             system ( "pdflatex $outfilename" ) && die "error while creating pdf output";
-             system ( "thumbpdf $outfilename" ) && die "error while creating pdf thumbnails";
-             system ( "pdflatex $outfilename" ) && die "error while creating pdf output";
-             system ( "rm -f *.tpt *.log *.aux *.ilg *.idx *.ind *.dvi *.toc *.mx1 *.mx2 $outfilename.tex" );
-           }
+    # Zeichen für Zeilenende abschneiden
+    chomp;
+    # wenn am Anfang der Zeile { steht, handelt es sich um eine Direktive
+    if ( /^{/ ){ directive(); next; }
+    # Leerzeile
+    if ( /^$/ ){ print TEX "$empty_line\n"; next; }
+    # wenn am Anfang der Zeile % oder # steht = Kommentar
+    if ( /^[%#]/ ){    next; }
+    # wenn am Anfang der Zeile \ steht = Latex-Kommando
+    if ( /\\.*/ ){ print TEX "$_\n"; next; }
+    # innerhalb einer Tabulatur
+    if ( $env eq "tab" ) {
+        print TEX "\\footnotesize \\verb!$_! \\normalsize \\newline\n"; next;
+    }
+    crdpro();
+}
+# LaTeX-Footer ausgeben
+latex_footer();
+
+system ( "rm -f $outfilename.tmp" );
+
+$output eq "ps" && create_ps();
+$output eq "pdf" && create_pdf();
+
+
+sub create_ps {
+    $verbose && print "creating postscript\n";
+    system ( "rm -f *.log *.aux *.ilg *.idx *.ind *.dvi *.toc *.mx1 *.mx2" );
+    system ( "latex --interaction batchmode $outfilename" ) && die "error in first LaTeX run";
+    if ( $document_class eq "book" ){
+        system ( "makeindex $outfilename.idx" ) && die "error while creating index";
+    }
+    if ( $musixtex eq "yes" ){
+        system ( "musixflx $outfilename" ) && die "error in musixflx run";
+    }
+    if ( $document_class eq "book" or $musixtex eq "yes" ){
+        system ( "latex --interaction batchmode $outfilename" ) && die "error in second LaTeX run";
+    }
+    system ( "dvips $outfilename" ) && die "error while converting from dvi to postscript";
+    system ( "rm -f *.log *.aux *.ilg *.idx *.ind *.dvi *.toc *.mx1 *.mx2 $outfilename.tex" );
+}
+
+
+sub create_pdf {
+    $verbose && print "creating pdf\n";
+    system ( "rm -f *.tpt *.log *.aux *.ilg *.idx *.ind *.dvi *.toc *.mx? *.mx2" );
+    system ( "pdflatex $outfilename" ) && die "error while creating pdf output";
+    if ( $document_class eq "book" ){
+        system ( "makeindex $outfilename.idx" ) && die "error while creating index";
+    }
+    if ( $musixtex eq "yes" ){
+        system ( "musixflx $outfilename" ) && die "error in musixflx run";
+    }
+    system ( "pdflatex $outfilename" ) && die "error while creating pdf output";
+    system ( "thumbpdf $outfilename" ) && die "error while creating pdf thumbnails";
+    system ( "pdflatex $outfilename" ) && die "error while creating pdf output";
+    system ( "rm -f *.tpt *.log *.aux *.ilg *.idx *.ind *.dvi *.toc *.mx1 *.mx2 $outfilename.tex" );
+}
 
 
 
 sub crdpro { # Bearbeitung der Zeile aus der Eingabedatei
-       if ( $lyrics ){
-               s/\[.*?\]//g; # Akkorde entfernen
-                       print TEX "$_\\\\\n" unless ( /^\s*$/ );
-       }else{
+    if ( $lyrics ){
+        s/\[.*?\]//g; # Akkorde entfernen
+        print TEX "$_\\\\\n" unless ( /^\s*$/ );
+    }else{
 
-               s/\s/$space/g;                          # alle Leerzeichen durch feste Leerzeichen ersetzen
-               s/(\^)(.*?)(\])/\\\(^\{\2\}\\\)\]/g;    # Ziffern hochstellen
+        s/\s/$space/g;                                 # alle Leerzeichen durch feste Leerzeichen ersetzen
+        s/(\^)(.*?)(\])/\\\(^\{\2\}\\\)\]/g;   # Ziffern hochstellen
 
-               s/\[/\}\\gtxchord{/g;                   # linke Klammer ersetzen
-               s/\]/}{/g;                              # rechte Klammer ersetzen
+        s/\[/\}\\gtxchord{/g;                  # linke Klammer ersetzen
+        s/\]/}{/g;                             # rechte Klammer ersetzen
        #       s/(\})(.*?)(\\)/}{\2}\\/g;              # Text zwischen Akkorden in geschweifte Klammern setzen
-               s/$/}/; # rechte Klammer am Ende der Zeile ergänzen
-               s/^\}//; # rechte Klammer am Anfang der Zeile entfernen
-               if ( $_ !~ /^\\/ ) { s/^/\\gtxchord\{\}\{/ }
-
-               s/#/$sharp/g;                           # Vorzeichen "#" ersetzen
-               s/\{Ab/{A$flat/g;                       # Vorzeichen "b" ersetzen
-               s/\{Bb/{B$flat/g;
-               s/\{Cb/{C$flat/g;
-               s/\{Db/{D$flat/g;
-               s/\{Eb/{E$flat/g;
-               s/\{Fb/{F$flat/g;
-               s/\{Gb/{G$flat/g;
-               if ( $italian ) {
-                       s/gtxchord\{D/gtxchord{Re/g;
-                       s/gtxchord\{E/gtxchord{Mi/g;
-                       s/gtxchord\{F/gtxchord{Fa/g;
-                       s/gtxchord\{G/gtxchord{Sol/g;
-                       s/gtxchord\{A/gtxchord{La/g;
-                       s/gtxchord\{B/gtxchord{Si/g;
-                       s/gtxchord\{H/gtxchord{Si/g;
-                       s/gtxchord\{C/gtxchord{Do/g;
-
-                       s!/D!/Re!g;
-                       s!/E!/Mi!g;
-                       s!/F!/Fa!g;
-                       s!/G!/Sol!g;
-                       s!/A!/La!g;
-                       s!/B!/Si!g;
-                       s!/H!/Si!g;
-                       s!/C!/Do!g;
-
-               }
-               print TEX "$_\\\\\n";
-       }
+        s/$/}/; # rechte Klammer am Ende der Zeile ergänzen
+        s/^\}//; # rechte Klammer am Anfang der Zeile entfernen
+        if ( $_ !~ /^\\/ ) { s/^/\\gtxchord\{\}\{/ }
+
+        s/#/$sharp/g;                          # Vorzeichen "#" ersetzen
+        s/\{Ab/{A$flat/g;                       # Vorzeichen "b" ersetzen
+        s/\{Bb/{B$flat/g;
+        s/\{Cb/{C$flat/g;
+        s/\{Db/{D$flat/g;
+        s/\{Eb/{E$flat/g;
+        s/\{Fb/{F$flat/g;
+        s/\{Gb/{G$flat/g;
+        if ( $italian ) {
+            s/gtxchord\{D/gtxchord{Re/g;
+            s/gtxchord\{E/gtxchord{Mi/g;
+            s/gtxchord\{F/gtxchord{Fa/g;
+            s/gtxchord\{G/gtxchord{Sol/g;
+            s/gtxchord\{A/gtxchord{La/g;
+            s/gtxchord\{B/gtxchord{Si/g;
+            s/gtxchord\{H/gtxchord{Si/g;
+            s/gtxchord\{C/gtxchord{Do/g;
+
+            s!/D!/Re!g;
+            s!/E!/Mi!g;
+            s!/F!/Fa!g;
+            s!/G!/Sol!g;
+            s!/A!/La!g;
+            s!/B!/Si!g;
+            s!/H!/Si!g;
+            s!/C!/Do!g;
+
+        }
+        print TEX "$_\\\\\n";
+    }
 }
 
 
 sub directive{
-       if      ( /{soc}|{start_of_chorus}/ )   { $env = "chorus"; print TEX "$chorus_begin";
-       }elsif  ( /{eoc}|{end_of_chorus/ )      { $env = "normal"; print TEX "$chorus_end";
-       }elsif  ( /{sob}|{start_of_bridge}/ )   { $env = "bridge"; print TEX "$bridge_begin";
-       }elsif  ( /{eob}|{end_of_bridge/ )      { $env = "normal"; print TEX "$bridge_end";
-       }elsif  ( /{soi}|{start_of_instr}/ ) {
-               $env = "instr";
-               print TEX "$instr_begin" unless ( $lyrics );
-       }elsif ( /{eoi}|{end_of_instr/ ) {
-               $env = "normal";
-               print TEX "$instr_end" unless ( $lyrics );
-       }elsif ( /{sot}|{start_of_tab}/ ) {
-               $env = "tab";
-               print TEX "$tab_begin" unless ( $lyrics );
-       }elsif ( /{eot}|{end_of_tab/ ) {
-               $env = "normal";
-               print TEX "$tab_end" unless ( $lyrics );
-       }elsif ( /{np}/ ) {
-               print TEX "$new_page";
-       }elsif ( /{even}/ ) {
-               print TEX "\\ifthenelse{\\isodd{\\thepage}}{}{\\newpage ~}";
-       }elsif ( /{title:|{t:/ ) {
-               s/({.*:)(.+)(})/\2/;
-               if ( $document_class eq "book" ){
-                       print TEX "$define" unless ( $lyrics );
-               }
-               print TEX "%\n%----- New Song -----\n";
-               print TEX "\\newpage\\addcontentsline{toc}{section}{$_}\n";
-               if ( $output eq "pdf" ) { print TEX "\\pdfdest name {$_} fith \\pdfoutline goto name {$_} {$_}" }
-               print TEX "\\begin{center} \\section*{$_}\\end{center}\n";
-               $define="";
-               print TEX "\\index{$_}";
-               $song_title = $_;
-               $verbose && print TEX "\\typeout{$_}";
-       }elsif ( /{subtitle:|{st:/ ) {
-               s/({.*:)(.+)(})/\2/;
-               print TEX "\\index{$_!$song_title}";
-               print TEX "\\begin{center}$_\\end{center}\n";
-       }elsif ( /{margin:|{m:/ ) {
-               s/({.*:)(.+)(})/\2/;
-               print TEX "\\marginpar{$_}\n";
-       }elsif ( /{comment:|{c:/ ) {
-               s/({.*:)(.+)(})/\2/;
-               print TEX "\\textit{$_}\\\\\n" unless ( $lyrics );
-       }elsif ( /{second:|{2:/ ) {
-               s/({.*:)(.+)(})/\2/;
-               s/\s/$space/g;  #Leerzeichen durch feste Leerzeichen ersetzen
-               print TEX "\\colorbox{second_back}{\\textcolor{second_text}{$_}}\\\\\n" unless ( $lyrics );
-       }elsif ( /{chapter:/ ) {
-               $chaptercount++;
-               s/({.*:)(.+)(})/\2/;
-               if ( $document_class eq "book" ) {
-                       print TEX "$define" unless ( $lyrics );
-                       $define = "";
-                       print TEX "\n\\chapter{$_} \\fancyhead[CO]{$_}\n\n";
-                       if ( $output eq "pdf" ) {
-                               $count = $titlecount[$chaptercount];
-                               $verbose && print TEX "% chapter: $_, $count entries\n";
-                               print TEX "\\pdfdest name {$_} fith \\pdfoutline goto name {$_} count $count {$_}"
-                       }
-                       $verbose && print TEX "\\typeout{$_}";
-               };
-       }elsif ( /{define/ ) {
-               s/\{//;
-               s/\}//;
-               s/define//;
-               s/://;
-               s/base-fret//;
-               s/frets//;
-               s/[Xx]/-1/g;
-               s/- /-1/g;
-               s/-$/-1/g;
-               s/-1/x/g;
-               @def = split(" ",$_);
-               @def[0] =~ s/#/\\#/g;
-               #$define .= "\\mbox{\\begin{picture}(20,18)\\special{\"0 0 moveto ";
-               #$define .= "($def[0]) $def[2] $def[3] $def[4] $def[5] $def[6] $def[7] $def[1]";
-               #$define .= " 0 dots}\\end{picture}}\n";
-               $define .= " ~\\gchord{{$def[1]}}{$def[2],$def[3],$def[4],$def[5],$def[6],$def[7]}{$def[0]}";
-       }elsif ( /{guitartab:/ ) {
-               print TEX "\\guitartab\n" unless ( $lyrics );
-               newtab() unless ( $lyrics );
-       }elsif ( /{basstab:/ ) {
-               print TEX "\\basstab\n" unless ( $lyrics );
-               newtab() unless ( $lyrics );
-       }
+    if         ( /{soc}|{start_of_chorus}/ )   { $env = "chorus"; print TEX "$chorus_begin";
+    }elsif     ( /{eoc}|{end_of_chorus/ )      { $env = "normal"; print TEX "$chorus_end";
+    }elsif     ( /{sob}|{start_of_bridge}/ )   { $env = "bridge"; print TEX "$bridge_begin";
+    }elsif     ( /{eob}|{end_of_bridge/ )      { $env = "normal"; print TEX "$bridge_end";
+    }elsif     ( /{soi}|{start_of_instr}/ ) {
+        $env = "instr";
+        print TEX "$instr_begin" unless ( $lyrics );
+    }elsif ( /{eoi}|{end_of_instr/ ) {
+        $env = "normal";
+        print TEX "$instr_end" unless ( $lyrics );
+    }elsif ( /{sot}|{start_of_tab}/ ) {
+        $env = "tab";
+        print TEX "$tab_begin" unless ( $lyrics );
+    }elsif ( /{eot}|{end_of_tab/ ) {
+        $env = "normal";
+        print TEX "$tab_end" unless ( $lyrics );
+    }elsif ( /{np}/ ) {
+        print TEX "$new_page";
+    }elsif ( /{even}/ ) {
+        print TEX "\\ifthenelse{\\isodd{\\thepage}}{}{\\newpage ~}";
+    }elsif ( /{title:|{t:/ ) {
+        s/({.*:)(.+)(})/\2/;
+        if ( $document_class eq "book" ){
+            print TEX "$define" unless ( $lyrics );
+        }
+        print TEX "%\n%----- New Song -----\n";
+        print TEX "\\newpage\\addcontentsline{toc}{section}{$_}\n";
+        if ( $output eq "pdf" ) { print TEX "\\pdfdest name {$_} fith \\pdfoutline goto name {$_} {$_}" }
+        print TEX "\\begin{center} \\section*{$_}\\end{center}\n";
+        $define="";
+        print TEX "\\index{$_}";
+        $song_title = $_;
+        $verbose && print TEX "\\typeout{$_}";
+    }elsif ( /{subtitle:|{st:/ ) {
+        s/({.*:)(.+)(})/\2/;
+        print TEX "\\index{$_!$song_title}";
+        print TEX "\\begin{center}$_\\end{center}\n";
+    }elsif ( /{margin:|{m:/ ) {
+        s/({.*:)(.+)(})/\2/;
+        print TEX "\\marginpar{$_}\n";
+    }elsif ( /{comment:|{c:/ ) {
+        s/({.*:)(.+)(})/\2/;
+        print TEX "\\textit{$_}\\\\\n" unless ( $lyrics );
+    }elsif ( /{second:|{2:/ ) {
+        s/({.*:)(.+)(})/\2/;
+        s/\s/$space/g; #Leerzeichen durch feste Leerzeichen ersetzen
+        print TEX "\\colorbox{second_back}{\\textcolor{second_text}{$_}}\\\\\n" unless ( $lyrics );
+    }elsif ( /{chapter:/ ) {
+        $chaptercount++;
+        s/({.*:)(.+)(})/\2/;
+        if ( $document_class eq "book" ) {
+            print TEX "$define" unless ( $lyrics );
+            $define = "";
+            print TEX "\n\\chapter{$_} \\fancyhead[CO]{$_}\n\n";
+            if ( $output eq "pdf" ) {
+                $count = $titlecount[$chaptercount];
+                $verbose && print TEX "% chapter: $_, $count entries\n";
+                print TEX "\\pdfdest name {$_} fith \\pdfoutline goto name {$_} count $count {$_}"
+            }
+            $verbose && print TEX "\\typeout{$_}";
+        };
+    }elsif ( /{define/ ) {
+        s/\{//;
+        s/\}//;
+        s/define//;
+        s/://;
+        s/base-fret//;
+        s/frets//;
+        s/[Xx]/-1/g;
+        s/- /-1/g;
+        s/-$/-1/g;
+        s/-1/x/g;
+        @def = split(" ",$_);
+        @def[0] =~ s/#/\\#/g;
+        #$define .= "\\mbox{\\begin{picture}(20,18)\\special{\"0 0 moveto ";
+        #$define .= "($def[0]) $def[2] $def[3] $def[4] $def[5] $def[6] $def[7] $def[1]";
+        #$define .= " 0 dots}\\end{picture}}\n";
+        $define .= " ~\\gchord{{$def[1]}}{$def[2],$def[3],$def[4],$def[5],$def[6],$def[7]}{$def[0]}";
+    }elsif ( /{guitartab:/ ) {
+        print TEX "\\guitartab\n" unless ( $lyrics );
+        newtab() unless ( $lyrics );
+    }elsif ( /{basstab:/ ) {
+        print TEX "\\basstab\n" unless ( $lyrics );
+        newtab() unless ( $lyrics );
+    }
 
 }
 
 
 sub newtab {
-       if ( /{guitartab:/ ) { $guitartab="yes" } else { $guitartab ="no" };
-       s/({.*:)(.+)(})/\2/;
-       s/\]\[/\]~~~\[/g;       #fill in fixed spaces between notes
-       s/\_/~~~/g;             #fill in extra space
-       s/\s/~/g;               #replace spaces with fixed spaced
-       s/\]&\[/\]\[/g;         #chord
-       s/\[1;/\[2.5ex;/g;
-       s/\[2;/\[4.5ex;/g;
-       s/\[3;/\[6.5ex;/g;
-       s/\[4;/\[8.5ex;/g;
-       s/\[5;/\[10.5ex;/g;
-       s/\[6;/\[12.5ex;/g;
-       if ( $guitartab eq "yes") {
-               s/\|/~~~\[3.7ex;\|\][5.7ex;\|\][7.7ex;\|\][9.7ex;\|\][11.3ex;\|\]~~~/g;
-       }else{
-               s/\|/~~~\[3.7ex;\|\][5.7ex;\|\][7.3ex;\|\]~~~/g;
-       }
-       s/\[/\\gtxtabs{/g;
-       s/\]/\}/g;
-       s/;/\}\{/g;
-       print TEX "$_\n\n";
+    if ( /{guitartab:/ ) { $guitartab="yes" } else { $guitartab ="no" };
+    s/({.*:)(.+)(})/\2/;
+    s/\]\[/\]~~~\[/g;       #fill in fixed spaces between notes
+    s/\_/~~~/g;             #fill in extra space
+    s/\s/~/g;               #replace spaces with fixed spaced
+    s/\]&\[/\]\[/g;         #chord
+    s/\[1;/\[2.5ex;/g;
+    s/\[2;/\[4.5ex;/g;
+    s/\[3;/\[6.5ex;/g;
+    s/\[4;/\[8.5ex;/g;
+    s/\[5;/\[10.5ex;/g;
+    s/\[6;/\[12.5ex;/g;
+    if ( $guitartab eq "yes") {
+        s/\|/~~~\[3.7ex;\|\][5.7ex;\|\][7.7ex;\|\][9.7ex;\|\][11.3ex;\|\]~~~/g;
+    }else{
+        s/\|/~~~\[3.7ex;\|\][5.7ex;\|\][7.3ex;\|\]~~~/g;
+    }
+    s/\[/\\gtxtabs{/g;
+    s/\]/\}/g;
+    s/;/\}\{/g;
+    print TEX "$_\n\n";
 }
 
 #-------------------------------------------------------------------------------
@@ -321,241 +320,241 @@ sub newtab {
 
 sub latex_header {
 
-  includes();
-
-  $document_class = "article";                 #default document class
-  if ( $output eq "ps" ){$geometry = "dvips, "}                                #default geometry parameter
-  $preamble = "";                                      #default preamble parameter
-  $musixtex = "no";
-  $musixlyr = "no";
-  $tabdefs = "no";
-  $chaptercount = 0;
-  @titlecount = (0);
-
-  open ( CHORDPRO, "$dirname/$outfilename.tmp" ) || die "cannot open input file";
-
-  # read the whole document for settings
-  while ( <CHORDPRO> ){
-    if ( /^{/ ) {      # nur Zeilen mit Direktiven bearbeiten
-      chomp;
-      if ( /{book_title:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $title = $_ ;
-      }elsif ( /{book_author:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $author = $_ ;
-      }elsif ( /{book_date:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $date = $_ ;
-      }elsif ( /{document_class:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $document_class = $_ ;
-       $verbose && print "Document_class: $document_class\n";
-       if ( $document_class ne "book" && $document_class ne "article" ) {
-         die "parameter of directive document_class must be \"book\" or \"article\"\n";
-       }
-      }elsif ( /{font_size:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $font_size = $_ ;
-      }elsif ( /{color_chorus:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $color_chorus = $_ ;
-      }elsif ( /{color_bridge:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $color_bridge = $_ ;
-      }elsif ( /{color_instr:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $color_instr = $_ ;
-      }elsif ( /{color_tab:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $color_tab = $_ ;
-      }elsif ( /{color_second:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $color_second = $_ ;
-      }elsif ( /{color_second_back:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $color_second_back = $_ ;
-      }elsif ( /{geometry:|{g:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $geometry .= "$_," ;
-      }elsif ( /{preamble:|{p:/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $preamble .= "$_\n" ;
-      }elsif ( /{musixtex}/ ) {
-       $musixtex = "yes";
-      }elsif ( /{musixlyr}/ ) {
-       $musixlyr = "yes";
-      }elsif ( /{tabdefs}/ ) {
-       $tabdefs = "yes";
-      }elsif ( /{chapter/ ) {
-       s/({.*:)(.+)(})/\2/;
-       $chaptercount++;
-       push @titlecount, (0);
-      }elsif ( /{title:|{t:/ ) {
-       $titlecount[$chaptercount]++;
-      }
-               }
-           }
-
-$verbose && print "$chaptercount chapters, @titlecount\n";
-
-chop $geometry;                        #delete last comma
-close ( CHORDPRO );
-
-
-
-#open temporary file
-open ( CHORDPRO, "$dirname/$outfilename.tmp" ) || die "cannot open input file";
-
-#print preamble into LaTeX file
-if ( $output eq "pdf" ) { print TEX "\\pdfoutput=1
-\\pdfcompresslevel=9
-\\pdfpageheight=29.7cm
-\\pdfpagewidth=21cm
-\\pdfcatalog  {/PageMode /UseOutlines}
-\\pdfinfo {
-      /Title ($title)
-      /Author ($author)
-      /CreationDate ($date)
-      /Producer (GuitarTeX by Joachim Miltz)
-}
-";
-}
+    includes();
+
+    $document_class = "article";                       #default document class
+    if ( $output eq "ps" ){$geometry = "dvips, "}      #default geometry parameter
+    $preamble = "";                                    #default preamble parameter
+    $musixtex = "no";
+    $musixlyr = "no";
+    $tabdefs = "no";
+    $chaptercount = 0;
+    @titlecount = (0);
+
+    open ( CHORDPRO, "$dirname/$outfilename.tmp" ) || die "cannot open input file";
+
+    # read the whole document for settings
+    while ( <CHORDPRO> ){
+        if ( /^{/ ) {  # nur Zeilen mit Direktiven bearbeiten
+            chomp;
+            if ( /{book_title:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $title = $_ ;
+            }elsif ( /{book_author:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $author = $_ ;
+            }elsif ( /{book_date:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $date = $_ ;
+            }elsif ( /{document_class:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $document_class = $_ ;
+                $verbose && print "Document_class: $document_class\n";
+                if ( $document_class ne "book" && $document_class ne "article" ) {
+                    die "parameter of directive document_class must be \"book\" or \"article\"\n";
+                }
+            }elsif ( /{font_size:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $font_size = $_ ;
+            }elsif ( /{color_chorus:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $color_chorus = $_ ;
+            }elsif ( /{color_bridge:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $color_bridge = $_ ;
+            }elsif ( /{color_instr:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $color_instr = $_ ;
+            }elsif ( /{color_tab:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $color_tab = $_ ;
+            }elsif ( /{color_second:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $color_second = $_ ;
+            }elsif ( /{color_second_back:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $color_second_back = $_ ;
+            }elsif ( /{geometry:|{g:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $geometry .= "$_," ;
+            }elsif ( /{preamble:|{p:/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $preamble .= "$_\n" ;
+            }elsif ( /{musixtex}/ ) {
+                $musixtex = "yes";
+            }elsif ( /{musixlyr}/ ) {
+                $musixlyr = "yes";
+            }elsif ( /{tabdefs}/ ) {
+                $tabdefs = "yes";
+            }elsif ( /{chapter/ ) {
+                s/({.*:)(.+)(})/\2/;
+                $chaptercount++;
+                push @titlecount, (0);
+            }elsif ( /{title:|{t:/ ) {
+                $titlecount[$chaptercount]++;
+            }
+        }
+    }
 
+    $verbose && print "$chaptercount chapters, @titlecount\n";
 
-print TEX "\\documentclass[$languages{$language},";
+    chop $geometry;                    #delete last comma
+    close ( CHORDPRO );
 
-if ( $output eq "pdf" ) { print TEX " pdftex," }
 
-print TEX " $font_size"."pt]{$document_class}
-\\usepackage[$geometry]{geometry}
-\\usepackage[T1]{fontenc}
-";
 
-if ( $language eq "pl" ){
-  print TEX "\\usepackage[latin2]{inputenc}\n"
-}else{
-  print TEX "\\usepackage[latin1]{inputenc}\n"
-}
+    #open temporary file
+    open ( CHORDPRO, "$dirname/$outfilename.tmp" ) || die "cannot open input file";
 
+    #print preamble into LaTeX file
+    if ( $output eq "pdf" ) { print TEX "\\pdfoutput=1
+                                                    \\pdfcompresslevel=9
+                                                    \\pdfpageheight=29.7cm
+                                                    \\pdfpagewidth=21cm
+                                                    \\pdfcatalog  {/PageMode /UseOutlines}
+                              \\pdfinfo {
+                              /Title ($title)
+                                  /Author ($author)
+                                  /CreationDate ($date)
+                                  /Producer (GuitarTeX by Joachim Miltz)
+                                                }
+                              ";
+    }
 
-print TEX "\\usepackage{babel}
-\\usepackage{color}
-\\usepackage{graphicx}
-\\usepackage{ifthen}
-\\usepackage{calc}
-\\usepackage{gchords}
-%
-";
 
+    print TEX "\\documentclass[$languages{$language},";
 
-if ( $output eq "pdf" ){
-print TEX "\\usepackage[pdftex]{thumbpdf}\n";
-}
+    if ( $output eq "pdf" ) { print TEX " pdftex," }
+
+    print TEX " $font_size"."pt]{$document_class}
+    \\usepackage[$geometry]{geometry}
+    \\usepackage[T1]{fontenc}
+    ";
+
+    if ( $language eq "pl" ){
+        print TEX "\\usepackage[latin2]{inputenc}\n"
+    }else{
+        print TEX "\\usepackage[latin1]{inputenc}\n"
+    }
+
+
+    print TEX "\\usepackage{babel}
+    \\usepackage{color}
+    \\usepackage{graphicx}
+    \\usepackage{ifthen}
+    \\usepackage{calc}
+    \\usepackage{gchords}
+    %
+                                                    ";
 
-if ( $musixtex eq "yes" ){
-print TEX "
+
+    if ( $output eq "pdf" ){
+        print TEX "\\usepackage[pdftex]{thumbpdf}\n";
+    }
+
+    if ( $musixtex eq "yes" ){
+        print TEX "
 \\input{musixtex}
 \\input{musixlyr}
 \\input{tabdefs}
 "
-}
+    }
 
-if ( $document_class eq "book" ){
-print TEX "
-\\title{$title}
-\\author{$author}
-\\date{$date}
-\\usepackage{makeidx}
-\\makeindex
-\\usepackage{fancyhdr}
-\\pagestyle{fancy}
-"
-}else{
-print TEX "
+    if ( $document_class eq "book" ){
+        print TEX "
+        \\title{$title}
+        \\author{$author}
+        \\date{$date}
+        \\usepackage{makeidx}
+        \\makeindex
+        \\usepackage{fancyhdr}
+        \\pagestyle{fancy}
+        "
+    }else{
+        print TEX "
 \\pagestyle{empty}
 "};
 
-print TEX "
-%
-%------definition of font colors-----------
-\\definecolor{chorus}{rgb}{$color_chorus}
-\\definecolor{bridge}{rgb}{$color_bridge}
-\\definecolor{instr}{rgb}{$color_instr}
-\\definecolor{tab}{rgb}{$color_tab}
-\\definecolor{second_text}{rgb}{$color_second}
-\\definecolor{second_back}{rgb}{$color_second_back}
-%
-%------definition of environments-------
-\\newenvironment{chorus}{\\color{chorus}}{\\normalcolor}
-\\newenvironment{bridge}{\\color{bridge}}{\\normalcolor}
-\\newenvironment{instr}{\\color{instr}}{\\normalcolor}
-\\newenvironment{gtxtab}{\\color{tab}}{\\normalcolor}
-%
-%------counter for line numbers------
-%\\newcounter{verscnt}[section]
-%\\newcommand{\\vers}{\\stepcounter{verscnt}%
-%\\makebox[0.5cm][r]{\\scriptsize\\theverscnt\\normalsize}%
-%\\makebox[0.5cm]{}}
-%
-\\newcommand{\\gtxchordsize}{\\footnotesize}
-\\setlength{\\parindent}{0pt}
-
-%------PostScript-Header für die Chord-Songs------
-%\\special{header=$libpath/chord-common.ps}
-
-\\sloppy
-\\setlength{\\unitlength}{1mm}
-
-\\newcommand{\\gtxchord}[2]{\\sbox{\\gtxchordbox}{#1}\\sbox{\\textbox}{#2}%
-       \\ifthenelse{\\lengthtest{\\wd\\textbox>\\wd\\gtxchordbox}}%
-       {%
-               \\raisebox{2ex}[2ex][2.5ex]{\\makebox[0pt][l]{\\scriptsize\\bf#1}}#2%
-       }{%
-       \\raisebox{2ex}[2ex][2.5ex]{\\makebox[0pt][l]{\\scriptsize\\bf#1}}\\makebox[\\wd\\gtxchordbox+0.5em][l]{#2}%
-       }%
-}%
-
-\\newcommand{\\guitartab}{%
-\\makebox[0cm][l]{\\raisebox{12.5ex}{\\footnotesize{e}}}%
-\\makebox[0cm][l]{\\raisebox{10.5ex}{\\footnotesize{B}}}%
-\\makebox[0cm][l]{\\raisebox{8.5ex}{\\footnotesize{G}}}%
-\\makebox[0cm][l]{\\raisebox{6.5ex}{\\footnotesize{D}}}%
-\\makebox[0cm][l]{\\raisebox{4.5ex}{\\footnotesize{A}}}%
-\\makebox[0cm][l]{\\raisebox{2.5ex}{\\footnotesize{E}}}%
-~~
-\\makebox[0cm][l]{\\raisebox{13ex}{\\line(1,0){130}}}%
-\\makebox[0cm][l]{\\raisebox{11ex}{\\line(1,0){130}}}%
-\\makebox[0cm][l]{\\raisebox{9ex}{\\line(1,0){130}}}%
-\\makebox[0cm][l]{\\raisebox{7ex}{\\line(1,0){130}}}%
-\\makebox[0cm][l]{\\raisebox{5ex}{\\line(1,0){130}}}%
-\\makebox[0cm][l]{\\raisebox{3ex}{\\line(1,0){130}}}%
-~}
-
-\\newcommand{\\basstab}{%
-\\makebox[0cm][l]{\\raisebox{8.5ex}{\\footnotesize{G}}}%
-\\makebox[0cm][l]{\\raisebox{6.5ex}{\\footnotesize{D}}}%
-\\makebox[0cm][l]{\\raisebox{4.5ex}{\\footnotesize{A}}}%
-\\makebox[0cm][l]{\\raisebox{2.5ex}{\\footnotesize{E}}}%
-~~
-\\makebox[0cm][l]{\\raisebox{9ex}{\\line(1,0){130}}}%
-\\makebox[0cm][l]{\\raisebox{7ex}{\\line(1,0){130}}}%
-\\makebox[0cm][l]{\\raisebox{5ex}{\\line(1,0){130}}}%
-\\makebox[0cm][l]{\\raisebox{3ex}{\\line(1,0){130}}}%
-~}
-
-\\newcommand{\\gtxtabs}[2]{\\makebox[0cm][l]{\\raisebox{#1}{#2}}}
-
-$preamble
-
-%------start of document-----------
-\\begin{document}
-\\newsavebox{\\gtxchordbox}
-\\newsavebox{\\textbox}
-";
-
-if ( $document_class eq "book" ){
-print TEX "
+    print TEX "
+                                                    %
+                                                    %------definition of font colors-----------
+                                                    \\definecolor{chorus}{rgb}{$color_chorus}
+    \\definecolor{bridge}{rgb}{$color_bridge}
+    \\definecolor{instr}{rgb}{$color_instr}
+    \\definecolor{tab}{rgb}{$color_tab}
+    \\definecolor{second_text}{rgb}{$color_second}
+    \\definecolor{second_back}{rgb}{$color_second_back}
+    %
+                                                    %------definition of environments-------
+                                                    \\newenvironment{chorus}{\\color{chorus}}{\\normalcolor}
+    \\newenvironment{bridge}{\\color{bridge}}{\\normalcolor}
+    \\newenvironment{instr}{\\color{instr}}{\\normalcolor}
+    \\newenvironment{gtxtab}{\\color{tab}}{\\normalcolor}
+    %
+                                                    %------counter for line numbers------
+                                                    %\\newcounter{verscnt}[section]
+                                                    %\\newcommand{\\vers}{\\stepcounter{verscnt}%
+                                                                              %\\makebox[0.5cm][r]{\\scriptsize\\theverscnt\\normalsize}%
+                                                                              %\\makebox[0.5cm]{}}
+    %
+                                                    \\newcommand{\\gtxchordsize}{\\footnotesize}
+    \\setlength{\\parindent}{0pt}
+
+    %------PostScript-Header für die Chord-Songs------
+                                                    %\\special{header=$libpath/chord-common.ps}
+
+    \\sloppy
+                                                    \\setlength{\\unitlength}{1mm}
+
+    \\newcommand{\\gtxchord}[2]{\\sbox{\\gtxchordbox}{#1}\\sbox{\\textbox}{#2}%
+    \\ifthenelse{\\lengthtest{\\wd\\textbox>\\wd\\gtxchordbox}}%
+    {%
+         \\raisebox{2ex}[2ex][2.5ex]{\\makebox[0pt][l]{\\scriptsize\\bf#1}}#2%
+                                     }{%
+                                           \\raisebox{2ex}[2ex][2.5ex]{\\makebox[0pt][l]{\\scriptsize\\bf#1}}\\makebox[\\wd\\gtxchordbox+0.5em][l]{#2}%
+                                                                       }%
+                                       }%
+
+                                           \\newcommand{\\guitartab}{%
+                                                                         \\makebox[0cm][l]{\\raisebox{12.5ex}{\\footnotesize{e}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{10.5ex}{\\footnotesize{B}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{8.5ex}{\\footnotesize{G}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{6.5ex}{\\footnotesize{D}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{4.5ex}{\\footnotesize{A}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{2.5ex}{\\footnotesize{E}}}%
+                                                                         ~~
+                                                                         \\makebox[0cm][l]{\\raisebox{13ex}{\\line(1,0){130}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{11ex}{\\line(1,0){130}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{9ex}{\\line(1,0){130}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{7ex}{\\line(1,0){130}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{5ex}{\\line(1,0){130}}}%
+                                                                         \\makebox[0cm][l]{\\raisebox{3ex}{\\line(1,0){130}}}%
+                                                                         ~}
+
+    \\newcommand{\\basstab}{%
+                                \\makebox[0cm][l]{\\raisebox{8.5ex}{\\footnotesize{G}}}%
+                                \\makebox[0cm][l]{\\raisebox{6.5ex}{\\footnotesize{D}}}%
+                                \\makebox[0cm][l]{\\raisebox{4.5ex}{\\footnotesize{A}}}%
+                                \\makebox[0cm][l]{\\raisebox{2.5ex}{\\footnotesize{E}}}%
+                                ~~
+                                \\makebox[0cm][l]{\\raisebox{9ex}{\\line(1,0){130}}}%
+                                \\makebox[0cm][l]{\\raisebox{7ex}{\\line(1,0){130}}}%
+                                \\makebox[0cm][l]{\\raisebox{5ex}{\\line(1,0){130}}}%
+                                \\makebox[0cm][l]{\\raisebox{3ex}{\\line(1,0){130}}}%
+                                ~}
+
+    \\newcommand{\\gtxtabs}[2]{\\makebox[0cm][l]{\\raisebox{#1}{#2}}}
+
+    $preamble
+
+        %------start of document-----------
+        \\begin{document}
+    \\newsavebox{\\gtxchordbox}
+    \\newsavebox{\\textbox}
+    ";
+
+    if ( $document_class eq "book" ){
+        print TEX "
 \\fancyhead
 \\fancyfoot
 \\frontmatter
@@ -566,7 +565,7 @@ print TEX "
 \\fancyhead[LE,RO]{\\thepage}
 "};
 
-print TEX "%\n%\n";
+    print TEX "%\n%\n";
 }
 
 
@@ -577,13 +576,13 @@ print TEX "%\n%\n";
 #-------------------------------------------------------------------------------
 
 sub latex_footer {
-  print TEX "$define\n";
-  if ( $document_class eq "book") {
-    print TEX "\\backmatter";
-    print TEX "\\printindex\n";
-  }
-  print TEX "\\end{document}\n";
-  close ( TEX );
+    print TEX "$define\n";
+    if ( $document_class eq "book") {
+        print TEX "\\backmatter";
+        print TEX "\\printindex\n";
+    }
+    print TEX "\\end{document}\n";
+    close ( TEX );
 }
 
 #-------------------------------------------------------------------------------
@@ -593,22 +592,22 @@ sub latex_footer {
 #-------------------------------------------------------------------------------
 
 sub includes{
-  open ( TMP, ">$dirname/$outfilename.tmp" ) || die "cannot open temporary output file";
-  # open input file
-  open ( CHORDPRO, "$filename" ) || die "cannot open input file";
-  while ( <CHORDPRO> ){
-    if ( /{include:/ ) {               #read only lines with an include directive
-      s/({.*:)(.+)(})/\2/;
-      print TMP "#$_\n#\n";
-      open ( INSERT, "$dirname/$_" ) || die "cannot open file to insert: $_";
-      while ( <INSERT> ){      #insert file to include
-       print TMP;
-      }
-    }else{
-      print TMP;
+    open ( TMP, ">$dirname/$outfilename.tmp" ) || die "cannot open temporary output file";
+    # open input file
+    open ( CHORDPRO, "$filename" ) || die "cannot open input file";
+    while ( <CHORDPRO> ){
+        if ( /{include:/ ) {           #read only lines with an include directive
+            s/({.*:)(.+)(})/\2/;
+            print TMP "#$_\n#\n";
+            open ( INSERT, "$dirname/$_" ) || die "cannot open file to insert: $_";
+            while ( <INSERT> ){        #insert file to include
+                print TMP;
+            }
+        }else{
+            print TMP;
+        }
+        close (INSERT);
     }
-        close (INSERT);
-      }
-      close ( CHORDPRO );
+    close ( CHORDPRO );
     close ( TMP );
-  }
+}