From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/55493 Path: news.gmane.org!not-for-mail From: Tad Ashlock Newsgroups: gmane.comp.tex.context Subject: Automated Quotation/Punctuation Placement Date: Fri, 08 Jan 2010 09:27:37 -0700 Message-ID: <4B475CF9.1050305@cyberdude.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 1262968091 12992 80.91.229.12 (8 Jan 2010 16:28:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 8 Jan 2010 16:28:11 +0000 (UTC) To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Fri Jan 08 17:28:04 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 1NTHgy-0005WJ-8S for gctc-ntg-context-518@m.gmane.org; Fri, 08 Jan 2010 17:28:04 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 94B71C9C9A; Fri, 8 Jan 2010 17:28:04 +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 uJ519agq-5oo; Fri, 8 Jan 2010 17:28:01 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id DD385C9C85; Fri, 8 Jan 2010 17:28:01 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id E6B00C9C85 for ; Fri, 8 Jan 2010 17:28:00 +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 mXLcrGlg1W5V for ; Fri, 8 Jan 2010 17:27:49 +0100 (CET) Original-Received: from omspl-da02.mx.aol.com (omspl-da02.mx.aol.com [205.188.170.52]) by balder.ntg.nl (Postfix) with ESMTP id 7BBEEC9C68 for ; Fri, 8 Jan 2010 17:27:49 +0100 (CET) Original-Received: from rly-dh04.mx.aol.com (rly-dh04.mx.aol.com [205.188.157.8]) by omspl-da02.mx.aol.com (OMS Interface) with ESMTP id 96D6E38000228 for ; Fri, 8 Jan 2010 11:27:48 -0500 (EST) Original-Received: from [127.0.0.1] (71-210-199-37.albq.qwest.net [71.210.199.37]) by rly-dh04.mx.aol.com (WebSuites/MUA Thirdparty client Interface) with ESMTPA id D01BB38000081 for ; Fri, 8 Jan 2010 11:27:46 -0500 (EST) User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) X-Antivirus: avast! (VPS 100108-0, 01/08/2010), Outbound message X-Antivirus-Status: Clean x-aol-global-disposition: S X-AOL-SCOLL-SCORE: 0:2:407415776:93952408 X-AOL-SCOLL-URL_COUNT: 0 x-aol-sid: 3039cdbc9d084b475d0233d5 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:55493 Archived-At: 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? Thank you, 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 ___________________________________________________________________________________