ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jyrki Ruuskanen <yuruki@kotikone.fi>
Cc: Hans Hagen <pragma@wxs.nl>, Taco Hoekwater <taco@elvenkind.com>
Subject: How to preserve a TeX token list across passes (the	ConTeXt way)?
Date: Thu, 11 May 2006 20:50:55 +0300	[thread overview]
Message-ID: <7EB85204-2670-45AE-9F5D-3B7CFDFF70CD@kotikone.fi> (raw)

[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]

Ok, the module is read in cont-sys.rme with \usemodule[jtex]. It  
initializes the lists inside protect / unprotect pair with \newtoks 
\usedAbbreviations and \newtoks\usedReferences along with macro  
definitions.

Abbreviations are introduced with \setAbbreviation[<key>]{<abbr>} 
{<meaning>}{<description>} which defines macros \<key> \<key>@meaning  
and \<key>@description. Each call to \<key> calls \writeutilitycommand 
{\addToList[\string\usedAbbreviations]{<key>}, so after the first run  
the .tui file has a number of "c \addToList[\usedAbbreviations] 
{something}" lines in it.

Functionality is similar for the bibliography. The \cite command  
writes \addToList[\usedReferences]{<cite>} into .tui.

So, the .tuo file should populate used* lists and I could typeset the  
list of used abbreviations in initialization order with  
\executeListIntersection[\abbreviations][\usedAbbreviations] 
{\printAbbreviation}. Same for used bib references. But well, lists  
remain empty.

I'll attach the module and the .tui file.

And excuse me, I have never ever used a mailing list. How am I  
supposed to answer to a certain message in the chain? Thanks guys.

Jyrki


[-- Attachment #2: final.tui --]
[-- Type: application/octet-stream, Size: 35260 bytes --]

[-- Attachment #3: t-jtex.tex --]
[-- Type: application/octet-stream, Size: 5192 bytes --]

%D \enableregime[il1]
%D \module
%D	[file=t-jtex,
%D	version=2006.0,
%D	title=\CONTEXT\ User Module,
%D	subtitle=Miscellaneous Macros,
%D	author=Jyrki Ruuskanen,
%D	date=\currentdate,
%D	copyright=Jyrki Ruuskanen]

\writestatus{loading}{J's TeX Extensions}

\unprotect

% add \currentsecondlanguage variable
\def\secondlanguage[#1]{\def\currentsecondlanguage{#1}}

%%% handle multilingual texts (and uppercase)
% usage: \setText[lang]{key}{value}
\def\setText{\futurelet\testchar\maybeLangSetText}
\def\maybeLangSetText%
	{\ifx[\testchar \let\next\langSetText
	\else \let\next\defaultSetText \fi \next}
\def\langSetText[#1]#2#3{\def\name{#2@#1}\def\bigname{#2@#1@uppercase}
	\expandafter\def\csname \name \endcsname{#3}
	\expandafter\def\csname \bigname \endcsname{\uppercase{#3}}}
\def\defaultSetText#1#2{\langSetText[\currentmainlanguage]{#1}{#2}}

% usage: \getText{key}
\def\langGetText[#1]#2{\def\name{#2@#1}%
	\expandafter\ifx\csname \name \endcsname\relax
	\name missing!\else\csname \name \endcsname\fi}
\def\getText#1{\def\name{#1@\currentlanguage}%
	\expandafter\ifx\csname \name \endcsname\relax
	\langGetText[\currentmainlanguage]{#1}
	\else\langGetText[\currentlanguage]{#1}\fi}

% usage: \getUppercaseText{key}
\def\langGetUppercaseText[#1]#2{\def\name{#2@#1@uppercase}%
	\expandafter\ifx\csname \name \endcsname\relax
	\name missing!\else\csname \name \endcsname\fi}
\def\getUppercaseText#1{\def\name{#1@\currentlanguage @uppercase}%
	\expandafter\ifx\csname \name \endcsname\relax
	\langGetUppercaseText[\currentmainlanguage]{#1}
	\else\langGetUppercaseText[\currentlanguage]{#1}\fi}

% usage: \startTextBuffer[lang]{key}...
\def\startTextBuffer{\futurelet\testchar\maybeLangStartTextBuffer}
\def\maybeLangStartTextBuffer%
	{\ifx[\testchar \let\next\langStartTextBuffer
	\else \let\next\defaultStartTextBuffer \fi \next}
\def\langStartTextBuffer[#1]#2{\startbuffer[#2@#1]}
\def\defaultStartTextBuffer#1{\langStartTextBuffer[\currentmainlanguage]{#1}}

% NOTE doesn't work, use \stopbuffer for now
% usage: ...\stopTextBuffer
\let\stopTextBuffer=\stopbuffer

% usage: \getTextBuffer{key}
\def\getTextBuffer#1{\getbuffer[#1@\currentlanguage]}

%%% handle abbreviations
% usage: \setAbbreviation[key]{abbr}{meaning}{description}
\newtoks\usedAbbreviations
\newtoks\abbreviations
\def\setAbbreviation{\futurelet\testchar\maybeOptSetAbbreviation}
\def\maybeOptSetAbbreviation%
	{\ifx[\testchar \let\next\optSetAbbreviation
	\else \let\next\defaultSetAbbreviation \fi \next}
\def\optSetAbbreviation[#1]#2#3#4%
	{\addToList[\abbreviations]{#1}
	\expandafter\def\csname#1\endcsname%
		{#2\writeutilitycommand{\addToList[\string\usedAbbreviations]{#1}}}
	\setAsKeyAndValue[meaning]{#3}{#1}
	\setAsKeyAndValue[description]{#4}{#1}}
\def\defaultSetAbbreviation#1#2#3{\optSetAbbreviation[#1]{#1}{#2}{#3}}

% usage: \getMeaning{key}
\def\getMeaning#1{\def\meaning{#1@meaning}%
	\csname \meaning \endcsname}
\let\infull=\getMeaning

% usage: \getDescription{key}
\def\getDescription#1{\def\description{#1@description}%
	\csname \description \endcsname}

% usage: \printAbbreviation{key}
\def\printAbbreviation#1%
	{{\bf\csname#1\endcsname} (\getMeaning{#1}). \getDescription{#1}\par}

%%% handle references
% usage: \setReference[key]{cite}{description}
\newtoks\usedReferences
\newtoks\references
\def\setReference[#1]#2#3{\def\citename{#1@cite}%
	\addToList[\references]{#1}
	\expandafter\def\csname\citename\endcsname%
		{#2\writeutilitycommand{\addToList[\string\usedReferences]{#1}}}
	\setAsKeyAndValue[description]{#3}{#1}}
	
% usage: \cite[key]
\def\cite[#1]{\def\citename{#1@cite}%
	\csname \citename \endcsname}

% usage: \printReference{key}
\def\printReference#1%
	{\getDescription{#1}\par}

%%% token list operations
% usage: \addToList[\list]{value}
\def\addToList[#1]#2{\let\\=\relax
	\edef\act{\noexpand#1={\the#1 \\{#2}}}%
	\act}

% usage: \executeList[\list]{\command#1}
\def\executeList[#1]#2{\def\\##1{#2{##1}}%
	\the#1}

% usage: \executeListIntersection[\listone][\listtwo]{\command#1}
\def\executeOnMatch#1#2{\def\comparison{#2@comparison}%
	\expandafter\ifx\csname \comparison \endcsname\relax
	\else#1{#2} \fi}
\def\executeListIntersection[#1][#2]#3%
	{\executeList[#2]{\setAsKeyAndValue[comparison]{true}}
	\executeList[#1]{\executeOnMatch{#3}}}

% usage: \addToAssociative[\list]{value}{key}
\def\addToAssociative[#1]#2#3{\let\\=\relax
	\edef\act{\noexpand#1={\the#1 \\{#2}{#3}}}%
	\act}

% usage: \executeAssociative[\list]{\command#1#2}
\def\executeAssociative[#1]#2{\def\\##1##2{#2{##1}{##2}}%
	\the#1}

% usage: \setAsKeyAndValue[suffix]{value}{key}
\def\setAsKeyAndValue{\futurelet\testchar\maybeSetAsKeyAndValueWithSuffix}
\def\maybeSetAsKeyAndValueWithSuffix%
	{\ifx[\testchar \let\next\setAsKeyAndValueWithSuffix
	\else \let\next\setAsKeyAndValueWithoutSuffix \fi \next}
\def\setAsKeyAndValueWithSuffix[#1]#2#3{\def\name{#3@#1}%
	\expandafter\def\csname \name \endcsname{#2}}
\def\setAsKeyAndValueWithoutSuffix#1#2{\def\name{#2}%
	\expandafter\def\csname \name \endcsname{#1}}

% usage: \getFromAssociative[\list]{key}
\def\getFromAssociative[#1]#2{\def\name{#2@temp}%
	\executeAssociative[#1]{\setAsKeyAndValue[temp]}
	\csname \name \endcsname}

\protect

[-- Attachment #4: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

             reply	other threads:[~2006-05-11 17:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-11 17:50 Jyrki Ruuskanen [this message]
2006-05-11 18:29 ` Hans Hagen
2006-05-11 21:49 ` Hans Hagen
2006-05-15  8:28 ` Hans Hagen
2006-05-15  8:52 ` Hans Hagen
  -- strict thread matches above, loose matches on Subject: below --
2006-05-11 19:32 Jyrki Ruuskanen
2006-05-10 17:28 Jyrki Ruuskanen
2006-05-11  8:33 ` Taco Hoekwater
2006-05-11  8:45 ` Hans Hagen

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=7EB85204-2670-45AE-9F5D-3B7CFDFF70CD@kotikone.fi \
    --to=yuruki@kotikone.fi \
    --cc=ntg-context@ntg.nl \
    --cc=pragma@wxs.nl \
    --cc=taco@elvenkind.com \
    /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).