Re: Is it possible to have a PDF table of contents list? [corrected]
Mark Summerfield <[email protected]> Thu, 29 Nov 2018 13:38:34 +0000
| Newsgroups | gmane.comp.type-setting.lout |
|---|---|
| Organization | Qtrac Ltd. |
| Message-ID | <20181129133834.66f3cc4f@suki> |
Hi Uwe, On Thu, 29 Nov 2018 02:32:40 +0300 Valery Ushakov <[email protected]> wrote: > On Wed, Nov 28, 2018 at 21:08:17 +0000, Mark wrote: [snip] > This should be solvable with lout cross-references and some > indirection. There's probably a relevant example already in the > standard packages. If not, this old mail might provide some relevant > inspiration on creative use of @Tagged > > http://www.stderr.spb.ru/~uwe/lout/essays/1402.dictionary.txt > > (the same mail in official archives) > > http://lists.nongnu.org/archive/html/lout-users/1999-11/msg00021.html > > > Sorry, I no longer have enough lout cached in my head to come up with > an answer expromptu. I'm now using these: def @Toc left count right x { { @BackEnd @Case { PostScript @Yield { # lout provides ] ? "[ /Title ("x") /Count "-count" /OUT pdfmark " } ### I now negate the count so the start unexpanded else @Yield @Null } } @Graphic { } } def @SubToc right x { { @BackEnd @Case { PostScript @Yield { # lout provides ] ? "[ /Title ("x") /OUT pdfmark " } else @Yield @Null } } @Graphic { } } Used like this: @Lecture @Title{Test Session} @Begin 2 @Toc{Test Session} ### Forgot to include the count! @BeginOverheads @Overhead @Title{Slide 1} @Begin @SubToc{Slide 1} ... Here's the Python program I use to check the counts: #!/usr/bin/env python3 import glob import pathlib import re def main(): for filename in glob.iglob('*.lout'): check(filename) def check(filename): with open(filename, 'rt', encoding='latin1') as file: text = file.read() match = re.search(r'(?P<count>\d+)\s+@Toc[{]', text) if match is not None: expected = int(match.group('count')) count = text.count('@SubToc') if expected != count: print(f'{pathlib.Path(__file__).name}: {filename} {count}') if __name__ == '__main__': main() # If using < 3.6 change the print to: # print(pathlib.Path(__file__).name, filename, count) -- Mark Summerfield, Qtrac Ltd. ComparePDF - easy to use fast PDF comparison tool http://www.qtrac.eu/comparepdf.html