Next Previous Contents

3. ¡ÒÃãªé SGML-tools

¼ÙéãªéÊÒÁÒöàªç¤äÇ¡óì·Õèà¢Õ¹ã¹ä¿Åì SGML ä´éâ´Â

% sgmlcheck foo.sgml
ã¹·Õè¹Õé¨Ð¢Í¡ÅèÒǶ֧¡ÒÃá»Å§àÍ¡ÊÒÃÀÒÉÒä·ÂẺ SGML ãËéà»ç¹àÍ¡ÊÒÃẺÍ×è¹æ ੾ÒÐẺ Plain Text, HTML áÅÐ LaTeX à·èÒ¹Ñé¹.

3.1 ¡ÒüÅÔµàÍ¡ÊÒÃÀÒÉÒä·ÂẺ Plain Text

¼ÙéãªéÊÒÁÒöá»Å§àÍ¡ÊÒÃÀÒÉÒä·ÂẺ SGML ·Õèà¢Õ¹äÇéà»ç¹áºº Plain Text ä´é´éǤÓÊÑè§

% sgml2txt -c latin foo.sgml
¶éÒäÁèà¡Ô´¢éͼԴ¾ÅÒ´ã´æ ¼Ùéãªé¨Ðä´éä¿ÅìãËÁè·Õèª×èÍ foo.txt ã¹ä´àá·ÍÃÕè·Õè·Ó§Ò¹ÍÂÙè.

3.2 ¡ÒüÅÔµàÍ¡ÊÒÃÀÒÉÒä·ÂẺ HTML

¼ÙéãªéÊÒÁÒöá»Å§àÍ¡ÊÒÃÀÒÉÒä·ÂẺ SGML ·Õèà¢Õ¹äÇéà»ç¹áºº HTML ä´é´éǤÓÊÑè§

% sgml2html foo.sgml
¶éÒäÁèà¡Ô´¢éͼԴ¾ÅÒ´ã´æ ¼Ùéãªé¨Ðä´éä¿ÅìãËÁè·Õèª×èÍ foo.html áÅÐ foo-1.html, foo-2.html, ... ã¹ä´àá·ÍÃÕè·Õè·Ó§Ò¹ÍÂÙè. «Öè§ SGML-tools ¨Ðáºè§à»ç¹ä¿ÅìÂèÍÂæµÒÁËÑÇ¢éÍ(section)·ÕèÃкØäÇé. ã¹·Õè¹Õé¼ÙéãªéäÁèµéͧãÊè option -c latin, àÍ¡ÊÒ÷Õè¼ÅÔµÍÍ¡ÁÒ¨Ðà»ç¹ÃËÑÊ 8-bit «Ö觵ç¡ÑºÃËÑÊ tis-620 ÀÒÉÒä·Â·ÕèãªéÍÂÙ躹ÍÔ¹àµÍÃìà¹çµ·ÑèÇä». à¾×èͤÇÒÁÊдǡ㹡ÒÃãªé§Ò¹ÂÔ觢Öé¹, ¼Ùéà¢Õ¹ä´éà¢Õ¹ Perl script ÊÓËÃѺá»Å§àÍ¡ÊÒà HTML ·Õèà¢Õ¹ã¹ÃÙ»¢Í§ &LATIN_CHAR_NAME; ãËéà»ç¹ÃËÑÊ tis-620 áÅÐÁÕ option ÊÑè§ãËéàÃÕ¡ cttex ÁҵѴ¤Óà¾×èͤÇÒÁÊǧÒÁ´éÇÂ.



#!/usr/bin/perl

################################################################
# sgmlthtml: 
# Run sgml2html and convert latin symbols to Thai characters.
# This program will change, for example, à to "\340".
#
# by Poonlap Veeratanabutr <poon-v@fedu.uec.ac.jp> 
# $Id: sgmlthtml,v 1.1 1998/09/28 06:51:52 poon-v Exp poon-v $
################################################################


sub error {
    print STDERR "usage: $0 [-c] file.sgml\n";
    print STDERR "       -c , use cttex to fill <WBR>\n";
    exit; 
}    

# command line processing.
if( $#ARGV == -1 ){
    &error;
} elsif ( $#ARGV == 0 && $ARGV[0] ne "-c"){
    $file = $ARGV[0];
    $cut = 0;
} elsif ( $#ARGV == 1 ){
    if( $ARGV[0] eq "-c"){
        $cut = 1;
        $file = $ARGV[1];
    } elsif( $ARGV[1] eq "-c"){
        $cut = 1;
        $file = $ARGV[0];
    } else {
        &error;
    }
} else {
    &error;
}

# run sgml2html
if( system( "sgml2html $file" ) != 0 ){
    exit;
}

# lookup table for what to change and not to change
%lookuptbl = (quot, "quot",amp,"amp","lt","lt","gt","gt",copy,"\251",reg,"\256",
              micro,"\265",Agrave,"\300",Aacute,"\301",Acirc,"\302",Atilde,"\303",
              Auml,"\304",Aring,"\305",AElig,"\306",Ccedil,"\307",Egrave,"\310",
              Eacute,"\311",Ecirc,"\312",Euml,"\313",Igrave,"\314",Iacute,"\315",
              Icirc,"\316",Iduml,"\317",ETH,"\320",eth,"\320",Ntilde,"\321",
              Ograve,"\322",Oacute,"\323",Ocirc,"\324",Otilde,"\325",Ouml,"\326",
              Oslash,"\330",Ugrave,"\331",Uacute,"\332",THORN,"THORNÞ",Thorn,"Thron",
              szlig,"\337",agrave,"\340",aacute,"\341",acirc,"\342",atilde,"\343",
              auml,"\344",aring,"\345",aelig,"\346",ccedil,"\347",egrave,"\350",
              eacute,"\351",ecirc,"\352",euml,"\353",igrave,"\354",iacute,"\355",
              icirc,"\356",iuml,"\357",eth,"\360",ntilde,"\361",ograve,"\362",
              oacute,"\363",ocirc,"\364",otilde,"\365",ouml,"\366",oslash,"\370",
              ugrave,"\371",uacute,"\372",ucirc,"\373",uuml,"uuml",yacute,"yacute",
              yuml,"yuml");

# separate directory and file name from the given file name
if( $file =~ /(.*)[\/](.+)$/ ){
    $dir = $1;
    $file = $2;
}
$file =~ s/(.+)\.sgml/$1/; # get rootname

if( length( $dir ) == 0 ){
    opendir( DIR, ".");
} else {
    opendir( DIR, "$dir" );
}
@html = grep {/$file.*\.html$/} readdir( DIR ); # get all related html files
closedir( DIR );

foreach $html_file (@html) {
    print "Processing file $html_file\n";
    open( INPUT, "$html_file");
    open( OUTPUT,">$html_file.tmp" );    
    
    while( <INPUT> ){
        $line = $_;
        $beg = index( $line, "&");
        $end = index( $line, ";");
        while( $beg >= 0  && $end > $beg  ){
            $target = substr( $line, $beg+1, $end-$beg-1);
            $thai = $lookuptbl{ $target };
            if( $target eq $thai ){
                $line = sprintf( "%s%s%s", substr( $line, 0, $beg), '&' . $thai . ';', 
                                substr( $line, $end+1 ));
                
            } else {
                $line = sprintf( "%s%s%s", substr( $line, 0, $beg), $thai, 
                                substr( $line, $end+1 ));
            }
            $beg = index( $line, "&", $beg+1);
            $end = index( $line, ";", $beg);
        }
        print OUTPUT "$line";
    }
    close( INPUT );
    close( OUTPUT );
    if( $cut == 1 ){
        system( "cttex 0 < $html_file.tmp > $html_file" );
        system( "rm -f $html_file.tmp" );
    } else {
        rename( "$html_file.tmp", "$html_file");
    }
}

# EOF

¼ÙéãªéÊÒÁÒöàÃÕ¡¤ÓÊÑè§ sgmlthtml á·¹ sgml2html ÊÓËÃѺàÍ¡ÊÒà SGML ·ÕèÁÕÀÒÉÒä·Âä´é´Ñ§¹Õé

% sgmlthtml foo.sgml -c 
¨Ò¡µÑÇÍÂèÒ§´Ñ§¡ÅèÒÇ, sgmlthtml ¨ÐàÃÕ¡¤ÓÊÑè§ sgml2html «Ö觨мÅÔµä¿ÅìẺ HTML ËÅÒÂä¿Åì. ¨Ò¡¹Ñé¹â»Ãá¡ÃÁ sgmlthtml ¨Ð¾ÂÒÂÒÁà»ÅÕè¹ &LATIN_CHAR_NAME; ãËéà»ç¹ÃËÑÊ tis-620 (¶éÒÁÕ, â´Â»Ã¡µÔ sgml2html ¨Ð¼ÅÔµä¿Åì·Õèà¼ÍÔ­µÃ§µÒÁ tis-620 ÍÂÙèáÅéÇ) áÅÐàÃÕ¡ cttex ÁҵѴ¤Ó(·Ø¡ä¿Åì·Õèà¡ÕèÂÇ¢éͧ¡Ñº foo.sgml) ãËé¡ÒÃáÊ´§¼Åº¹ browser ÊǧÒÁ¢Öé¹. ¡Ò÷Õè¨Ðãªé¤ÓÊÑ觹Õé, ¼ÙéãªéµéͧÁÕâ»Ãá¡ÃÁ cttex ÍÂÙèã¹Ãкº´éÇÂ. ËÒ¡äÁèµéͧ¡ÒÃãËé cttex µÑ´¤Ó, äÁèµéͧãÊè option -c ´Ñ§µÑÇÍÂèÒ§
% sgmlthtml foo.sgml

3.3 ¡ÒüÅÔµàÍ¡ÊÒÃÀÒÉÒä·ÂẺ LaTeX

¼ÙéãªéµéͧÁժشâ»Ãá¡ÃÁ LaTeX áÅеԴµÑé§ÀÒÉÒä·ÂàÃÕºÃéÍÂáÅéǨ֧¨ÐÊÒÁÒöá»Å§àÍ¡ÊÒèҡ SGML à»ç¹ LaTeX ä´é. ¡ÒõԴµÑé§ÀÒÉÒä·Âã¹ LaTeX ÊÒÁÒöÍèÒ¹ä´é¨Ò¡àÍ¡ÊÒà " ¡ÒÃãªéÀÒÉÒä·Â¡Ñº LaTeX".

¼ÙéãªéÊÒÁÒö¼ÅÔµàÍ¡ÊÒà LaTeX(.tex) ·ÕèÁÕÀÒÉÒä·Â¨Ò¡àÍ¡ÊÒÃẺ SGML ä´éâ´Â¤ÓÊÑè§

% sgml2latex --output=tex foo.sgml

¨Ò¡¤ÓÊÑ觢éÒ§º¹ sgml2latex ¨ÐÊÃéÒ§ä¿Åì foo.tex ã¹ä´àá·ÍÃÕè·Õè·Ó§Ò¹ÍÂÙè. ¼ÙéãªéÂѧäÁèÊÒÁÒö¹Óä¿Åì¹Õéä»ãªé¡Ñº LaTeX ä´éâ´ÂµÃ§, ¨Ðµéͧá¡éÊèǹ preamble ¢Í§ä¿Åì¹ÕéàÅ硹éÍ¡è͹¹Óä»ãªé¡Ñº cttex áÅÐ latex µèÍä».

¼ÙéãªéµéͧźºÃ÷ѴµèÍ仹ÕéÍÍ¡¨Ò¡ preamble ¢Í§ä¿Åì foo.tex

\usepackage[latin1]{inputenc}
\usepackage{t1enc}
\usepackage{babel}
áÅÐãÊèºÃ÷ѴµèÍ仹Õé᷹ŧä»á·¹
\usepackage{thai}
¨Ò¡¹Ñ鹨֧ÊÑ觤ÓÊÑè§ cttex áÅÐ latex µÒÁÅӴѺ´Ñ§µÑÇÍÂèÒ§
% cttex < foo.tex > foo_ok.tex
% latex foo_ok.tex

¨ÐàËç¹ä´éÇèÒà¹×èͧ¨Ò¡ SGML-tools äÁèä´é¼ÅÔµÁÒà¾×èÍãªé¡ÑºÀÒÉÒä·Ââ´Â੾ÒШ֧ãªéÂØè§ÂÒ¡. ¼Ùéà¢Õ¹¾ÂÒÂÒÁÅ´¢Ñ鹵͹àËÅèÒ¹Õéâ´Âà¢Õ¹ Perl script ª×èÍ sgmltlatex ·Ó˹éÒ·ÕèµèÒ§æàËÅèÒ¹Õéâ´ÂÍѵâ¹ÁѵÔ.



#!/usr/bin/perl

###############################################################################
#  sgmltlatex:
#  Processing SGML or LaTeX file for Thai language.
#  
#
#  by Poonlap Veeratanabutr <poon-v@fedu.uec.ac.jp>
#  $Id: sgmltools.sgml,v 1.1 1998/09/28 11:26:44 poon-v Exp poon-v $
###############################################################################
sub error {
    print STDERR "$0 - Processing SGML or LaTeX file for Thai language.\n";
    print STDERR "usage: $0 [-[t|d|p] sgml_file] [-l latex_file] \n";
    print STDERR "       -t , create latex_file file from sgml_file\n";
    print STDERR "       -d , create dvi file from sgml_file and leave latex_file\n";
    print STDERR "       -p , create Postscript file and leave latex_file\n";
    print STDERR "       -l , run latex on latex_file\n";
    exit( -1 );
}

# command line processing
if( $#ARGV != 1 ){
    &error;
} elsif ( $ARGV[0] eq "-l" ){
    $option = "l";
} elsif ( $ARGV[0] eq "-t" ){
    $option = "t";
} elsif ( $ARGV[0] eq "-d" ){
    $option = "d";
} elsif ( $ARGV[0] eq "-p" ){
    $option = "p";
} else {
    &error;
}
$file = $ARGV[1];
$tempfile = "$file" . ".tmp";

if( $option ne "l" ){
    if( system( "sgml2latex --output=tex $file" ) != 0 ){
        exit( -1 );
    }
    
# separate directory and file name from the given file name
    if( $file =~ /(.*)[\/](.+)$/ ){
        $dir = $1;
        $file = $2;
    }
    
    if( $file =~ m/(.+)\.sgml$/ ){
        $rootname = "$1";
    } else {
        $rootname = $file;
    }
    $file = $rootname . ".tex";
    
    print "Processing file $file\n";

    open( INPUT, "$file" );
    open( OUTPUT, ">" . "$tempfile" );
    $preamble = 1;
    while( <INPUT> ){
        if( $preamble == 1 ){
            if( /^\\begin\s*{\s*document\s*}\s*$/ ){
                print OUTPUT "\\usepackage{thai}\n";
                $preamble = 0;
                break;
            }
            s/^\\usepackage.*{\s*inputenc.*}\n//;
            s/^\\usepackage.*{\s*babel.*}\n//;
            s/^\\usepackage.*{\s*t1enc.*}\n//;
            print OUTPUT;
            
        } else {
            print OUTPUT;
        }
    }
    close( INPUT );
    close( OUTPUT );

    
} else {
    unless( $file =~ m/(.+)\.tex$/ ){
        print STDERR "$0 needs .tex file\n";
        &error;
    }
    rename( "$file", "$tempfile" );
}


if( $option eq "t" ){
    rename( "$tempfile", "$file" );
    exit( 0 );
} else {
    system( "cttex < $tempfile > $file" );
    system( "latex $file" );
    rename( "$tempfile", "$file" );
} 

if( $option eq "p" ){
    $psfile = "$rootname" . ".ps";
    $dvifile = "$rootname" . ".dvi";
    system( "dvips -o $psfile $dvifile" );
}

exit( 0 );

#EOF
    

¼ÙéãªéÊÒÁÒöàÃÕ¡¤ÓÊÑè§ sgmltlatex á·¹ sgml2latex ÊÓËÃѺàÍ¡ÊÒà SGML ·ÕèÁÕÀÒÉÒä·Â. ¶éÒµéͧ¡ÒüÅÔµàÍ¡ÊÒÃẺ .dvi,

% sgmltlatex -d foo.sgml
ËÒ¡äÁèÁÕ¢éͼԴ¾ÅÒ´à¡Ô´¢Öé¹, ¨Ðä´é foo.dvi ã¹ä´àá·ÍÃÕè·Õè·Ó§Ò¹ÍÂÙè. ¶éÒµéͧ¡ÒüÅÔµä¿ÅìẺ Postscript ãËéÊÑ觤ÓÊÑè§
% sgmltlatex -p foo.sgml
ËÃ×ͶéÒµéͧ¡ÒüÅÔµàÍ¡ÊÒÃẺ LaTeX (.tex) ãËéãªé¤ÓÊÑè§
% sgmltlatex -t foo.sgml
㹡óշÕèãªé option "d" ËÃ×Í "p" ËÃ×Í "t" ¨Ðä´éä¿ÅìẺ LaTeX (.tex) ´éÇÂ. ¼ÙéãªéÊÒÁÒöá¡éä¢à¹×éÍËÒã¹ foo.tex áÅéÇÊÑ觤ÓÊÑ觴ѧ¹Õé
% sgmltlatex -l foo.tex
¤ÓÊÑ觹Õé¨ÐàÃÕ¡ cttex ÁҵѴ¤ÓáÅÐÊ觵èÍãËé latex ¨Ñ´¡ÒÃ. ËÅѧ¨Ò¡¹Ñé¹ sgmltlatex ¨ÐºÑ¹·Ö¡ä¿Åì foo.tex ã¹ÃÙ»·Õè¼ÙéãªéÊÒÁÒöá¡éä¢ä´éÍÕ¡. «Öè§ËÁÒ¤ÇÒÁÇèÒ¼ÙéãªéäÁèÁÕ¤ÇÒÁ¨Óà»ç¹µéͧÊÑè§ cttex áÅÐ latex ¾ÃéÍÁ¡Ñ¹ÍÕ¡.

à¹×èͧ¨Ò¡àÍ¡ÊÒÃẺ LaTeX ·Õè¼ÅÔµâ´Â SGML-tools µéͧ¡Òà linuxdoc-sgml.sty, qwertz.sty, url.sty, epsfig.sty áÅÐ null.sty 㹡ÒüÅÔµä¿Åì .dvi ¼Ùéãªéµéͧ configure â»Ãá¡ÃÁ latex ãËéÃÙéÇèÒä¿ÅìàËÅèÒ¹ÕéÍÂÙè·Õèä˹´éÇÂ. ÇÔ¸Õ·Õè§èÒ·ÕèÊØ´¤×Í¡çÍ»»Õéä¿ÅìàËÅèÒ¹Õé«Öè§ã¹¡Ã³Õ¢Í§¼Ùéà¢Õ¹¨ÐÍÂÙèãµéä´àá·ÍÃÕè /usr/local/lib/sgml-tools/ ÁÒäÇé·Õèä´àá·ÍÃÕè·ÕèÁÕä¿Åì .tex ÍÂÙèËÃ×Í·Ó symbolic link ¡çä´é.


Next Previous Contents