From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/55494 Path: news.gmane.org!not-for-mail From: Wolfgang Schuster Newsgroups: gmane.comp.tex.context Subject: Re: Automated Quotation/Punctuation Placement Date: Fri, 8 Jan 2010 17:51:08 +0100 Message-ID: <28CEDF1F-4AFE-4B44-9A69-3355696FDC00@googlemail.com> References: <4B475CF9.1050305@cyberdude.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1077) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1262969497 18121 80.91.229.12 (8 Jan 2010 16:51:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 8 Jan 2010 16:51:37 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Fri Jan 08 17:51:30 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 1NTI3d-0008Vn-Pb for gctc-ntg-context-518@m.gmane.org; Fri, 08 Jan 2010 17:51:29 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id D8C1CC9CB0; Fri, 8 Jan 2010 17:51: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 QsdzbFLJkhSw; Fri, 8 Jan 2010 17:51:26 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id F40FFC9C91; Fri, 8 Jan 2010 17:51:25 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 5B614C9C98 for ; Fri, 8 Jan 2010 17:51:24 +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 VHOnMaxvavYq for ; Fri, 8 Jan 2010 17:51:13 +0100 (CET) Original-Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.154]) by balder.ntg.nl (Postfix) with ESMTP id 1AD11C9C91 for ; Fri, 8 Jan 2010 17:51:12 +0100 (CET) Original-Received: by fg-out-1718.google.com with SMTP id 19so1082090fgg.2 for ; Fri, 08 Jan 2010 08:51:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:content-type:mime-version :subject:from:in-reply-to:date:content-transfer-encoding:message-id :references:to:x-mailer; bh=3PIBMhqnEkvOYjC9TS7WnpqCFhAk39i31G09967d0J8=; b=ux0yX2FiGvZciWKHQFIuglxAaIBSAcphnThpyo1zuLBB4gP9pJmeXbVjjWEd91EHI9 /BLJti3utuaNEhc/Uep0iKBzKoKtWqIZo+JYwyzSnW9+RcMHb1vc2cCBerRaS9MwGAoG Nati2TJIPSIR1NKnRIr3aWwbfM79tv2twU+Mc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; b=GE44yUIaJsyZcXB6o2CMBsJ6Uv4EEJUsC9eRnvWbwEhAz26Wmr9AWcK69L6wV3xX0m PGL2Q5OjO/pREf2aj6Q3V8NEtzNMmY1o4aAFCkHHPqMEyTbO3gEthVJPWH9kNerD9ygT 8Js/sfRUSOr/rexVxnin20IK0pyUEPDhXzDBc= Original-Received: by 10.87.50.40 with SMTP id c40mr5494973fgk.54.1262969472784; Fri, 08 Jan 2010 08:51:12 -0800 (PST) Original-Received: from ?192.168.2.23? (p5B29382F.dip.t-dialin.net [91.41.56.47]) by mx.google.com with ESMTPS id d8sm49240221fga.23.2010.01.08.08.51.09 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 08 Jan 2010 08:51:11 -0800 (PST) In-Reply-To: <4B475CF9.1050305@cyberdude.com> X-Mailer: Apple Mail (2.1077) 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:55494 Archived-At: Am 08.01.2010 um 17:27 schrieb Tad Ashlock: > Hi All, > > I'm trying to create a command that will apply a consistent style to a word or phrase. For example, when documenting source code, I'd like to be able to mark variables with \Var{var_name}. Then if I want the variable names to be in mono, I can \def\Var#1{\type{#1}}. No problem there. If I want variable names to be in quotes, then \def\Var#1{\quote{#1}}. > > The problem is that in my ConTeXt code I'd write "This is \Var{var_name}, a variable." Which would get typeset as "This is 'var_name', a variable." where punctuation convention (at least in American English) would have the comma inside the quote like this: "This is 'var_name,' a variable." > > I've tried four different ways of implementing this, but none of them work consistently. Here's my last attempt: > > ========================== > \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.} > > and the following error results: > ========================== > systems : begin file test.tex at line 16 > ! Missing $ inserted. > > $ > > _ > l.1 ...spaces quote{unskip ignorespaces type{var_ > name} > \Var ...=],[==[#2]==], '\\quote{\\type{','}','}')} > l.18 \framed{This is \Var{var_name}, > a variable.} > ? > ========================== > > I think my problem has to do with parameter expansion, but I don't understand the intricacies enough to solve this. I flailed away, unsuccessfully, with various combinations of \unexpanded, \normalunexpanded, luaescapestring, etc. > > Does anyone have a solution or a pointer in the right direction? \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 ___________________________________________________________________________________ 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 ___________________________________________________________________________________