# Re: [NTG-context] Accessing raw titles in textcommand in TOC

On Fri, 21 Feb 2020 13:34:20 +0000
alephzorro <alephzo...@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
___________________________________________________________________________________