The script under my sig is a filter that takes a LyX file from stdin and
spits
out the chapters. Right now it doesn’t do parts, but it probably will
later
on. Perhaps some day it will handle the whole hierchy of
Part/chapter/section/subsection/subsubsection/paragraph/subparagraph.
Consider this version public domain with no warranty.
chapname += (" " + line) unless line =~ /^\s*\\/ or line =~ /^\s*$/
elsif in_chapter && line =~ /^\s*(\|$)/
chapname << " " << line
end
end
end
printf(“%2d: %s\n”, chapno, chapname) if chapname and chapname != “”
Also, I’d use puts and #{} instead of printf, but tastes vary. Your
code would be a good example for the flip-flop operator (no religious
wars, please):
if (line =~ /^\s*\layout Chapter/)…(line =~ /^\s*\layout/)
if line =~ /^\s*(\|$)/
chapname << " " << line
end
end