ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Tad Ashlock <taashlo@cyberdude.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Automated Quotation/Punctuation Placement
Date: Fri, 08 Jan 2010 14:50:30 -0700	[thread overview]
Message-ID: <4B47A8A6.8040604@cyberdude.com> (raw)
In-Reply-To: <20100108170141.GA2153@khaled-laptop>

Khaled Hosny wrote:
> On Fri, Jan 08, 2010 at 09:27:37AM -0700, Tad Ashlock wrote:
>>
>> ==========================
>> \startluacode
>> function move_end_punctuation (text, punc, cmd_start, cmd_mid, cmd_end)
>>    context(cmd_start .. text .. cmd_mid)
>>    if string.find('.,!?', punc, 1, true) then
>>        context(punc .. cmd_end)
>>    else
>>        context(cmd_end .. ' ' .. punc)
>>    end
>> end
>> \stopluacode
>>
>> \def\Var#1#2{\ctxlua{move_end_punctuation([==[#1]==],[==[#2]==],
>>    '\\quote{\\type{','}','}')}}
>>
>> \starttext
>>
>> This is \Var{var_name}, a variable.
>>
>> \stoptext
>> ==========================
> What about:
>
>
> \def\Var#1#2{'\type{#1}%
> \directlua{
> if "#2" == "," then
>   tex.sprint("#2'")
> else
>   tex.sprint("'#2")
> end}}
>
>
> \Var{555}, hello \Var{666}. \Var{666}\par
>


Thank you, Khaled, for the response.  This solution works as is.  But it 
has a problem as soon as you want to put double quotes around the 
variable name.

Simply replacing the single quotes with double quotes in your solution 
doesn't produce open- and close-quotes pairs:

==================
\def\Var#1#2{"\type{#1}%
\directlua{
if "#2" == "," then
  tex.sprint('#2"')
else
  tex.sprint('"#2')
end}}
==================

In order to do that, you need (I think) to use the \quotation{} command:

==================
\def\Var#1#2{\quotation{\type{#1}%
\directlua{
if "#2" == "," then
  tex.sprint("#2}")
else
  tex.sprint("}#2")
end}}
==================

resulting in:

==================
! Too many }'s.
l.7 end}}
==================

I also tried \bgroup...\egroup:

==================
\def\Var#1#2{\quotation\bgroup\type{#1}%
\directlua{
if "#2" == "," then
  tex.sprint("#2\egroup ")
else
  tex.sprint("\egroup #2")
end}}
==================

giving:

==================
! Missing } inserted.
<inserted text>
                }
<to be read again>
                   \normalend
l.18 \stoptext
==================

Thanks again!
Tad

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


      reply	other threads:[~2010-01-08 21:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-08 16:27 Tad Ashlock
2010-01-08 16:51 ` Wolfgang Schuster
2010-01-08 21:30   ` Tad Ashlock
2010-01-08 17:01 ` Khaled Hosny
2010-01-08 21:50   ` Tad Ashlock [this message]

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=4B47A8A6.8040604@cyberdude.com \
    --to=taashlo@cyberdude.com \
    --cc=ntg-context@ntg.nl \
    /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).