All, I forgot about non-dialog uses of quotes (around a word or term, to
emphasize) within a sentence. Thanks, Andre. The attached code takes
care of almost all those cases. To be properly user friendly, this
routine should prompt for input and output file names and should return
a quick error check, separate counts of left and of right curly quotes,
to see if they are equal. Or, fancier, some kind of stack push/pop
routine to check nested levels for mismatched pairs and, when finding
one, generating a location error message. There are too many
possibilities to catch them all automatically. It would probably be
better to keep the replacement algorithm simple, get 99.9% of them, and
then let the user adjust the remaininder to his or her satisfaction.
Just my opinion, of course. Ideally, this routine should be part of the
ascii import code (a switch: convert straight quotes?) or else offered
as a utility tool from within LyX.
#!/usr/bin/perl  -w 

#   straightQuoteConvertToLyX 

#                               by John Wetterau
#                               [EMAIL PROTECTED]

#   converts ascii straight quotes to LyX curly quotes

#   joe.burke.in.lyx is a novel originally written in Word for Windows.
#   It was exported in MS-DOS no lines format, copied to Linux, run 
#   through dos2unix (to convert cr,lf to newline), and then imported 
#   by LyX as an ascii file. The Word export routine replaced all curly 
#   quotes with straight quotes. This perl code takes the lyx document, after
#   it has been imported by LyX, and inserts LyX code for left and right curly
#   quotes at the appropriate places. It may miss some unusual cases, 
#   but it worked fine for me on hundreds of pages of mixed description and 
#   dialog. This code will not work properly on incorrect punctuation.
#   e.g. "Zounds!"  works, gets a left and right curly quote
#        "Zounds"!  does not work, gets 2 left curly quotes

#   Hard coded input and output files cuz I don't
#   know any better (first perl code).
#   You will have to replace the filenames with your own.


$LYXIN = "</home/jw/writing/joe.burke.in.lyx";
$LYXOUT = ">/home/jw/writing/joe.burke.out.lyx";

$LCURLY =  "\n\\begin_inset Quotes eld\n\\end_inset
\n\n";
$RCURLY =  "\n\\begin_inset Quotes erd\n\\end_inset
\n\n";

open LYXIN or die "Can't find file $LYXIN: $!\n";
open LYXOUT or die "Can't find file $LYXOUT: $!\n";

select LYXOUT;

while (<LYXIN>) {

#         substitute for right straight quotes first
     s/\."/.$RCURLY/gxm;
     s/\?"/?$RCURLY/gxm;
     s/,"/,$RCURLY/gxm;
     s/!"/!$RCURLY/gxm;
     s/"\)/$RCURLY)/gxm;
     s/"\ /$RCURLY /gxm;

#         remaining straight quotes should be lefties

     s/"/$LCURLY/gxm;

     print;

}



Reply via email to