From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/55495 Path: news.gmane.org!not-for-mail From: Khaled Hosny Newsgroups: gmane.comp.tex.context Subject: Re: Automated Quotation/Punctuation Placement Date: Fri, 8 Jan 2010 19:01:41 +0200 Message-ID: <20100108170141.GA2153@khaled-laptop> References: <4B475CF9.1050305@cyberdude.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1320820776==" X-Trace: ger.gmane.org 1262970130 20500 80.91.229.12 (8 Jan 2010 17:02:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 8 Jan 2010 17:02:10 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Fri Jan 08 18:02:02 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 1NTIDq-00052w-4v for gctc-ntg-context-518@m.gmane.org; Fri, 08 Jan 2010 18:02:02 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id C7CF6C9CB7; Fri, 8 Jan 2010 18:02:02 +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 lxFhK9h1pdpG; Fri, 8 Jan 2010 18:02:00 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 4FC95C9CA8; Fri, 8 Jan 2010 18:02:00 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 4BBCEC9CA8 for ; Fri, 8 Jan 2010 18:01:58 +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 UE0hKM-vqyIA for ; Fri, 8 Jan 2010 18:01:46 +0100 (CET) Original-Received: from mail-ew0-f213.google.com (mail-ew0-f213.google.com [209.85.219.213]) by balder.ntg.nl (Postfix) with ESMTP id 5DB92C9CA7 for ; Fri, 8 Jan 2010 18:01:46 +0100 (CET) Original-Received: by ewy5 with SMTP id 5so8157042ewy.34 for ; Fri, 08 Jan 2010 09:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:date:from:to:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=0gJntXPqZ4rq8i43CD6uimLCdT4oofkVwy3u4aCAsuc=; b=LqL5ifC+whR4gBRsjgS4WN7AcUTsfga/cXQOVQt5MCVGiNXQ1+zMsdGsADBrUpVnPG xbKbL+UuWYO8MthG2BGgsyB8UCcSUxAgcFbPtN4VELSPXWThEiaeXALn/4WVEvlWnwuf HulcNfX4cYSxcGMjFjxV9Hib487aIanXU0H1g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=BVPUSx+UpFpSWjy0tcnj3Gewqlioln5MNfxzXS/7oiEox3lInBzFC9vQ1IT4wOVAc7 6h6QwyLL1e2yW3fskzxUqiSlJwa/7gja/LuDBmw37DcWVCnZfK+JMauRhitY0Qdi4fDE TyHgw7HsL0uk9hgTznqRB90+uk4ZhGtiHP+o0= Original-Received: by 10.213.39.210 with SMTP id h18mr10427138ebe.96.1262970106030; Fri, 08 Jan 2010 09:01:46 -0800 (PST) Original-Received: from localhost ([41.238.232.75]) by mx.google.com with ESMTPS id 13sm16075031ewy.1.2010.01.08.09.01.44 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 08 Jan 2010 09:01:44 -0800 (PST) In-Reply-To: <4B475CF9.1050305@cyberdude.com> User-Agent: Mutt/1.5.20 (2009-06-14) 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:55495 Archived-At: --===============1320820776== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="fdj2RfSjLxBAspz7" Content-Disposition: inline --fdj2RfSjLxBAspz7 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable What about: \def\Var#1#2{'\type{#1}% \directlua{ if "#2" =3D=3D "," then tex.sprint("#2'") else tex.sprint("'#2") end}} \Var{555}, hello \Var{666}. \Var{666}\par On Fri, Jan 08, 2010 at 09:27:37AM -0700, Tad Ashlock wrote: > Hi All, >=20 > 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}}. >=20 > 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." >=20 > I've tried four different ways of implementing this, but none of > them work consistently. Here's my last attempt: >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D > \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 >=20 > \def\Var#1#2{\ctxlua{move_end_punctuation([=3D=3D[#1]=3D=3D],[=3D=3D[#2]= =3D=3D], > '\\quote{\\type{','}','}')}} >=20 > \starttext >=20 > This is \Var{var_name}, a variable. >=20 > \stoptext > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D >=20 > This works, until the \Var{} macro appears in the argument of > another macro. For example, make the text: >=20 > \framed{This is \Var{var_name}, a variable.} >=20 > and the following error results: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D > systems : begin file test.tex at line 16 > ! Missing $ inserted. > > $ > > _ > l.1 ...spaces quote{unskip ignorespaces type{var_ > name} > \Var ...=3D],[=3D=3D[#2]=3D=3D], '\\quote{\\type{','}','}')} > l.18 \framed{This is \Var{var_name}, > a variable.} > ? > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D >=20 > 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. >=20 > Does anyone have a solution or a pointer in the right direction? >=20 > Thank you, > Tad >=20 >=20 >=20 > _________________________________________________________________________= __________ > If your question is of interest to others as well, please add an entry to= the Wiki! >=20 > maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-co= ntext > webpage : http://www.pragma-ade.nl / http://tex.aanhet.net > archive : http://foundry.supelec.fr/projects/contextrev/ > wiki : http://contextgarden.net > _________________________________________________________________________= __________ --=20 Khaled Hosny Arabic localiser and member of Arabeyes.org team Free font developer --fdj2RfSjLxBAspz7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAktHZPUACgkQRoqITGOuyPJ2NACePXMrvTaBLLTi9hX9Mbu8UDKi /1oAn0BeQGV72xM+mYH+pI0QhdtRb5Pn =oNOv -----END PGP SIGNATURE----- --fdj2RfSjLxBAspz7-- --===============1320820776== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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 ___________________________________________________________________________________ --===============1320820776==--