"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/doc/preview-dtxdoc.pl" (18 Oct 2020, 4542 Bytes) of package /linux/misc/auctex-12.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "preview-dtxdoc.pl" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 12.2_vs_12.3.

    1 #!/usr/bin/perl
    2 # -*- coding: iso-latin-1-unix; -*-
    3 
    4 # Autoconverter from preview.dtx to preview-dtxdoc.texi
    5 
    6 # Author: Jan-Åke Larsson <jalar@mai.liu.se>
    7 # Maintainer: auctex-devel@gnu.org
    8 
    9 # Copyright (C) 2002, 2005, 2020 Free Software Foundation, Inc.
   10 
   11 # This file is part of AUCTeX.
   12 
   13 # AUCTeX is free software; you can redistribute it and/or modify it
   14 # under the terms of the GNU General Public License as published by
   15 # the Free Software Foundation; either version 3, or (at your option)
   16 # any later version.
   17 
   18 # AUCTeX is distributed in the hope that it will be useful, but
   19 # WITHOUT ANY WARRANTY; without even the implied warranty of
   20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   21 # General Public License for more details.
   22 
   23 # You should have received a copy of the GNU General Public License
   24 # along with AUCTeX; see the file COPYING.  If not, write to the Free
   25 # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   26 # MA 02110-1301, USA.
   27 
   28 # Commentary:
   29 
   30 # Simpleminded autoconverter from preview.dtx to preview-dtxdoc.texi
   31 # run as 'perl preview-dtxdoc.pl ../latex/preview.dtx preview-dtxdoc.texi'
   32 
   33 die "Usage: perl preview-dtxdoc.pl infile outfile" unless ($#ARGV == 1);
   34 open(STDIN, $ARGV[0]) || die "Can't open $ARGV[0] for reading";
   35 open(STDOUT, "> $ARGV[1]") || die "Can't open $ARGV[1] for writing";
   36 
   37 
   38 # Eat header 
   39 MUNGE: while (<STDIN>) {
   40     last MUNGE if /^% *.section/;
   41 }
   42 
   43 # Fish out possible CR characters.
   44 /(\r*)$/;
   45 $cr = $1;
   46 
   47 
   48 # Noindent is used sometimes after \end{quote} (see below) 
   49 $noindent="";
   50 # Quote environments is translated into @example _without_
   51 # @code{..} inside (see below) 
   52 $quote="";
   53 MAIN: while (<STDIN>) {
   54     s/^%//;
   55     s/\\%/%/g;
   56 
   57     # Comment
   58     s/\^\^A.*\n//;
   59 
   60     # Text-substitution macros
   61     s/\@/\@\@/g;
   62     s/\\#/#/g;
   63     s/AUC~?\\TeX[\\ ]?/\@AUCTeX{}/g;
   64     s/\\LaTeX[\\ ]?/\@LaTeX{}/g;
   65     s/\\TeX[\\ ]?/\@TeX{}/g;
   66     s/\\previewlatex[\\ ]?/\@previewlatex{}/g;
   67     s/EPS/\@acronym{EPS}/g;
   68     s/DVI/\@acronym{DVI}/g;
   69     s/~/\@w{ }/g;
   70     s/^ *//;
   71     # Environments
   72     if (s/\\begin\{quote\}/$cr\n\@example/) { 
   73     $quote="yes" }
   74     if (/^\w/) { 
   75     print $noindent } 
   76     $noindent = "";
   77     if (s/\\end\{quote\}/\@end example$cr\n/) { 
   78     $quote=""; 
   79     $noindent="\@noindent$cr\n"  }
   80     s/\\begin\{description\}/$cr\n\@table \@w/;
   81     # Convoluted pattern: handle 
   82     # \item[|...|], \item[\meta{..}] and \item[{|[]|}]
   83     s/\\item\[\{?(.+?[\|\}])\}?\] ?/\@item $1$cr\n/;
   84     s/\\end\{description\}/\@end table$cr\n/;
   85     s/\\begin\{enumerate\}/$cr\n\@enumerate/;
   86     s/\\item /\@item /;
   87     s/\\end\{enumerate\}/\@end enumerate$cr\n/;
   88 
   89     # Formatting (\cmd is special within {quote})
   90     s/\\texttt/\@option/g;
   91     s/\\marg\{([^}]+)\}/\@{\@var{$1}\@}/g;
   92     s/\\meta/\@var/g;
   93     s/\\emph/\@emph/g;
   94     s/\\cmd(\\[\(\)\w]+)/|$1|/g;
   95     s/\\cmd\{(.*?)\}/|$1|/g;
   96     s/\\oarg\{([^}]+?)\}/\[\@var{$1}\]/g;
   97     s/\\char.//g;
   98     s/\\raggedright$cr\n//g;
   99     s/\\DescribeEnv\{(.*?)\} /\@item \\begin\@{$1\@}\@dots{}\\end\@{$1\@}$cr\n/;
  100     if (s/\\DescribeMacro\{(.*?)\}( |$cr\n)/\@item $1$cr\n/) {
  101     # Index entries for two important macros
  102     if (/(\\Preview(Macro|Environment))( |$cr\n)/) {
  103         $_ .= "\@findex $1$cr\n";
  104     }
  105     }
  106 
  107     # ||||||| Hell... I hate bars
  108     # Braces WITHIN bars should be escaped like so: @{ @}
  109     # and |..| translates to @code{..} or @file{..} depending on content
  110     # and to .. if in {quote}
  111     @chunks = split /\|/;
  112     $odd=0;
  113     COMMAND: foreach (@chunks) {
  114     if ($odd==0) {
  115         $odd=1;
  116     } else {
  117         s/\{/\@\{/g;
  118         s/\}/\@\}/g;
  119         if (! $quote) {
  120         if (/[.\/]/) {
  121             $_="\@file\{".$_."\}";
  122         } else {
  123             $_="\@code\{".$_."\}";
  124         }
  125         }
  126         $odd=0;
  127     }
  128     }
  129     $_=join("",@chunks);
  130     # Argh! mixed types occurs in @code{...}@var{..}@file{..}
  131     # Should be @file{...@var{..}..}
  132     s/\@code(\S*?)\}(\S*)\@file\{/\@file$1$2/g;
  133 
  134     # Texinfo @node-ification
  135     if (s/\\section\{(.*)\}/\@subsection $1/) {
  136     if (s/[Oo]ptions/options/) {
  137         $_="\@menu$cr\n" .
  138 "* Package options::$cr\n" .
  139 "* Provided commands::$cr\n" .
  140 "\@end menu$cr\n$cr\n" .
  141 "\@node Package options, Provided commands, The LaTeX style file, The LaTeX style file$cr\n" . $_;
  142     } elsif (s/[Cc]ommands/commands/) {
  143         # \Describe... needs @table
  144         $_= "\@node Provided commands, ,Package options, The LaTeX style file$cr\n" . 
  145         $_ . "$cr\n\@table \@code$cr\n";
  146     }
  147     }
  148     
  149     # Stop here
  150     # \Describe.... needs @end table
  151     if (/^.StopEventually/) {
  152     print "\@end table$cr\n";
  153     last MAIN;
  154     }
  155     print $_;
  156 }