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:40:15 +0200
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:
Heiko Oberdiek <[log in to unmask]>
Parts/Attachments:
text/plain (70 lines)
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

ATOM RSS1 RSS2