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:30:13 -0700	[thread overview]
Message-ID: <4B47A3E5.9020400@cyberdude.com> (raw)
In-Reply-To: <28CEDF1F-4AFE-4B44-9A69-3355696FDC00@googlemail.com>

Wolfgang Schuster wrote:
> Am 08.01.2010 um 17:27 schrieb Tad Ashlock:Hi All,
>>
>> ========================
>> \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
>> ========================
>>
>> This works, until the \Var{} macro appears in the argument of another macro.  For example, make the text:
>>
>> \framed{This is \Var{var_name}, a variable.}
>
> \nonknuthmode % make '_' a normal character in text mode
>
> \define[1]\Var
>   {\doifnextcharelse{,}{\doVar{#1,}\gobbleoneargument}{\noVar{#1}}}
>
> \define[1]\doVar
>   {\mono{#1}}
>
> \define[1]\noVar
>   {\mono{#1}%
>    \doifnextcharelse{;} % \autoinsertnextspace is no longer available in MkIV :(
>      {\donothing}
>      {\doifnextcharelse{.}
>         {\donothing}
>         {\space}}}
>
> \starttext
>
> This is \Var{var_name}, a variable.
>
> This is \Var{var_name,} a variable.
>
> \framed{This is \Var{var_name}, a variable.}
>
> \stoptext
>
> Wolfgang


Thanks for responding Wolfgang.  But this solution has some problems.

The first problem is that it only works for commas.  I'm sure I can 
figure out how to next the \doifnextcharelse commands to add periods, 
question marks, and exclamation points, but then the command becomes 
rather unwieldy.  Not really a problem for a single command, but this 
leads to...

Problem number 2 is that I'm going to need many of these commands for 
different types of things.  I'd like to abstract out the "punctuation 
swapping" so that it doesn't have to be repeated for each command.

But the show-stopper is problem number 3: this solution still breaks in 
other places, like captions:

========================
\starttext
\placefigure
[left]
{This is \Var{var_name}, a variable.}
{\framed{And \Var{another_var_name} is yet another variable.}}
\stoptext
========================

results in:

========================
> ! Argument of \gobbleoneargument has an extra }.
> <inserted text>
>                 \par
> <to be read again>
>                    }
> \doifnextcharelse ...token =#1\def \!!stringa {#2}
>                                                   \def \!!stringb 
> {#3}\futur...
> \@@kjfiguretitle ->This is \Var {var_name}
>                                           , a variable.
> \doif #1#2->\edef \!!stringa {#1
>                                 }\edef \!!stringb {#2}\ifx \!!stringa 
> \!!str...
> \dostructurecountercomponent ...\c!title }\v!none
>                                                   {\setfalse 
> \hasstructureco...
> ...
> l.47 ...other_var_name} is yet another variable.}}
>                                                  
> ?
========================

This is the sort of problem I was flailing around with.  I'd get a 
definition that worked in one case, but broke in another.  One attempt 
broke when I included a table of contents.

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:30 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 [this message]
2010-01-08 17:01 ` Khaled Hosny
2010-01-08 21:50   ` Tad Ashlock

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=4B47A3E5.9020400@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).