diff --git a/lib/doc/.cvsignore b/lib/doc/.cvsignore index 58070c19b4..dbc62ecc6e 100644 --- a/lib/doc/.cvsignore +++ b/lib/doc/.cvsignore @@ -2,3 +2,4 @@ Makefile.in Makefile LaTeXConfig.lyx Makefile.depend +*.pyc diff --git a/lib/doc/ChangeLog b/lib/doc/ChangeLog index ef4eb189f0..ad51994822 100644 --- a/lib/doc/ChangeLog +++ b/lib/doc/ChangeLog @@ -1,3 +1,18 @@ +2004-10-17 José Matos + + * Depend.pl: removed. + + * depend.py: new script to generate Makefile file to build TOCs. + + * Doc_toc.pl: removed. + + * doc_toc.py: script to extract TOC from documentation files and + create a new files with that information. + + * TOC_top/* : removed. + + * Makefile.am: change accordingly. + 2004-10-11 Martin Vermeer * Customization.lyx: added description of BibTeX, diff --git a/lib/doc/Depend.pl b/lib/doc/Depend.pl deleted file mode 100755 index 4fbaa39c4f..0000000000 --- a/lib/doc/Depend.pl +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/perl -w -# -# Create a file which describes dependencies. The file gets included by the -# Makefile which creates TOC.lyx files -# -# Essentially, this file creates a TOCs target, which makes the -# TOC.lyx for every possible language. Then it creates a target for -# each language's xx_TOC.lyx, which depends on various files. -# E.g., de_TOC.lyx depends on files like de_UserGuide.lyx. If non-English -# files don't exist, TOC.lyx just uses the corresponding English file. - -use strict; - -print <TOC.lyx -# The script tries hard to ignore Footnotes, Notes; ERT and labels in section -# headings. There is even some code to handle nested insets, but no doubt it -# can break on some files. The emphasis has been put on working with current -# docs. - -use strict; - -my $Usage = <) { - last if /\\the_end/; # don't print last line! - print; -} -close HEAD; - -# loop through files; print out headers -my @matches; -my $level; -my $match = ""; -my $sub_match; -my $ignore = 0; # ignore lines (e.g. footnote in a heading) -my @sec_counter; - -while (<>) { - # first few lines of the file - unless (@matches) { - if (/^\\textclass (\w+)/) { - # Hopefully it's book, report, or article - my $class = $1; - @matches = @LyX_classes; - # Article doesn't have Chapters - if ($class eq "article") { - shift @matches; - } - $match = $matches[0]; - $sub_match = $matches[1]; - } - - next; - } - - # Footnotes in a section heading could confuse things! - # And don't bother printing out section labels. - if (/^\\begin_float footnote/ - || /^\\begin_inset OptArg/ - || /^\\begin_inset (Foot|Note|ERT|LatexCommand \\label)/) { - $ignore++; - } - elsif ($ignore && /^\\begin_inset/ ) { - $ignore++; - } - # Unset ignoring. But note that end_inset could be the end of another - # kind of inset! - if ($ignore && /^\\end_(float|inset)/) { - $ignore--; - next; # don't print out \end_float line - } - next if $ignore; - - # Now actually handle title & section headings - if (/^\\layout\s+(\w+)/) { - my $layout = $1; - my $found = 0; # did we find the start of a heading? - - if ($layout eq "Title") { - $found = 1; - @sec_counter = scalar(@matches) x (0); # (re)start section counters - print "\\layout Section*\n"; - - } else { - my $level; - foreach $level (0 .. $#matches) { - if ($layout eq $matches[$level]) { - - # If this is the first subsection of this level, - # start nesting. Top level (level 0) needs no nesting - if ($level && !$sec_counter[$level]) { - print "\\begin_deeper\n"; - } - - # A new section ends any sub- or subsubsections - # below it, etc. - # (Make sure to do this before calling §ion_number! - my $sublevel; - foreach $sublevel ($level+1 .. $#sec_counter) { - if ($sec_counter[$sublevel]) { - print "\\end_deeper\n"; - $sec_counter[$sublevel] = 0; - } - } - - $found = 1; - $sec_counter[$level]++; - my $sec = §ion_number (@sec_counter); - print "\\layout Description\n$sec "; - last; # don't need to try any more matches - } - } - } - - # If we found "Title" or one of the section layouts, then we're - # in a section header. Otherwise, this \layout command ENDS any section - # we might have been in before. - $printing = $found; - - # Rare case of a section header w/ no text after it at the end of a file - } elsif (/^\\the_end/) { - $printing = 0; # obviously we're not in the section header any more! - } else { - print if $printing; - } - - # Cleanup at the end of each file - if (eof) { - # Finish nesting subsections - # I.e., if we had any subsections in this section, end subsectioning - my $level; - foreach $level (1 .. $#sec_counter) { - if ($sec_counter[$level]) { - print "\\end_deeper\n"; - } - } - # So that on next file we check whether it's an article or book - @matches = (); - } - -} - -print "\n\\the_end\n"; - -# Make a (nested) section number -# Input is current section numbers -sub section_number { - my $number = shift; # Highest level section counter - my $index; - foreach $index (@_) { - if ($index) { - $number .= ".$index"; - } else { - # Done creating the number - last; - } - } - return $number; -} diff --git a/lib/doc/Makefile.am b/lib/doc/Makefile.am index 2fb563da11..93daa4ff68 100644 --- a/lib/doc/Makefile.am +++ b/lib/doc/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/config/common.am DISTCLEANFILES += LyXConfig.lyx LaTeXConfig.lyx Makefile.depend -EXTRA_DIST = Depend.pl Doc_toc.pl LyXConfig.lyx.in README.Documentation $(docfiles) $(toc_DATA) +EXTRA_DIST = depend.py doc_toc.py LyXConfig.lyx.in README.Documentation $(docfiles) docfiles = \ cs_TOC.lyx \ @@ -89,16 +89,6 @@ doc_DATA = \ $(docfiles) \ LaTeXConfig.lyx -tocdir = $(docdir)/TOC_top -toc_DATA = \ - TOC_top/da_TOC_top.lyx \ - TOC_top/de_TOC_top.lyx \ - TOC_top/fr_TOC_top.lyx \ - TOC_top/ru_TOC_top.lyx \ - TOC_top/sl_TOC_top.lyx \ - TOC_top/TOC_top.lyx - - # TODO can we instead just #include the DEPENDFILE in this Makefile? # problem with this is that the DEPENDFILE that's included won't be the updated # one. JMarc should know how to handle this. @@ -109,6 +99,6 @@ TOCs : depend make -f $(DEPENDFILE) TOCs depend: - perl Depend.pl > $(DEPENDFILE) + python depend.py > $(DEPENDFILE) .PHONY: depend diff --git a/lib/doc/TOC_top/TOC_top.lyx b/lib/doc/TOC_top/TOC_top.lyx deleted file mode 100644 index 332e4e031a..0000000000 --- a/lib/doc/TOC_top/TOC_top.lyx +++ /dev/null @@ -1,30 +0,0 @@ -#LyX 1.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 221 -\textclass article -\language english -\inputencoding default -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize Default -\paperpackage a4 -\use_geometry 0 -\use_amsmath 0 -\use_natbib 0 -\use_numerical_citations 0 -\paperorientation portrait -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\quotes_times 2 -\papercolumns 1 -\papersides 1 -\paperpagestyle default - -\layout Title - -LyX Documentation Table of Contents -\the_end diff --git a/lib/doc/TOC_top/da_TOC_top.lyx b/lib/doc/TOC_top/da_TOC_top.lyx deleted file mode 100644 index 1c35b66756..0000000000 --- a/lib/doc/TOC_top/da_TOC_top.lyx +++ /dev/null @@ -1,30 +0,0 @@ -#LyX 1.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 221 -\textclass article -\language danish -\inputencoding latin1 -\fontscheme default -\graphics none -\paperfontsize 10 -\spacing single -\papersize Default -\paperpackage widemarginsa4 -\use_geometry 0 -\use_amsmath 0 -\use_natbib 0 -\use_numerical_citations 0 -\paperorientation portrait -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation skip -\defskip medskip -\quotes_language german -\quotes_times 2 -\papercolumns 1 -\papersides 1 -\paperpagestyle default - -\layout Title - -Indholdsfortegnelse over LyX's dokumentation -\the_end diff --git a/lib/doc/TOC_top/de_TOC_top.lyx b/lib/doc/TOC_top/de_TOC_top.lyx deleted file mode 100644 index 3ab04d9627..0000000000 --- a/lib/doc/TOC_top/de_TOC_top.lyx +++ /dev/null @@ -1,30 +0,0 @@ -#LyX 1.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 221 -\textclass article -\language german -\inputencoding latin1 -\fontscheme default -\graphics none -\paperfontsize 10 -\spacing single -\papersize Default -\paperpackage widemarginsa4 -\use_geometry 0 -\use_amsmath 0 -\use_natbib 0 -\use_numerical_citations 0 -\paperorientation portrait -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation skip -\defskip medskip -\quotes_language german -\quotes_times 2 -\papercolumns 1 -\papersides 1 -\paperpagestyle default - -\layout Title - -Inhaltsverzeichnis LyX Dokumentation -\the_end diff --git a/lib/doc/TOC_top/fr_TOC_top.lyx b/lib/doc/TOC_top/fr_TOC_top.lyx deleted file mode 100644 index f017ee5b63..0000000000 --- a/lib/doc/TOC_top/fr_TOC_top.lyx +++ /dev/null @@ -1,30 +0,0 @@ -#LyX 1.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 221 -\textclass article -\language french -\inputencoding default -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize Default -\paperpackage a4 -\use_geometry 0 -\use_amsmath 0 -\use_natbib 0 -\use_numerical_citations 0 -\paperorientation portrait -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\quotes_times 2 -\papercolumns 1 -\papersides 1 -\paperpagestyle default - -\layout Title - -Plan de la documentation -\the_end diff --git a/lib/doc/TOC_top/ru_TOC_top.lyx b/lib/doc/TOC_top/ru_TOC_top.lyx deleted file mode 100644 index 4001d1d138..0000000000 --- a/lib/doc/TOC_top/ru_TOC_top.lyx +++ /dev/null @@ -1,30 +0,0 @@ -#LyX 1.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 221 -\textclass article -\language russian -\inputencoding koi8-r -\fontscheme default -\graphics default -\paperfontsize default -\spacing single -\papersize Default -\paperpackage a4 -\use_geometry 0 -\use_amsmath 0 -\use_natbib 0 -\use_numerical_citations 0 -\paperorientation portrait -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation indent -\defskip medskip -\quotes_language english -\quotes_times 2 -\papercolumns 1 -\papersides 1 -\paperpagestyle default - -\layout Title - -LyX Documentation Table of Contents -\the_end diff --git a/lib/doc/TOC_top/sl_TOC_top.lyx b/lib/doc/TOC_top/sl_TOC_top.lyx deleted file mode 100644 index 7c15b114b9..0000000000 --- a/lib/doc/TOC_top/sl_TOC_top.lyx +++ /dev/null @@ -1,33 +0,0 @@ -#LyX 1.3 created this file. For more info see http://www.lyx.org/ -\lyxformat 221 -\textclass article -\options dvips -\language slovene -\inputencoding latin2 -\fontscheme default -\graphics dvips -\paperfontsize default -\spacing single -\papersize a4paper -\paperpackage a4 -\use_geometry 1 -\use_amsmath 0 -\use_natbib 0 -\use_numerical_citations 0 -\paperorientation portrait -\headsep 0pt -\footskip 0pt -\secnumdepth 3 -\tocdepth 3 -\paragraph_separation skip -\defskip medskip -\quotes_language german -\quotes_times 2 -\papercolumns 1 -\papersides 1 -\paperpagestyle default - -\layout Title - -Kazalo dokumentacije LyXa -\the_end diff --git a/lib/doc/depend.py b/lib/doc/depend.py new file mode 100644 index 0000000000..8fdb70c3de --- /dev/null +++ b/lib/doc/depend.py @@ -0,0 +1,88 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-1 -*- +# This file is part of the LyX Documentation +# Copyright (C) 2004 José Matos +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# This script creates a "master table of contents" for a set of LyX docs. +# It does so by going through the files and printing out all of the +# chapter, section, and sub(sub)section headings out. (It numbers the +# sections sequentially; hopefully noone's using Section* in the docs.) + +import sys +import os + +import re +from glob import glob + +possible_documents = ("Intro", "FAQ", "Tutorial", "UserGuide", "Extended", "Customization") +lang_pattern = re.compile('^([a-z]{2})_') + +def documents(prefix): + result = [] + for file in possible_documents: + fname = prefix + file + '.lyx' + if os.access(fname, os.F_OK): + result.append(fname) + return result + + +def main(argv): + print """# This is a Makefile for the TOC.lyx files. +# It was automatically generated by %s +# +# First come the rules for each xx_TOC.lyx file. Then comes the +# TOCs target, which prints all the TOC files. +""" % argv[0] + + # What are the languages available? And its documents? + languages = {} + for file in glob('*'): + lang = lang_pattern.match(file) + if lang: + if lang.group(1) not in languages: + languages[lang.group(1)] = [file] + else: + languages[lang.group(1)].append(file) + + # sort languages alphabetically + langs = languages.keys() + langs.sort() + + # The default language is english and doesn't need any prefix + print 'TOC.lyx:', '.lyx '.join(possible_documents) + '.lyx' + print '\tpython doc_toc.py' + print + tocs = ['TOC.lyx'] + + # Write rules for other languages + for lang in langs: + toc_name = lang + '_TOC.lyx' + tocs.append(toc_name) + + languages[lang].remove(toc_name) + + print toc_name + ':', ' '.join(languages[lang]) + print '\tpython doc_toc.py %s' % lang + print + + # Write meta-rule to call all the other rules + print 'TOCs:', ' '.join(tocs) + print '\t@echo Made TOCs succesfully.' + + +if __name__ == "__main__": + main(sys.argv) diff --git a/lib/doc/doc_toc.py b/lib/doc/doc_toc.py new file mode 100755 index 0000000000..7277d69837 --- /dev/null +++ b/lib/doc/doc_toc.py @@ -0,0 +1,125 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-1 -*- +# This file is part of the LyX Documentation +# Copyright (C) 2004 José Matos +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# This script creates a "master table of contents" for a set of LyX docs. +# It does so by going through the files and printing out all of the +# chapter, section, and sub(sub)section headings out. (It numbers the +# sections sequentially; hopefully noone's using Section* in the docs.) + +import sys +import os + +sys.path.insert(0,"../lyx2lyx") +import parser_tools +import LyX +import depend + +# Specific language information +# info["isoname"] = (language, language_quotes, enconding, TOC_translated) +info = { 'da' : ('danish', 'german', 'latin1', "Indholdsfortegnelse over LyX's dokumentation"), + 'de' : ('german', 'german', 'latin1', "Inhaltsverzeichnis LyX Dokumentation"), + 'fr' : ('french', 'french', 'latin1', "Plan de la documentation"), + 'ru' : ('russian', 'english', 'koi8-r', "LyX Documentation Table of Contents"), + 'sl' : ('slovene', 'german', 'latin2', "Kazalo dokumentacije LyXa"), + 'en' : ('english', 'english', 'latin1', "LyX Documentation Table of Contents")} + +def usage(pname): + print """Usage: %s [lang] + + lang is the language to build the TOC file, if not present use english. +""" % pname + + +transform_table = {'Title' : 'Section*', 'Chapter': 'Enumerate', + 'Section':'Enumerate', 'Subsection': 'Enumerate', + 'Subsubsection' : 'Enumerate'} + +def build_from_toc(par_list): + if not par_list: + return [] + + if par_list[0].name == 'Title': + par = par_list[0] + par.name = transform_table[par.name] + + if len(par_list) == 1: + return par_list + + for i in range(1, len(par_list)): + if par_list[i].name == 'Title': + return [par] + \ + build_from_toc(par_list[1:i]) + \ + build_from_toc(par_list[i:]) + + return [par] + build_from_toc(par_list[1:]) + + if par_list[0].name in ('Chapter', 'Section', 'Subsection', 'Subsubsection'): + return nest_struct(par_list[0].name, par_list) + + +def nest_struct(name, par_list): + if par_list[0].name == name: + par = par_list[0] + par.name = transform_table[par.name] + + if len(par_list) == 1: + return par_list + + for i in range(1, len(par_list)): + if par_list[i].name == name: + par.child = build_from_toc(par_list[1:i]) + return [par] + build_from_toc(par_list[i:]) + par.child = build_from_toc(par_list[1:]) + return [ par ] + + +def main(argv): + if len(argv) > 2: + usage() + sys.exit(1) + + # choose language and prefix for files + if len(argv) == 1: + lang = "en" + pref = "" + else: + lang = argv[1] + pref = lang + '_' + # fallback + if lang not in info: + lang = 'en' + + # Determine existing translated documents for that language. + toc_general = [] + for file in depend.documents(pref): + file = LyX.File(input= file) + file.convert() + toc_general.extend(file.get_toc()) + + file = LyX.NewFile(output= pref + 'TOC.lyx') + data = info[lang] + file.set_header(language = data[0], language_quotes = data[1], inputencoding = data[2]) + body = [ LyX.Paragraph('Title', [data[3]])] + body.extend(build_from_toc(toc_general)) + file.set_body(body) + file.write() + + +if __name__ == "__main__": + main(sys.argv)