ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Accessing raw titles in textcommand in TOC
@ 2020-02-21 13:34 alephzorro
  2020-02-21 14:04 ` Hans Hagen
  2020-02-21 18:42 ` Wolfgang Schuster
  0 siblings, 2 replies; 5+ messages in thread
From: alephzorro @ 2020-02-21 13:34 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 1162 bytes --]

Hello,

I would like to display titles differently in TOC than they appear in text. For example, MyChapter1 -> 1retpahCyM. Basically any highly non-trivial transformation that really needs Lua.

I've written simple Lua macros before, but the following approach trying to define textcommand does not work since I can't find the way to pass the raw title to my transform function.

\startluacode
userdata = userdata or {}
function userdata.mytransform(title)
    --context(title) --this is just fine, but isn't very useful
    context(string.reverse(title))
end
\stopluacode

\def\transformtitle#1%
    {\ctxlua{userdata.mytransform([==[#1]==])}}

\setuplist[chapter][textcommand=\transformtitle]

\starttext
\completecontent

\startchapter[title={Sample Chapter}]
\stopchapter
\stoptext

When I print the actual title that is passed to mytransform, all I get is \currentlistentrytitle and I haven't succeed expanding it (and there's all kind of formatting stuff and so on going on I suppose). Sections have "deeptextcommand" which is somewhat what I'm after here, but I've not found similar option for TOC. So, is there a way to get just the raw titles?

Jason C.

[-- Attachment #1.2: Type: text/html, Size: 1752 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Accessing raw titles in textcommand in TOC
  2020-02-21 13:34 Accessing raw titles in textcommand in TOC alephzorro
@ 2020-02-21 14:04 ` Hans Hagen
  2020-02-22  5:57   ` alephzorro
  2020-02-21 18:42 ` Wolfgang Schuster
  1 sibling, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2020-02-21 14:04 UTC (permalink / raw)
  To: alephzorro, mailing list for ConTeXt users

On 2/21/2020 2:34 PM, alephzorro wrote:
> Hello,
> 
> I would like to display titles differently in TOC than they appear in 
> text. For example, MyChapter1 -> 1retpahCyM. Basically any highly 
> non-trivial transformation that really needs Lua.

\starttext

     \completecontent

     \startchapter[title={Sample Chapter},list={retpahC elpmaS}]
     \stopchapter

\stoptext


> I've written simple Lua macros before, but the following approach trying 
> to define textcommand does not work since I can't find the way to pass 
> the raw title to my transform function.
> 
> 
> 
> 
> \startluacode
> userdata = userdata or {}
> function userdata.mytransform(title)
>      --context(title) --this is just fine, but isn't very useful
>      context(string.reverse(title))
> end
> \stopluacode
> 
> \def\transformtitle#1%
>      {\ctxlua{userdata.mytransform([==[#1]==])}}
> 
> \setuplist[chapter][textcommand=\transformtitle]
> 
> 
> \starttext
> \completecontent
> 
> \startchapter[title={Sample Chapter}]
> \stopchapter
> \stoptext
> 
> 
> When I print the actual title that is passed to mytransform, all I get 
> is \currentlistentrytitle and I haven't succeed expanding it (and 
> there's all kind of formatting stuff and so on going on I suppose). 
> Sections have "deeptextcommand" which is somewhat what I'm after here, 
> but I've not found similar option for TOC. So, is there a way to get 
> just the raw titles?
> 
> Jason C.
> 
> 
> 
> 
> 
> ___________________________________________________________________________________
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
> 


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Accessing raw titles in textcommand in TOC
  2020-02-21 13:34 Accessing raw titles in textcommand in TOC alephzorro
  2020-02-21 14:04 ` Hans Hagen
@ 2020-02-21 18:42 ` Wolfgang Schuster
  2020-02-22  6:03   ` alephzorro
  1 sibling, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2020-02-21 18:42 UTC (permalink / raw)
  To: ntg-context; +Cc: mailing list for ConTeXt users

On Fri, 21 Feb 2020 13:34:20 +0000
alephzorro <alephzorro@protonmail.com> wrote:

> Hello,
> 
> I would like to display titles differently in TOC than they appear in text. For example, MyChapter1 -> 1retpahCyM. Basically any highly non-trivial transformation that really needs Lua.
> 
> I've written simple Lua macros before, but the following approach trying to define textcommand does not work since I can't find the way to pass the raw title to my transform function.
> 
> \startluacode
> userdata = userdata or {}
> function userdata.mytransform(title)
>     --context(title) --this is just fine, but isn't very useful
>     context(string.reverse(title))
> end
> \stopluacode
> 
> \def\transformtitle#1%
>     {\ctxlua{userdata.mytransform([==[#1]==])}}
> 
> \setuplist[chapter][textcommand=\transformtitle]
> 
> \starttext
> \completecontent
> 
> \startchapter[title={Sample Chapter}]
> \stopchapter
> \stoptext
> 
> When I print the actual title that is passed to mytransform, all I get is \currentlistentrytitle and I haven't succeed expanding it (and there's all kind of formatting stuff and so on going on I suppose). Sections have "deeptextcommand" which is somewhat what I'm after here, but I've not found similar option for TOC. So, is there a way to get just the raw titles?

There is no user level command to access the raw list title which is needed in your case but there is another way to achieve the desired result.

When you change the text direction for the list text (you can't use the align key because this would change the positions of the chapter and page numbers) the complete title is printed in reverse order.

%%%% begin example
%\setuplist[chapter][textcommand=\reversehbox]
\setuplist[chapter][textcommand={\unframed[location=low,align=righttoleft]}]

\starttext

\completecontent

\chapter{Sample Chapter}

\stoptext
%%%% end example

Wolfgang
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Accessing raw titles in textcommand in TOC
  2020-02-21 14:04 ` Hans Hagen
@ 2020-02-22  5:57   ` alephzorro
  0 siblings, 0 replies; 5+ messages in thread
From: alephzorro @ 2020-02-22  5:57 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users

The "list" seems capable of handling even complex lua macros. It does not require much work to add this to all chapters manually in my case so this solution works for me (and there's always awk and such for larger things). Thank you!

Jason


‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, February 21, 2020 4:04 PM, Hans Hagen <j.hagen@xs4all.nl> wrote:

> On 2/21/2020 2:34 PM, alephzorro wrote:
>
> > Hello,
> > I would like to display titles differently in TOC than they appear in
> > text. For example, MyChapter1 -> 1retpahCyM. Basically any highly
> > non-trivial transformation that really needs Lua.
>
> \starttext
>
> \completecontent
>
> \startchapter[title={Sample Chapter},list={retpahC elpmaS}]
> \stopchapter
>
> \stoptext
>
> > I've written simple Lua macros before, but the following approach trying
> > to define textcommand does not work since I can't find the way to pass
> > the raw title to my transform function.
> > \startluacode
> > userdata = userdata or {}
> > function userdata.mytransform(title)
> >     --context(title) --this is just fine, but isn't very useful
> >     context(string.reverse(title))
> > end
> > \stopluacode
> > \def\transformtitle#1%
> >     {\ctxlua{userdata.mytransform([==[#1]==])}}
> > \setuplist[chapter][textcommand=\transformtitle]
> > \starttext
> > \completecontent
> > \startchapter[title={Sample Chapter}]
> > \stopchapter
> > \stoptext
> > When I print the actual title that is passed to mytransform, all I get
> > is \currentlistentrytitle and I haven't succeed expanding it (and
> > there's all kind of formatting stuff and so on going on I suppose).
> > Sections have "deeptextcommand" which is somewhat what I'm after here,
> > but I've not found similar option for TOC. So, is there a way to get
> > just the raw titles?
> > Jason C.
> >
> > 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://context.aanhet.net
> > archive : https://bitbucket.org/phg/context-mirror/commits/
> > wiki : http://contextgarden.net
>
> --
>
> --
>
>                                            Hans Hagen | PRAGMA ADE
>                Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>         tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
>


___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Accessing raw titles in textcommand in TOC
  2020-02-21 18:42 ` Wolfgang Schuster
@ 2020-02-22  6:03   ` alephzorro
  0 siblings, 0 replies; 5+ messages in thread
From: alephzorro @ 2020-02-22  6:03 UTC (permalink / raw)
  To: Wolfgang Schuster; +Cc: ntg-context

Yup, this works gloriously for reversing titles. And more complex transformations (in my case mostly weird stuff like generating morse code for titles to be shown in TOC) can be done by specifying "list" for all chapters as Hans suggested. Thank you!

Jason




‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, February 21, 2020 8:41 PM, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote:

> On Fri, 21 Feb 2020 13:34:20 +0000
> alephzorro alephzorro@protonmail.com wrote:
>
> > Hello,
> > I would like to display titles differently in TOC than they appear in text. For example, MyChapter1 -> 1retpahCyM. Basically any highly non-trivial transformation that really needs Lua.
> > I've written simple Lua macros before, but the following approach trying to define textcommand does not work since I can't find the way to pass the raw title to my transform function.
> > \startluacode
> > userdata = userdata or {}
> > function userdata.mytransform(title)
> > --context(title) --this is just fine, but isn't very useful
> > context(string.reverse(title))
> > end
> > \stopluacode
> > \def\transformtitle#1%
> > {\ctxlua{userdata.mytransform([==[#1]==])}}
> > \setuplist[chapter][textcommand=\transformtitle]
> > \starttext
> > \completecontent
> > \startchapter[title={Sample Chapter}]
> > \stopchapter
> > \stoptext
> > When I print the actual title that is passed to mytransform, all I get is \currentlistentrytitle and I haven't succeed expanding it (and there's all kind of formatting stuff and so on going on I suppose). Sections have "deeptextcommand" which is somewhat what I'm after here, but I've not found similar option for TOC. So, is there a way to get just the raw titles?
>
> There is no user level command to access the raw list title which is needed in your case but there is another way to achieve the desired result.
>
> When you change the text direction for the list text (you can't use the align key because this would change the positions of the chapter and page numbers) the complete title is printed in reverse order.
>
> %%%% begin example
> %\setuplist[chapter][textcommand=\reversehbox]
> \setuplist[chapter][textcommand={\unframed[location=low,align=righttoleft]}]
>
> \starttext
>
> \completecontent
>
> \chapter{Sample Chapter}
>
> \stoptext
> %%%% end example
>
> Wolfgang


___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2020-02-22  6:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-21 13:34 Accessing raw titles in textcommand in TOC alephzorro
2020-02-21 14:04 ` Hans Hagen
2020-02-22  5:57   ` alephzorro
2020-02-21 18:42 ` Wolfgang Schuster
2020-02-22  6:03   ` alephzorro

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