Update TOC building for all the translated languages. (Documentation)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9093 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
José Matox 2004-10-17 19:12:33 +00:00
parent 3c84dfb21e
commit fa133e49b9
13 changed files with 231 additions and 447 deletions

View File

@ -2,3 +2,4 @@ Makefile.in
Makefile Makefile
LaTeXConfig.lyx LaTeXConfig.lyx
Makefile.depend Makefile.depend
*.pyc

View File

@ -1,3 +1,18 @@
2004-10-17 José Matos <jamatos@lyx.org>
* 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 <martin.vermeer@hut.fi> 2004-10-11 Martin Vermeer <martin.vermeer@hut.fi>
* Customization.lyx: added description of BibTeX, * Customization.lyx: added description of BibTeX,

View File

@ -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 <<ENDHEAD;
# This is a Makefile for the TOC.lyx files.
# It was automatically generated by $0
#
# First come the rules for each xx_TOC.lyx file. Then comes the
# TOCs target, which prints all the TOC files.
ENDHEAD
# Add (whitespace separated) "Foo" to this list to create a TOC for Foo.lyx
# Don't bother including Reference.lyx
my @Default_Files = map {"$_.lyx"} qw(
Intro FAQ Tutorial UserGuide Extended Customization
);
my $Toc_Top_Dir = "TOC_top";
my $Toc_Top_Base = "TOC_top.lyx";
my $Toc_Base = "TOC.lyx";
# Any language which has any translated docs needs to have a TOC.lyx
my %a;
opendir (DIR, ".") or die $!;
foreach (readdir DIR) {
$a{$1}++ if /^([a-z]{2}_)/;
}
close DIR;
my @langs = sort keys %a;
unshift @langs, ""; # English file doesn't have en_ prefix
# Foreach language, create Makefile dependencies
# and create make action
my @Tocs; # List of all TOC files
my $lang;
foreach $lang (@langs) {
# "TOCs" target will depend on this language's TOC
my $tfile = "$lang$Toc_Base";
push @Tocs, $tfile;
# Make list of files, English or not.
# First TOC_Top file
# TODO print warning if language-specific file doesn't exist?
my $ttfile = (-e "$Toc_Top_Dir/$lang$Toc_Top_Base" ?
"$Toc_Top_Dir/$lang$Toc_Top_Base" :
"$Toc_Top_Dir/$Toc_Top_Base");
my @Files = ($ttfile);
# Now actual Doc files
foreach (@Default_Files) {
my $i18n = $lang . $_;
# Use xx_foo if it exists, else foo
push (@Files, (-e $i18n ? $i18n : $_));
}
# Create Makefile dependencies for this language's TOC file
my $depend = "$tfile: ";
$depend .= join (" ", @Files);
print "$depend\n";
# Create make action
my $make = "\tperl Doc_toc.pl ";
# TODO is there a simple way to tell it to pass all the dependencies in?
# Then this could be a default rule for creating *TOC.lyx!
$make .= join (" ", @Files);
$make .= ' > $@';
print "$make\n\n";
}
my $depend = "TOCs: ";
$depend .= join (" ", @Tocs);
print "#" x 80,"\n";
print "\n$depend\n";
print "\t\@echo Made TOCs succesfully.\n";

View File

@ -1,168 +0,0 @@
#!/usr/bin/perl -w
# Note! If your perl isn't in /usr/bin/perl, change the line above.
# (Or say "perl Doc_toc.pl" instead of just "Doc_toc.pl")
#
# 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.)
# ./Doc_toc.pl TOC_top/TOC_top.lyx Intro.lyx FAQ.lyx Tutorial.lyx UserGuide.lyx Extended.lyx Customization.lyx >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 = <<ENDUSAGE;
$0 Toc_Top_File Doc [Doc ...]
* Docs are LyX docs to be TOC-ified
* All information up to and including the TOC doc title is in a
language-specific file Toc_Top_File
ENDUSAGE
my $printing = 0; # are we currently supposed to be copying input to STDOUT?
my @LyX_classes = qw (Chapter Section Subsection Subsubsection);
my $Toc_Top_File = shift;
# Get document header from language-specific TOC_top
open(HEAD, "<$Toc_Top_File") or die $!;
while (<HEAD>) {
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 &section_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 = &section_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;
}

View File

@ -2,7 +2,7 @@ include $(top_srcdir)/config/common.am
DISTCLEANFILES += LyXConfig.lyx LaTeXConfig.lyx Makefile.depend 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 = \ docfiles = \
cs_TOC.lyx \ cs_TOC.lyx \
@ -89,16 +89,6 @@ doc_DATA = \
$(docfiles) \ $(docfiles) \
LaTeXConfig.lyx 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? # 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 # problem with this is that the DEPENDFILE that's included won't be the updated
# one. JMarc should know how to handle this. # one. JMarc should know how to handle this.
@ -109,6 +99,6 @@ TOCs : depend
make -f $(DEPENDFILE) TOCs make -f $(DEPENDFILE) TOCs
depend: depend:
perl Depend.pl > $(DEPENDFILE) python depend.py > $(DEPENDFILE)
.PHONY: depend .PHONY: depend

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

88
lib/doc/depend.py Normal file
View File

@ -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 <jamatos@lyx.org>
#
# 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)

125
lib/doc/doc_toc.py Executable file
View File

@ -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 <jamatos@lyx.org>
#
# 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)