3 # Autoconverter from preview.dtx to preview-dtxdoc.texi
5 # Author: Jan-Åke Larsson <jalar@mai.liu.se>
6 # Maintainer: auctex-devel@gnu.org
8 # Copyright (C) 2002, 2005 Free Software Foundation, Inc.
10 # This file is part of AUCTeX.
12 # AUCTeX is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3, or (at your option)
17 # AUCTeX is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with AUCTeX; see the file COPYING. If not, write to the Free
24 # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
29 # Simpleminded autoconverter from preview.dtx to preview-dtxdoc.texi
30 # run as 'perl preview-dtxdoc.pl ../latex/preview.dtx preview-dtxdoc.texi'
32 die "Usage: perl preview-dtxdoc.pl infile outfile" unless ($#ARGV == 1);
33 open(STDIN, $ARGV[0]) || die "Can't open $ARGV[0] for reading";
34 open(STDOUT, "> $ARGV[1]") || die "Can't open $ARGV[1] for writing";
38 MUNGE: while (<STDIN>) {
39 last MUNGE if /^% *.section/;
42 # Fish out possible CR characters.
47 # Noindent is used sometimes after \end{quote} (see below)
49 # Quote environments is translated into @example _without_
50 # @code{..} inside (see below)
52 MAIN: while (<STDIN>) {
56 # Text-substitution macros
59 s/AUC~?\\TeX[\\ ]?/\@AUCTeX{}/g;
60 s/\\LaTeX[\\ ]?/\@LaTeX{}/g;
61 s/\\TeX[\\ ]?/\@TeX{}/g;
62 s/\\previewlatex[\\ ]?/\@previewlatex{}/g;
63 s/EPS/\@acronym{EPS}/g;
64 s/DVI/\@acronym{DVI}/g;
68 if (s/\\begin\{quote\}/$cr\n\@example/) {
73 if (s/\\end\{quote\}/\@end example$cr\n/) {
75 $noindent="\@noindent$cr\n" }
76 s/\\begin\{description\}/$cr\n\@table \@w/;
77 # Convoluted pattern: handle
78 # \item[|...|], \item[\meta{..}] and \item[{|[]|}]
79 s/\\item\[\{?(.+?[\|\}])\}?\] ?/\@item $1$cr\n/;
80 s/\\end\{description\}/\@end table$cr\n/;
81 s/\\begin\{enumerate\}/$cr\n\@enumerate/;
83 s/\\end\{enumerate\}/\@end enumerate$cr\n/;
85 # Formatting (\cmd is special within {quote})
86 s/\\texttt/\@option/g;
87 s/\\marg\{([^}]+)\}/\@{\@var{$1}\@}/g;
90 s/\\cmd(\\[\(\)\w]+)/|$1|/g;
91 s/\\cmd\{(.*?)\}/|$1|/g;
92 s/\\oarg\{([^}]+?)\}/\[\@var{$1}\]/g;
94 s/\\raggedright$cr\n//g;
95 s/\\DescribeEnv\{(.*?)\} /\@item \\begin\@{$1\@}\@dots{}\\end\@{$1\@}$cr\n/;
96 if (s/\\DescribeMacro\{(.*?)\}( |$cr\n)/\@item $1$cr\n/) {
97 # Index entries for two important macros
98 if (/(\\Preview(Macro|Environment))( |$cr\n)/) {
99 $_ .= "\@findex $1$cr\n";
103 # ||||||| Hell... I hate bars
104 # Braces WITHIN bars should be escaped like so: @{ @}
105 # and |..| translates to @code{..} or @file{..} depending on content
106 # and to .. if in {quote}
107 @chunks = split /\|/;
109 COMMAND: foreach (@chunks) {
117 $_="\@file\{".$_."\}";
119 $_="\@code\{".$_."\}";
126 # Argh! mixed types occurs in @code{...}@var{..}@file{..}
127 # Should be @file{...@var{..}..}
128 s/\@code(\S*?)\}(\S*)\@file\{/\@file$1$2/g;
130 # Texinfo @node-ification
131 if (s/\\section\{(.*)\}/\@subsection $1/) {
132 if (s/[Oo]ptions/options/) {
134 "* Package options::$cr\n" .
135 "* Provided commands::$cr\n" .
136 "\@end menu$cr\n$cr\n" .
137 "\@node Package options, Provided commands, The LaTeX style file, The LaTeX style file$cr\n" . $_;
138 } elsif (s/[Cc]ommands/commands/) {
139 # \Describe... needs @table
140 $_= "\@node Provided commands, ,Package options, The LaTeX style file$cr\n" .
141 $_ . "$cr\n\@table \@code$cr\n";
146 # \Describe.... needs @end table
147 if (/^.StopEventually/) {
148 print "\@end table$cr\n";