Hi, gregorio devs & users--
One inconvenience about using gregorio is the need to create and
manually edit a "wrapper" TeX file, even for simple cases. The
attached Perl script automates this task.
The script "gprocess" reads the gabc file, finds its attributes (score
title, annotation, etc.), and inserts them into a template
("gprocess-template.tex"), to produce a simple wrapper TeX file.
Then the script runs lamed, dvipdf, and kpdf. I find gprocess
convenient when I'm editing a .gabc file and need to see the score so far.
Feel free to use, adapt, and improve it as you wish (per the GNU GPL).
--Richard Chonak
#!/usr/bin/perl
# gprocess
# a script for 'compiling' gregorio gabc music files
# v0.1
# (c) Richard Chonak, 2008.
# Permission to redistribute is granted to all per the GNU GPL.
my $GABCFILE = $ARGV[0];
my $SCORENAME;
my $ANNOTATION;
my $REFERENCE;
my $OFFICEPART;
my $NAMEFOUND = 0;
my $KEEPSEARCHING = 1;
my $INLINE = "";
my $TEMPLATEFILE=$0;
$TEMPLATEFILE =~ s#/[^/]*$#/gprocess-template.tex#;
my $SCORETEXFILE = $GABCFILE;
$SCORETEXFILE =~ s/gabc$/tex/;
my $SCOREWRAPTEX = $SCORETEXFILE;
$SCOREWRAPTEX =~ s/.tex/-main.tex/;
#### GET THE SCORE TITLE FROM THE GABC FILE ####
if ($GABCFILE =~ m#/#) {
die "File spec must not contain slashes: $GABCFILE\n";
};
open (GABC,"<".$GABCFILE) or die "No such file: $GABCFILE\n";
while ($KEEPSEARCHING == 1 && ($INLINE = <GABC>)) {
if ($INLINE =~ /^name/) {
$SCORENAME = $INLINE;
$SCORENAME =~ s/^.*:\s*//;
$SCORENAME =~ s/\s*;\s*$//;
};
if ($INLINE =~ /^anotation/) {
$ANNOTATION = $INLINE;
$ANNOTATION =~ s/^.*:\s*//;
$ANNOTATION =~ s/\s*;\s*$//;
};
if ($INLINE =~ /^reference/) {
$REFERENCE = $INLINE;
$REFERENCE =~ s/^.*:\s*//;
$REFERENCE =~ s/\s*;\s*$//;
};
if ($INLINE =~ /^office-part/) {
$OFFICEPART = $INLINE;
$OFFICEPART =~ s/^.*:\s*//;
$OFFICEPART =~ s/\s*;\s*$//;
};
if ($INLINE =~ /^%%/) { $KEEPSEARCHING = 0; }
}
close (GABC);
#### READ IN THE TEMPLATE ####
my @TEMPLATELINES;
open (TEMP,"<".$TEMPLATEFILE) or die "Template file not found: $TEMPLATEFILE\n";
@TEMPLATELINES = <TEMP>;
close (TEMP);
#### MAKE SUBSTITUTIONS ####
&do_subst ("XXXX-SCORENAME-XXXX", uc $SCORENAME);
&do_subst ("XXXX-SCORETEXFILE-XXXX", $SCORETEXFILE);
&do_subst ("XXXX-ANNOTATION-XXXX", $ANNOTATION);
&do_subst ("XXXX-OFFICEPART-XXXX", $OFFICEPART);
&do_subst ("XXXX-REFERENCE-XXXX", $REFERENCE);
foreach (@TEMPLATELINES){
s/^.*XXXX.*$//;
};
#### WRITE TEX WRAPPER FILE ####
open (TEXWRAP,">".$SCOREWRAPTEX) or die "Cannot write file $SCOREWRAPTEX\n";
print TEXWRAP @TEMPLATELINES;
close (TEXWRAP);
#### RUN GREGORIO, LATEX, AND KPDF ####
system("gregorio $GABCFILE");
system("lamed $SCOREWRAPTEX");
my $DVIFILE = $SCOREWRAPTEX;
$DVIFILE =~ s/tex$/dvi/;
system ("dvipdf $DVIFILE");
my $PDFFILE = $SCOREWRAPTEX;
$PDFFILE =~ s/tex$/pdf/;
system ("kpdf $PDFFILE");
my $AUXFILE = $DVIFILE;
$AUXFILE =~ s/dvi$/aux/;
unlink $DVIFILE or warn "Could not delete temporary file: $DVIFILE\n";
unlink $AUXFILE or warn "Could not delete temporary file: $AUXFILE\n";
print "\n\nOutput is in $PDFFILE .\n";
exit;
sub do_subst {
my $TAG = $_[0];
my $VAL = $_[1];
foreach (@TEMPLATELINES) {
s/$TAG/$VAL/g;
}
};
\documentclass[12pt, letterpaper]{article}
\usepackage{fullpage}
\usepackage{palatino}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{gregoriotex}
\pagestyle{empty}
\begin{document}
\begin{center}\begin{huge}XXXX-SCORENAME-XXXX\end{huge}\end{center}
\setspaceafterinitial{3.2mm plus 0em minus 0em}
\setspacebeforeinitial{3.2mm plus 0em minus 0em}
\def\greinitialformat#1{%
{\fontsize{43}{43}\selectfont #1}%
}
\setfirstlineaboveinitial{\small \textsc{\textbf{XXXX-ANNOTATION-XXXX}}}{\small
\textsc{\textbf{XXXX-ANNOTATION-XXXX}}}
\commentary{{\small \emph{XXXX-REFERENCE-XXXX}}}
\setgrefactor{17}
\includescore{XXXX-SCORETEXFILE-XXXX}
\end{document}
_______________________________________________
Gregorio-devel mailing list
[email protected]
https://mail.gna.org/listinfo/gregorio-devel