vincentb1 / fmtcount

Source for LaTeX fmtcount package
11 stars 5 forks source link

\Hexadecimal somewhat inconsistent #35

Open FrankMittelbach opened 6 years ago

FrankMittelbach commented 6 years ago

By convention you have \xxx (lowercase result) \Xxx (first letter uppercase) \XXX all uppercase, e.g., you use \AAalph not \Aaalph or \ORDINALstring. The only exception is \Hexadecimal which should therefore be called \HEXAdecimal in my opinion. Maybe \HEXAdecimal should be provided and simply giving the same result as \Hexadecimal (to keep backward compatibility) -- or maybe not, I was just noticing

vincentb1 commented 6 years ago

Well, with a hexadecimal number you would either put all in capital, or all in lower case, but it does not really make sense to have the first letter only in capital, because the 1st character can be either a digit or a letter — so in the case of a digit you would do nothing, just as with a number not using any letter anyway… Maybe \HEXADECIMAL would make more sense than \HEXAdecimal. OK, I see that you mean that \HEXAdecimal means uppercasing all the hexa digits (A B C D E F), and not the decimal digits (0 1 2 3 4 5 6 7 8 9). But that is not really what the code does. The results dépends on the definition of \@@hexadecimal and \@@Hexadecimal which are simply an \ifcase…\fi (not any call to uppercase for \@@Hexadecimal). And conceptually, assume there would be upper case arabic digits, I don't think that \Hexadecimal was meaning not using them, they are not used just because they do not exist, not because it not was desired to use them.

BTW, @nlct, I think that we could factorize the two macros by having two arguments to \@hexadecimal and passing either \@@hexadecimal or \@@Hexadecimal as the 1st argument,

vincentb1 commented 6 years ago

@nlct, don't take me wrong, to keep the robustness, we could have something like (\@hexadecimalengine is the factorized code).


\newrobustcmd*{\@hexadecimal}[1]{\@hexadecimalengine\@@hexadecimal}
\newrobustcmd*{\@Hexadecimal}[1]{\@hexadecimalengine\@@Hexadecimal}
\newcommand*{\@hexadecimalengine}[2]{%
  \@DT@padzeroestrue
  \@DT@loopN=\@vpt
  \@strctr=\@DT@loopN
  \whiledo{\@strctr<\c@padzeroesN}{0\advance\@strctr by \@ne}%
  \@strctr=65536\relax
  \@DT@X=#2\relax
  \loop
    \@DT@modctr=\@DT@X
    \divide\@DT@modctr by \@strctr
    \ifthenelse{\boolean{@DT@padzeroes}
      \and \(\@DT@modctr=0\)
      \and \(\@DT@loopN>\c@padzeroesN\)}
    {}{#1\@DT@modctr}%
    \ifnum\@DT@modctr=0\else\@DT@padzeroesfalse\fi
    \multiply\@DT@modctr by \@strctr
    \advance\@DT@X by -\@DT@modctr
    \divide\@strctr by 16\relax
    \advance\@DT@loopN by \m@ne
  \ifnum\@strctr>\@ne
  \repeat
  #1\@DT@X
}
FrankMittelbach commented 6 years ago

Am 30.05.18 um 20:12 schrieb Vincent Belaïche:

Well, with a hexadecimal number you would either put all in capital, or all in lower case, but it does not really make sense to have the first letter only in capital, because the 1st character can be either a digit or a letter — so in the case of a digit you would do nothing, just as with a number not using any letter anyway…

all I was saying is that if I look across all your naming conventions then these commands are somewhat inconsistent. No harm really but I personally like clear simple rules and elsewhere using just the first char in uppercase means you only uppercase the first character in the output.

Of course I agree it makes less/no sense to treat a hexadecimal like a word so you really probably only want everything lower or everything upper, by question was what should the command be named that does that and according to what you do elsewhere it would be \HEXAdecimal or \HEXADECIMAL not \Hexadecimal (which conceptually should uppercase only the first char if it is a letter)

vincentb1 commented 6 years ago

OK, then let us keep simple and opt out for \HEXADECIMAL, not \HEXAdecimal. I would just keep \Hexadecimal with a « this macro is deprecated, use \HEXADECIMAL » warning.

@nlct Nicola, do you agree with me that it is an opportunity to make some code factorizing as suggested in this comment, or do you think we should do only minimal changes to the code. Of course before doing the factorization I would check that the test bench does sufficient non regression coverage, and upgrade it otherwise.

vincentb1 commented 6 years ago

BTW, for the naming, there was one more option which is \HEXADecimal, just to get inspired from the \AAAlph and \ABAlph which after all, from the case perspective, are just respectively \AA + Alph and \AB + Alph. So we full-uppercase for the prefix (AA or AB) and only the first letter for the radix word (Alph). The same thinking with word « hexadecimal » would lead to « HEXADecimal », provided that you consider « hexa » as some prefix.

vincentb1 commented 6 years ago

Just as a side comment, one advantage of \HEXADecimal over \HEXADECIMAL is that it helps remember that the uppercase version of \aaalph is \AAAlph, not \AAalph as Frank wrote in his first comment. Also, if you don't cap-lock but just keep the shift key down, this is less writing work.

I have pushed an updated manual to HEAD of branch version_3.05+, where I used HEXADECIMAL, not HEXADecimal or HEXAdecimal, but I am quite open to critics. I also made quite a few other fixes:

Please tell me if you like it.

FrankMittelbach commented 6 years ago

I think \HEXADecimal is the most consistent naming given the other commands.

nlct commented 6 years ago

\HEXADecimal sounds best (with \Hexadecimal as a synonym for backward compatibility).

@vincentb1 You can make the code refactorizations that you consider appropriate. The code still has some legacy naming for internal commands (\@DT@ prefixes) leftover from when it was part of the datetime package (back in the late 1990s / early 2000s).

nlct commented 6 years ago

The code still has some legacy naming for internal commands (\@DT@ prefixes) leftover from when it was part of the datetime package (back in the late 1990s / early 2000s).

On reflection, I think it may be best not to rename the \@DT@... commands. Since they were originally defined in datetime, some of them may still be in datetime.sty. (It's now obsolete and its use is deprecated, but it may still be needed for legacy documents.)

vincentb1 commented 6 years ago

Funny, I thought that the English for « à la réflexion » was « on second thoughts », had I heard « on reflection » from a French person, I would have taken it for a false cognate…

Anyhow, here are some thoughts, when I keep \Hexadecimal and \Hexadecimalnum, but I just insert a \PackageWarning to tell people that it is deprecated, it works almost fine, except that the \PackageWarning causes some trouble when cross referencing is at stake. So doing so somehow breaks the backward compatibility. In my opinion the breach is however acceptable because the warning is sufficient for people to understand what happens…

vincentb1 commented 6 years ago

BTW, I have pushed all the changes to the repo. Please feel free for any comments/brickbats…