LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Wed, 7 May 2014 08:34:48 +0100
Reply-To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Message-ID:
Subject:
MIME-Version:
1.0
Content-Transfer-Encoding:
7bit
In-Reply-To:
Content-Type:
text/plain; charset=UTF-8
From:
Joseph Wright <[log in to unmask]>
Parts/Attachments:
text/plain (107 lines)
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

ATOM RSS1 RSS2