s-figures-names.mkiv /size: 3128 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [      file=s-figures-names.mkiv,
3%D        version=2017.07.17,
4%D          title=\CONTEXT\ Style File,
5%D       subtitle=Show Figure Names,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D Normally this module will be run someplace at the end of a document in some kind of tracing
15%D mode. We could hook it into \type {\stoptext} but better leave it up to the user. Loading
16%D this module upfront will not show anything useful. The main reason for making this module
17%D was that we wanted to report weird figurenames: spaces, multiple hyphens in a row, mixed
18%D hyphens and underscores, inconsistently mixed upper and lowercase, etc.
19%D
20%D If you only want info in the logfile, you can use:
21%D
22%D \starttyping
23%D \enabletrackers[graphics.lognames]
24%D \stoptyping
25%D
26%D This directive is persistent and can be issued any time before the end of the run.
27
28\startmodule[figures-names]
29
30\startluacode
31
32local context            = context
33local ctx_NC             = context.NC
34local ctx_NR             = context.NR
35local ctx_red            = context.red
36local ctx_starttabulate  = context.starttabulate
37local ctx_stoptabulate   = context.stoptabulate
38local ctx_hyphenatedname = context.hyphenatedfilename
39
40trackers.enable("graphics.lognames")
41
42context.start()
43
44    context.switchtobodyfont { "tt,small" }
45
46    local template = { "|Bl|p|" }
47
48    for _, data in table.sortedhash(figures.found) do
49        ctx_starttabulate(template)
50            local badname = data.badname
51            local found   = data.found
52            ctx_NC()
53                context("asked name")
54            ctx_NC()
55                if badname then
56                    ctx_red()
57                end
58                context(data.askedname)
59            ctx_NC() ctx_NR()
60            if found then
61                ctx_NC()
62                    context("format")
63                ctx_NC()
64                    context(data.format)
65                ctx_NC() ctx_NR()
66                ctx_NC()
67                    context("found file")
68                ctx_NC()
69                    ctx_hyphenatedname(data.foundname)
70                 -- context(data.foundname)
71                ctx_NC() ctx_NR()
72                ctx_NC()
73                    context("used file")
74                ctx_NC()
75                    ctx_hyphenatedname(data.fullname)
76                 -- context(data.fullname)
77                ctx_NC() ctx_NR()
78                if badname then
79                    ctx_NC()
80                        context("comment")
81                    ctx_NC()
82                        context("bad name")
83                    ctx_NC() ctx_NR()
84                end
85            else
86                ctx_NC()
87                    context("comment")
88                ctx_NC()
89                    context(data.comment or "not found")
90                ctx_NC() ctx_NR()
91            end
92        ctx_stoptabulate()
93    end
94
95context.stop()
96
97\stopluacode
98
99\stopmodule
100