From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/55496 Path: news.gmane.org!not-for-mail From: Tad Ashlock Newsgroups: gmane.comp.tex.context Subject: Re: Automated Quotation/Punctuation Placement Date: Fri, 08 Jan 2010 14:30:13 -0700 Message-ID: <4B47A3E5.9020400@cyberdude.com> References: <4B475CF9.1050305@cyberdude.com> <28CEDF1F-4AFE-4B44-9A69-3355696FDC00@googlemail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1262986243 11060 80.91.229.12 (8 Jan 2010 21:30:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 8 Jan 2010 21:30:43 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Fri Jan 08 22:30:35 2010 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.50) id 1NTMPj-0000O5-9J for gctc-ntg-context-518@m.gmane.org; Fri, 08 Jan 2010 22:30:35 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id BF5F4C9C98; Fri, 8 Jan 2010 22:30:33 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id DTZFhEzO7R27; Fri, 8 Jan 2010 22:30:31 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 475CBC9BC9; Fri, 8 Jan 2010 22:30:31 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 6D8E9C9BC9 for ; Fri, 8 Jan 2010 22:30:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id PiE-qIbpzPCO for ; Fri, 8 Jan 2010 22:30:27 +0100 (CET) Original-Received: from omspl-da01.mx.aol.com (omspl-da01.mx.aol.com [205.188.170.51]) by balder.ntg.nl (Postfix) with ESMTP id 219ECC9BBC for ; Fri, 8 Jan 2010 22:30:27 +0100 (CET) Original-Received: from rly-mh03.mx.aol.com (rly-mh03.mx.aol.com [64.12.139.199]) by omspl-da01.mx.aol.com (OMS Interface) with ESMTP id F2B743800011B for ; Fri, 8 Jan 2010 16:30:25 -0500 (EST) Original-Received: from [127.0.0.1] (71-210-199-37.albq.qwest.net [71.210.199.37]) by rly-mh03.mx.aol.com (WebSuites/MUA Thirdparty client Interface) with ESMTPA id 96B871C000081 for ; Fri, 8 Jan 2010 16:30:22 -0500 (EST) User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) In-Reply-To: <28CEDF1F-4AFE-4B44-9A69-3355696FDC00@googlemail.com> X-Antivirus: avast! (VPS 100108-1, 01/08/2010), Outbound message X-Antivirus-Status: Clean x-aol-global-disposition: S X-AOL-SCOLL-SCORE: 0:2:391687808:93952408 X-AOL-SCOLL-URL_COUNT: 0 x-aol-sid: 3039400c8bc74b47a3ee69f4 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:55496 Archived-At: 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 }. > > \par > > } > \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 ___________________________________________________________________________________