ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Cross-referencing Challenge
@ 2012-04-14 22:44 Aaron W. Hsu
  2012-04-14 23:19 ` S Barmeier
  0 siblings, 1 reply; 3+ messages in thread
From: Aaron W. Hsu @ 2012-04-14 22:44 UTC (permalink / raw)
  To: ntg-context

Hey All:

I am very new to ConTeXt, but I am trying to use it to achieve a format
similar to what you can get from WEB systems. Right now I am working on
the definitions of chunks and their cross references.  I have three main
macros:

\defchunk   Definining a new chunk \chunk      Referencing a chunk by name
\stopchunk  Ending a chunk definition

Here is an example:

\defchunk{This is a name}
Some text /BTEX\chunk{Other stuff}/ETEX goes here.
And here.
\stopchunk

\defchunk{Other stuff}
Something else \stopchunk

\defchunk{This is a name}
Some other stuff.
\stopchunk

Now, at the end, let's say that each of these appears in sections 1, 2,
and 3, respectively.  The output I am looking for, in Unicode, might look
like this:

⟨This is a name 1⟩≡
  Some text ⟨Other stuff 2⟩ goes here.
  And here.
──
See also section 3.

⟨Other stuff 2⟩≡
  Something else
──
This code is used in section 1.

⟨This is a name 1⟩≡
  Some other stuff.
──

So here, there are really three things that I want to achieve.  I need to
be able to get a list of all of the sections wherein a given chunk is
referenced using \chunk, a list of all the sections where a section of the
same name is defined, and finally, be able to tell in which section the
first occurrence of a chunk is defined.

How can I accomplish this?


-- 
Aaron W. Hsu | arcfide@sacrideo.us | http://www.sacrideo.us
Programming is just another word for the lost art of thinking.

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Cross-referencing Challenge
  2012-04-14 22:44 Cross-referencing Challenge Aaron W. Hsu
@ 2012-04-14 23:19 ` S Barmeier
  2012-04-15  0:38   ` Aaron W. Hsu
  0 siblings, 1 reply; 3+ messages in thread
From: S Barmeier @ 2012-04-14 23:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Aaron W. Hsu

On 04/15/2012 07:44 AM, Aaron W. Hsu wrote:
> Hey All:
> 
> I am very new to ConTeXt, but I am trying to use it to achieve a format
> similar to what you can get from WEB systems. Right now I am working on
> the definitions of chunks and their cross references.  I have three main
> macros:
> 
> \defchunk   Definining a new chunk \chunk      Referencing a chunk by name
> \stopchunk  Ending a chunk definition
> 
> Here is an example:
> 
> \defchunk{This is a name}
> Some text /BTEX\chunk{Other stuff}/ETEX goes here.
> And here.
> \stopchunk
> 
> \defchunk{Other stuff}
> Something else \stopchunk
> 
> \defchunk{This is a name}
> Some other stuff.
> \stopchunk
> 
> Now, at the end, let's say that each of these appears in sections 1, 2,
> and 3, respectively.  The output I am looking for, in Unicode, might look
> like this:
> 
> ⟨This is a name 1⟩≡
>   Some text ⟨Other stuff 2⟩ goes here.
>   And here.
> ──
> See also section 3.
> 
> ⟨Other stuff 2⟩≡
>   Something else
> ──
> This code is used in section 1.
> 
> ⟨This is a name 1⟩≡
>   Some other stuff.
> ──
> 
> So here, there are really three things that I want to achieve.  I need to
> be able to get a list of all of the sections wherein a given chunk is
> referenced using \chunk, a list of all the sections where a section of the
> same name is defined, and finally, be able to tell in which section the
> first occurrence of a chunk is defined.
> 
> How can I accomplish this?

Have you had a look at the reference manual? Chapter 13 on descriptions
will show you how to define something like

\definedescription[chunk][location=serried,titlestyle=\bf]

which you then should be able to use as

\chunk[name1]{This is a name}

For referencing (chapter 12), use \in for pointing to the relevant
section, \at[name1] for a page number.

\definedescription[chunk]
\starttext
\input tufte
\section[s1]{One section}
\chunk[c1]{A chunk}
\input ward \par
\input tufte
\startchunk[c2]{A long chunk}
\input ward
\input tufte
\stopchunk
In section \in[s1] on page \at[c1], we defined the first chunk.
\stoptext

You can style this with \setupdesription[chunk][...=...] or directly in
the definition.

Enjoy =)
Severin

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Cross-referencing Challenge
  2012-04-14 23:19 ` S Barmeier
@ 2012-04-15  0:38   ` Aaron W. Hsu
  0 siblings, 0 replies; 3+ messages in thread
From: Aaron W. Hsu @ 2012-04-15  0:38 UTC (permalink / raw)
  To: ntg-context

Thank you for the response, my response is below...

On Sun, 15 Apr 2012 08:19:28 +0900, S Barmeier wrote:

> On 04/15/2012 07:44 AM, Aaron W. Hsu wrote:

>> Here is an example:
>> 
>> \defchunk{This is a name}
>> Some text /BTEX\chunk{Other stuff}/ETEX goes here.
>> And here.
>> \stopchunk
>> 
>> \defchunk{Other stuff}
>> Something else \stopchunk
>> 
>> \defchunk{This is a name}
>> Some other stuff.
>> \stopchunk
>> 
>> Now, at the end, let's say that each of these appears in sections 1, 2,
>> and 3, respectively.  The output I am looking for, in Unicode, might
>> look like this:
>> 
>> ⟨This is a name 1⟩≡
>>   Some text ⟨Other stuff 2⟩ goes here.
>>   And here.
>> ──
>> See also section 3.
>> 
>> ⟨Other stuff 2⟩≡
>>   Something else
>> ──
>> This code is used in section 1.
>> 
>> ⟨This is a name 1⟩≡
>>   Some other stuff.
>> ──
>> 
>> So here, there are really three things that I want to achieve.  I need
>> to be able to get a list of all of the sections wherein a given chunk
>> is referenced using \chunk, a list of all the sections where a section
>> of the same name is defined, and finally, be able to tell in which
>> section the first occurrence of a chunk is defined.

> Have you had a look at the reference manual? Chapter 13 on descriptions
> will show you how to define something like
> 
> \definedescription[chunk][location=serried,titlestyle=\bf]
> 
> which you then should be able to use as
> 
> \chunk[name1]{This is a name}
> 
> For referencing (chapter 12), use \in for pointing to the relevant
> section, \at[name1] for a page number.
> 
> \definedescription[chunk]
> \starttext \input tufte \section[s1]{One section}
> \chunk[c1]{A chunk}
> \input ward \par \input tufte \startchunk[c2]{A long chunk}
> \input ward \input tufte \stopchunk In section \in[s1] on page \at[c1],
> we defined the first chunk.
> \stoptext
> 
> You can style this with \setupdesription[chunk][...=...] or directly in
> the definition.

So, basic cross-referencing with named labels is easy enough to figure 
out, but I do not know how to go from this to the automatic referencing 
that I want.  Specifically, in my above example, I do not want to 
explicitly list any labels.  Moreover, that example contains two chunks 
with the same name “This is a name.” I want to somehow be able to talk 
about all of the chunks that have the same name.  So, if I have three 
chunks of that name, I want to be able to say \refs{This is a name} or 
something like that, and end up with the set of cross-references to each 
of those chunks.  

If I gave each specific instance a specific label that was unique and 
then manually remembered which labels go together, then I could do the 
cross-references.  I do not want to have to do this manually though, and 
I want my macros to automatically remember and generate three things:

1) A mapping from a chunk name to the set of references where that chunk 
is defined; a single chunk name may be defined in multiple places, and I 
want to be able to talk about all of those references as a group.

2) A mapping from a chunk name to the first reference in the above set, 
that is, the start of the chunk definitions.

3) A set of references pointing to where a given chunk name is used as a 
reference. These are links pointing in the opposite direction.  A 
\chunkref{This is a name} should create a reference to which I point in 
the first definition of the chunk “This is a name.” The above example 
shows this, where I use chunk 2 in chunk 1, so the reference to chunk 1 
shows up in the cross-references under chunk 2. 

The problem I am having is understanding how to map multiple references 
onto a single label, for instance, or some other key, while still 
retaining the ability to say what the first use of that label is. 

Does this make sense? I hope this clarifies things.  I am trying to get 
the cross-referencing behavior that one gets from systems like CWEB or 
WEB.  In those systems, a preprocessor extracts the links and generates 
them before outputting the TeX code.

-- 
Aaron W. Hsu | arcfide@sacrideo.us | http://www.sacrideo.us
Programming is just another word for the lost art of thinking.

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-15  0:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-14 22:44 Cross-referencing Challenge Aaron W. Hsu
2012-04-14 23:19 ` S Barmeier
2012-04-15  0:38   ` Aaron W. Hsu

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).