deeptextcommand and firstcharacter
Hi, The attached file does not compile in ConTeXt. However, if the \placeindex is substituted for \completeindex, then the document compiles. Any idea how to use a deeptextcommand and firstcharacter as shown in the attachment while also using the firstcharacter macro? Thank you. Kindest regards.
On 9/21/2013 7:50 AM, Thangalin wrote:
Hi,
The attached file does not compile in ConTeXt.
However, if the \placeindex is substituted for \completeindex, then the document compiles.
Any idea how to use a deeptextcommand and firstcharacter as shown in the attachment while also using the firstcharacter macro?
this way of applying something to a first character won't work (as it assume real simple arguments) so, the next beta has: \applytofirstcharacter \defineframed[ChapterFramed][location=low,background=color,backgroundcolor=red,frame=off] \setuphead[chapter][deeptextcommand=\applytofirstcharacter\ChapterFramed] probaly a better interface is possible but it's seldom used so ... upto you to wikify this! Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hi, Most programming languages allow extraction of a character or substring from a string. For example, if I wanted to stylize the word Index: *I...* Index *...X* It would be handy to do something like: \bold{\getcharacter[1]{#!}}... #1 ...\bold{\getcharacter[\stringlength{#!}]} That is a much more flexible solution than only providing a mechanism to get the first character. Is this possible? Kind regards.
Sorry, I missed a {#1}: \bold{\getcharacter[1]{#1}}... #1 ...\bold{\getcharacter[\ stringlength{#1}{#1}]} Best regards.
Am 21.09.2013 um 19:11 schrieb Thangalin
Hi,
Most programming languages allow extraction of a character or substring from a string. For example, if I wanted to stylize the word Index:
I... Index ...X
It would be handy to do something like:
\bold{\getcharacter[1]{#!}}... #1 ...\bold{\getcharacter[\stringlength{#!}]}
That is a much more flexible solution than only providing a mechanism to get the first character.
Is this possible?
You can use Lua! \starttext \cldcontext{string.sub("A short example text!",0,1)} \cldcontext{string.sub("A short example text!",3,7)} \cldcontext{string.sub("A short example text!",-5)} \stoptext Wolfgang
Hi, Wolfgang. I tried dropping in the Lua code, but it does not extract the text: \define[1]\StyleChapter{% \StyleChapterFramed{% \framed[align=right, frame=off]{% \startoverlay \color[ColourSecondaryLightest]{% \cldcontext{string.sub(#1,0,1)} } \vskip-1.9em\hskip1.2em#1 \stopoverlay } } } ! LuaTeX error [string "\directlua "]:1: bad argument #1 to 'sub' (string expected, got nil) I've tried a few variations: \directlua{string.sub(tex.sprint("\luatexluaescapestring{#1}") } \directlua{string.sub("\luatexluaescapestring{#1}",0,1)} \directlua{string.sub(tex.sprint("#1"),0,1)} \cldcontext{string.sub(tex.sprint("#1"),0,1)} Any ideas?
Ah, I think this does it: \cldcontext{string.sub("#1",0,1)}% Automatically expands the macro. Nice.
Am 21.09.2013 um 20:46 schrieb Thangalin
Hi, Wolfgang.
I tried dropping in the Lua code, but it does not extract the text:
\define[1]\StyleChapter{% \StyleChapterFramed{% \framed[align=right, frame=off]{% \startoverlay \color[ColourSecondaryLightest]{% \cldcontext{string.sub(#1,0,1)}
\cldcontext{string.sub("#1",0,1)}%
} \vskip-1.9em\hskip1.2em#1 \stopoverlay } } }
When this doesn’t help you have to provide a complete minimal example.
! LuaTeX error [string "\directlua "]:1: bad argument #1 to 'sub' (string expected, got nil)
I've tried a few variations:
\directlua{string.sub(tex.sprint("\luatexluaescapestring{#1}") } \directlua{string.sub("\luatexluaescapestring{#1}",0,1)} \directlua{string.sub(tex.sprint("#1"),0,1)} \cldcontext{string.sub(tex.sprint("#1"),0,1)}
1. You have to use string.sub in the parameters of tex.sprint. 2. ConTeXt uses \luaescapestring. 3. We use in ConTeXt \ctxlua instead of \directlua. Wolfgang
On 9/21/2013 7:11 PM, Thangalin wrote:
Hi,
Most programming languages allow extraction of a character or substring from a string. For example, if I wanted to stylize the word Index:
*I...* Index *...X*
It would be handy to do something like:
\bold{\getcharacter[1]{#!}}... #1 ...\bold{\getcharacter[\stringlength{#!}]}
tex is macro language so that would not work .. of course I can provide something more clever than the previous hack but not this week (it's not too complex but i need to fool the font system and of course one might wonder if such features make any typographical sense at all esp in automated document processing)
That is a much more flexible solution than only providing a mechanism to get the first character.
in this case #1 == \headtext{#1} so you cannot easily do such things without know what you deal with ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Thangalin
-
Wolfgang Schuster