#!/usr/bin/env perl use strict; use warnings; use File::Basename qw(dirname); =head1 NAME sty2dtx -- Converts a LaTeX .sty file to a documented .dtx file =head1 VERSION Version: v2.4 - 2022/10/18 =head1 LINKS CTAN: https://ctan.org/pkg/sty2dtx Repository: https://github.com/MartinScharrer/sty2dtx Issues: https://github.com/MartinScharrer/sty2dtx/issues =head1 COPYRIGHT Copyright (c) 2010-2022 Martin Scharrer This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . =head1 DESCRIPTION Converts a .sty file (LaTeX package) to .dtx format (documented LaTeX source), by surrounding macro definitions with 'macro' and 'macrocode' environments. The macro name is automatically inserted as an argument to the 'macro' environemnt. Code lines outside macro definitions are wrapped only in 'macrocode' environments. Empty lines are removed. The script is not thought to be fool proof and 100% accurate but rather as a good start to convert undocumented style files to .dtx files. =head2 Basic Usage perl sty2dtx.pl infile [infile ...] outfile or perl sty2dtx.pl < file.sty > file.dtx =head2 Supported Definitions The following macro definitions are detected when they are at the start of a line (can be prefixed by \global, \long, \protected and/or \outer): \def \edef \gdef \xdef \newcommand{\name} \newcommand*{\name} \newcommand\name \newcommand*\name \renewcommand{\name} \renewcommand*{\name} \renewcommand\name \renewcommand*\name \providecommand{\name} \providecommand*{\name} \providecommand\name \providecommand*\name \@namedef{\name} \@namedef\name The following environment definitions are detected when they are at the start of a line: \newenvironment{name} \renewenvironemnt{name} \provideenvironment{name} The macro and environment definition must either end at the same line or with a 'C<}>' on its own on a line. =head1 USAGE sty2dtx [] [--= ...] [--] [] [] =head2 Files =over 2 =item * can be 'C<->' for STDIN or STDOUT, which is the default if no files are given =item * multiple input files are merged to one output file =back =head2 Variables Variables can be defined using --= or -- and will be used for substitutions in the template file. =head3 Common variables: author, email, maintainer, year (for copyright), version, date, description (of package/class), type (either 'package' default or 'class'), filebase (automatically set from output or input file name), =head2 Options =over 8 =item B<-h> S< > Print this help text =item B<-H> S< > Print extended help =item B<-V> S< > Print version and copyright =item B<-v> S< > Be verbose =item B<-o> F S< > Use given file as output =item B<-O> S< > Overwrite already existing output file(s) =item B<-B> S< > Use basename of single input file for output file =item B<-I> S< > Also create .ins (install) file =item B<-c> S< > Only use code section (like v1.0) =item B<-r> S< > Remove existing 'macro', 'macrocode', etc. environments. =item B<-R> S< > Do not remove existing 'macro', 'macrocode', etc. environments. =item B<-i> F S< > Create .ins file with given name =item B<-t> F