ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: tooltips and glossary
Date: Wed, 5 May 2010 09:04:02 +0200	[thread overview]
Message-ID: <20100505070402.GA21581@aides> (raw)
In-Reply-To: <20100505070218.GA21609@aides>


[-- Attachment #1.1.1: Type: text/plain, Size: 143 bytes --]

... forgot the attachment.
-- 
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

[-- Attachment #1.1.2: glossarium.lua --]
[-- Type: text/plain, Size: 2223 bytes --]

--
--------------------------------------------------------------------------------
--         FILE:  glossarium.lua
--        USAGE:  ConTeXt MkIV only
--  DESCRIPTION:  ad-hoc glossary
--       AUTHOR:  Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--      VERSION:  1.0
--      CREATED:  04/05/10 13:00:54 CEST
--     REVISION:  1
--------------------------------------------------------------------------------
--

gloss = {}
gloss.tracker, gloss.content = {}, {}

function gloss.warn( text )
    context.message( "== GLOSSARY: " .. text )
end

function gloss.newgloss( keyword, entry )
    if gloss.content[keyword] then
        gloss.warn( "Entry for " .. keyword .. " exists. Skipping." )
    else
        gloss.content[keyword] = entry
    end
end

function gloss.usegloss( keyword, explained_here)
    if gloss.content[keyword] then
        local indstring = "glossind:" .. keyword
        if explained_here ~= "" and
           not gloss.tracker[keyword] then
            local refstring = "gloss:" .. keyword
            context.reference({ refstring }, "")
            gloss.tracker[keyword] = true
        end
        context.goto(keyword, {indstring})
    else
        gloss.warn( "No entry for " .. keyword .. ". Skipping." )
    end
end

function gloss.place_glossary ()
    -- get all keywords and sort them
    local sort_me = {}
    for key, _ in pairs(gloss.content) do
        table.insert(sort_me, key)
    end
    table.sort(sort_me)

    -- pretty print them somehow
    for _, keyword in ipairs(sort_me) do
        local refstring = "gloss:"    .. keyword
        local indstring = "glossind:" .. keyword
        context.noindentation()
        context.reference({ indstring }, "")
        context.bgroup() 
            context.bf()
            --context.goto( keyword, { refstring } )
            context(keyword)
        context.egroup()

        -- leave some space before entry
        context.hskip1em()
        context(gloss.content[keyword])

        context.unskip()
        context(", (")
        context.at( "v.s. on p.", { refstring } )
        context(").")

        context.par()
    end
end


        


[-- Attachment #1.1.3: glossarium.tex --]
[-- Type: text/x-tex, Size: 1929 bytes --]

\setupinteraction[state=start]

\ctxlua{dofile("glossarium.lua")}

% Use \gloss#1#2 somewhere before \starttext, in a secondary file if you like.
% #1: gloss reference key (used as index)
% #2: the entry (explanation)
\def\gloss#1#2{%
  \ctxlua{gloss.newgloss("#1", "\luaescapestring{#2}")}
}

\def\dousegloss[#1]#2{%
  \ctxlua{gloss.usegloss("#2", "#1")}%
}

% Use this in your text to create a reference to the glossary.
% #1: optional, If this is the main passage where you explain the entry in detail, 
%     the glossary will link back here. (Just make it non-empty.)
% #2: the gloss key
\unexpanded\def\usegloss{\dosingleempty\dousegloss}


% This is meant to create the glossary after the text:
% The gloss key is typeset in bold face and will reference the point in the
% main text where \usegloss was called with a nonempty first arg.
\def\placeglossary{\ctxlua{gloss.place_glossary()}}

\starttext

\gloss{glossary}{%
  A collection of glosses; a list with explanations of abstruse,
  antiquated, dialectal, or technical terms; a partial dictionary. (As defined by
  M.~Saunders)%
}

\gloss{index}{%
  An index (plural: indexes) is a list of words or phrases ('headings') and
  associated pointers ('locators') to where useful material relating to that
  heading can be found in a document.
  (As def'ed by the English Wikipedia)
}

test \usegloss{glossary} test.
\page
Here \usegloss{index} just occurs.
\page
The glossary entry \usegloss[exp]{index} is explained here.
\page
Here \usegloss{index} just occurs again.
\footnote{Here \usegloss{index} just occurs again.}
\page
Here we'll deal with \usegloss[exp]{glossary} in detail.
\page
Here \usegloss{index} just occurs again.
\page
Here \usegloss{index} just occurs again.
\page
Here we mention \usegloss{glossary}.
\page
Here \usegloss{index} just occurs again.
\page

\placeglossary



\stoptext

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2010-05-05  7:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-05  4:36 Michael Saunders
2010-05-05  7:02 ` Philipp Gesang
2010-05-05  7:04   ` Philipp Gesang [this message]
2010-05-05  7:04 ` Marius
2010-05-06 10:31 ` luigi scarso
  -- strict thread matches above, loose matches on Subject: below --
2010-05-06 11:20 Michael Saunders
2010-05-06 11:49 ` luigi scarso
2010-05-04  9:44 Michael Saunders
2010-05-04 12:28 ` Philipp Gesang
     [not found]   ` <o2i54d7f5601005040628p90c28ea6s47eab9d212acce20@mail.gmail.com>
2010-05-04 13:32     ` Michael Saunders
2010-05-04 19:04       ` Philipp Gesang
2010-05-04 19:42       ` Corsair
2010-05-04 13:07 ` Willi Egger
2010-05-04 13:34 ` Marius
2010-05-06  9:45 ` Hans Hagen
2010-05-06 10:00   ` Taco Hoekwater
2010-05-03 19:18 Michael Saunders
2010-05-03 19:21 ` Wolfgang Schuster
2010-05-04  1:40 ` Michael Saunders
2010-05-04  8:18   ` Marius
2010-05-05  6:28   ` Taco Hoekwater
2010-05-02 22:51 Michael Saunders
2010-05-03 12:26 ` Wolfgang Schuster
2010-05-03 19:09 ` Wolfgang Schuster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100505070402.GA21581@aides \
    --to=pgesang@ix.urz.uni-heidelberg.de \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).