Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by h1439878.stratoserver.net (8.14.2/8.14.2/Debian-2build1) with ESMTP id s477bota020881 for ; Wed, 7 May 2014 09:37:51 +0200 Received: from relay.uni-heidelberg.de ([129.206.100.212]) by mx-ha.gmx.net (mxgmx007) with ESMTPS (Nemesis) id 0MTfNo-1WHRKC29su-00QWSf for ; Wed, 07 May 2014 09:37:45 +0200 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id s477YvNd004673 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 7 May 2014 09:34:57 +0200 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [127.0.0.1]) by listserv.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id s46M13wO001573; Wed, 7 May 2014 09:34:56 +0200 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 10865776 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Wed, 7 May 2014 09:34:56 +0200 Received: from relay.uni-heidelberg.de (relay.uni-heidelberg.de [129.206.100.212]) by listserv.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id s477Yu2m024703 for ; Wed, 7 May 2014 09:34:56 +0200 Received: from smtp2.easily.co.uk (smtp2.easily.co.uk [62.128.146.103]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id s477YnR8004603 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 7 May 2014 09:34:51 +0200 Received: from [139.222.114.112] (port=50381 helo=[139.222.114.112]) by smtp2.easily.co.uk with esmtpa (Exim 4.43) id 1WhwNM-0007oI-Oo for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Wed, 07 May 2014 08:34:48 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 References: <5366C875.9040709@googlemail.com> <5367453E.3030906@morningstar2.co.uk> <5369962B.2020905@gmail.com> <5369D54F.10503@googlemail.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Message-ID: <5369E218.4090809@morningstar2.co.uk> Date: Wed, 7 May 2014 08:34:48 +0100 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Joseph Wright Subject: Re: \__dim_strip_bp:n To: LATEX-L@LISTSERV.UNI-HEIDELBERG.DE In-Reply-To: <5369D54F.10503@googlemail.com> Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: Envelope-To: X-GMX-Antispam: 0 (Mail was not recognized as spam); Detail=V3; X-GMX-Antivirus: 0 (no virus found) X-UI-Filterresults: notjunk:1;V01:K0:4A31y8NT+Ns=:ohtvjr/jfZAn3iiP7EUEmHPFO+ QZhgnFqpfYhObt9WGZyRjYPpQW9U0BCwxRBZQjypG7aIL1KMAdwZ7adX13kwZ9qTDww52Nrcu hYRELeThMCX8KwVqhdvbM7iObLmSJJ14gmDTTMVMjEuCidAQshLzjj6VrQavlQ4suygfRCKRI 756m8eIx3PWq/3u09bfUkCZmeBJlbNAPXxreCserUhSJkFBBBclRXu8UeKJmZdulhdaPYc8Ix L024F7KuqTwWVeB6suGAFjJGU3ptn51mQ9lfn5l/Fdkd2tTb8FYeUbP5jb9alpEqRS41oTdal G3+pOiZ0/zWQs5yGXt5QRpItxOftY4SnPsdxF5mnXRnxnpc2iLHuxXEd5fDn60JzTcGqnsn+m E3V+R0e7UY1Nw92oCmq5tT1fYOPLwAGQ+VXvBMJ4/vH7xvJI67jx5VIkfJnu+3tBjFNYvHmBa zRXx9hzu8o2TJVaHI0Qi66aOKOzNmRcNoMR5IOAteB90JZnOr8kbLQ2qh1v5nBBflQHebAY+j EUdvspPDweh98cnADXBgb8h5sJnHX0QXUNZulHQH3xnQIflxFWxhJTr7WdDwb4RCFYL9RlMJM pekcuOlnlF7Y4rvZAwi0GSZe1FZTl6wCjv1JNU7iMPuMp6Ay6zaUSm1HHdrCp+IyXYhf9GX03 tZSkCQMk/f28TjiiA69njngvj7M8fS7rB+wO9sOx42XqWIHPK1jZ5rsvt0DewXTYOecS7Evjq uIzbqTy9+Kwi9gcWh8fTwrKCO/9uQQnxIrq6+shF1FJRb/DaJcMXxplD1lthL5bWyF2sibYtT StvCUJ+c6K2iN1YhfAXywIRUcl+VDkZbrzWeHBdClpeSvstGjC1nMFiy4K0Qw6v44dxI53B8t CRT/yte68EHgSsmq7iTyPdql1qAYB0N8qdhYdy5YbGMieMY/mmHMsDPuMZTcDWENT9W02Pxit +7l/x3JjLzAVuAHym0dLatEBUMcjUO6uMC2h7O3BD6ZKKm1P87uO/MmAxob03R7DSxbT8SeSq J41cRIHtsXLiDOWFQWjM7Z22JSzSLJ9WBsPj33WsgaYoOf5vVbtIs2oeFz0zRbeen17Wa3XTB 4TnF0NvPgumJ8qya86S8/Ik1A06gxXllV3AUjucw3bk4RCBGDbiSYERi2I8Bb1Cz//gMna3mO NkqwtIbxjwmxuqH1vEvesg/RYgNShtADuefyOuvwIggjzyR215lAjR768qzcsrz7FNv88nevr QHtUDRFuYGYgXQeKBWUALr5Id7petj0jRfgEWbX1kue1WBCWKKdfzkoZD368HLWsnSYlLaXRf HirIcdas6zBntpbQ2LOJMaYLZvlTZXXBjciOSz+hqv8+ICEDSOAvc44aENbyinayTcqWMjbMj UvOHPIOmG77mJARGxYjEwM3iYqny3V/nc/NVwAXGPL80c5CQ7nhLfqLaOwKk4lJMeVGUmCblx lKu+A3PA== X-UI-Loop:V01:XR6xRlFObHM=:f7DyCk7xBw9qrTuyYcgbp3qu58SEHI7cfGM+/andfFY= Status: R X-Status: X-Keywords: X-UID: 7400 On 07/05/2014 07:40, Heiko Oberdiek wrote: > On 07.05.2014 04:10, Qing Lee wrote: >> On 2014-05-05 at 16:01:02 +0800 GMT, Joseph Wright wrote: >>> On 05/05/2014 00:08, Heiko Oberdiek wrote: > >>>> \cs_new:Npn \__dim_strip_bp:n #1 >>>> { \__dim_strip_pt:n { 0.996 26 \__dim_eval:w #1 \__dim_eval_end: >>>> } } > >>>> \dimexpr 0.99626\dimexpr #1\relax\relax > >>>> Improved version with higher precision: >>>> >>>> \cs_new:Npn \__dim_strip_bp:n #1 >>>> { >>>> \__dim_strip_pt:n >>>> { >>>> \__dim_eval:w ( #1 ) * 800 / 803 \__dim_eval_end: >>>> } >>>> } > >> The new definition will be broken if its argument contains additional >> units. E.g., >> >> \__dim_strip_bp:n { 1 bp pt } > > The second "unit" is just additional text that serves > no purpose other than invalidating the argument. > > In the old version, the argument is put into: > > \dimexpr 1bp pt \relax > > A better syntax for e-TeX's \dimexpr would have been: > \dimexpr{...} > or at least ending the expression with a *mandatory* \relax: > \dimexpr ...\relax > > With an optionally \relax, the dimen expression ends > with the first token that does not belong to the > expression, in this case it is the letter "p". > > However the additional text will *not* go away and > will very likely causing trouble some time later, > a more mysterious error message or even worse, > the text could go silently into the output. > > Adding parentheses around "#1" gets an input validation > check for free. I seriously doubt that \__dim_strip_bp:n > should accept something like > > \__dim_strip_bp:n { 1 bp Lorem ipsum dolor sit ... } > > Also look at the names: > > \__dim_eval:w #1 \__dim_eval_end: > > The intention is very clear, that \__dim_eval_end: > is meant to *end* the dimen expression, not to add > an additional \relax in the input token list. > > Therefore I think, that the new version is also an > improvement for invalid arguments, because most > cases of illegal input are detected and this happens > at an earlier stage, that makes debugging and > hunting the bug easier, that had introduced the > additional text. > > Best regards > Heiko Oberdiek Before making any further changes (and adding tests for the defined behaviour), I think it's worth briefly considering why \__dim_strip_pt:n and \__dim_strip_bp:n are (currently) documented as accepting multiple units in the argument. (I was drafting this message before Heiko's reply!) While it's not in the sources, from memory the idea was that allowing input such as \__dim_strip_bp:n { 1 bp pt } means that at a 'higher level' something like \cs_new:npn \foo #1 { \_dim_strip_bp:n { #1 pt } } will work with \foo { 1 bp } and \foo { 1 } % Assumes pt will work. The idea was, I think, allowing an approach something like \@defaultunits in the LaTeX2e kernel or \Gin@defaultbp in graphics but in an expandable form. Now, that may not be a good plan: the functions here are supposed to be relatively low-level (they are for writing driver code), and it is likely to be better to require 'properly defined' units on the input. As I say, before I make any further change here it would be useful to have a proper idea of what is actually required. -- Joseph Wright