0

I have a package for \hg and \hgunits as given here

I wanted to use it like this:

\item svoboda a volnost {\jednotky{22}}
\item \def\aa{\value\modulo{152123}{10}}

{\hg
\hgunits{\aa}
} 

HERE

{\hg
\hgunits{2}
} 

WORKS but

{\hg
\hgunits{\aa}
} 

DOES NOT.

ALSO \jednotky{22} prints the correct value 2 when called alone.

I would like to know how to fix it.

the package:

\usepackage[nomessages]{fp}

\newcommand{\modulo}[2]{%
\FPeval{\result}{trunc(#1-(#2*trunc(#1/#2,0)),0)}\result%
}

\newcommand\jednotky[1]{
$\modulo{#1}{10}$
}
user2925716
  • 1,940
  • can you replace \def\hgunits by \edef\hgunits, which expands the argument – ebcontrol Oct 07 '19 at 12:59
  • 2
    \value is a macro that takes one argument so \value\modulo is the same as \value{\modulo} which causes all sorts of errors, you intended \value{\modulo{152123}{10}} but that also will do nothing useful as the argument to \value is the name of a counter, like section or enumi also do not use \aa as the name, that is a standard latex command. – David Carlisle Oct 07 '19 at 13:02
  • @ebcontrol Some other error occurs with edef: (D:\ProgramFiles\MikTexNEW\tex/latex/fp\fp-eval.sty)) ! Missing number, treated as zero. ## l.19 \edef\hgunits#1{\ifcase# 1?\or ?

    ! Emergency stop.

    ## l.19 \edef\hgunits#1{\ifcase# 1?\or No pages of output.
    – user2925716 Oct 07 '19 at 13:19
  • guessing why you are doing mod 10 arithmetic I added a \hgnum command to https://tex.stackexchange.com/a/511167/1090 that takes a number and expands to the hieroglyph typesetting, no mod 10 arithmetic is needed. – David Carlisle Oct 07 '19 at 13:28
  • @DavidCarlisle That's nice! Could you please explain to me this yours command: \def\hgnum#1{{\hg\expandafter\hgnumx\the\numexpr10000000+#1\relax}} ? I would like to study it in depth. – user2925716 Oct 07 '19 at 13:39
  • @u it just adds a big enough number so you always have a known number of digits then can simply extract the digits using #3#4#5#6#7#8 (#1 and #2 are always 10 and discarded) this assumes you never need a 7-digit number – David Carlisle Oct 07 '19 at 13:42
  • @DavidCarlisle Could you please also complete for me this numbering stuff? This one gives me an error: \begin{enumerate}[ label=\roman{enumi}--\arabic{enumi}--!!!!!\babyloniannum{\value{enumi}}!!!--\large\ngg\symbol{\numexpr "13000+\value{enumi}}--\hgnum{enumi}] – user2925716 Oct 07 '19 at 13:48
  • @user2925716 please don't ask new questions in comments. You would get an error for \! irrespective of the counters, it is a math mode command. I have no idea what \babyloniannum is (and this is not the place to define it in comments on an unrelated question) – David Carlisle Oct 07 '19 at 13:52
  • @DavidCarlisle NO without \hgnum it works fine. I'm asking another question here – user2925716 Oct 07 '19 at 13:59
  • @DavidCarlisle Could you please explain why in your comment above you claim that "(#1 and #2 are always 10 and discarded)" Do you mean that they are always less than 10 ? – user2925716 Oct 13 '19 at 18:29
  • @user2925716 look at the definition, it does not use #1 or #2(they are always 1 and 0 that were added to force the padding) – David Carlisle Oct 13 '19 at 18:32

1 Answers1

2

As noted in comments

\def\aa{\value\modulo{152123}{10}}

the command name should not be \aa as that over-writes a standard latex command. \value is a macro that takes a single argument so here, with no braces it gets the argument \modulo (not \modulo{152123}{10}).

The intended usage is \hgunits{\aa} but \hgunits is a simple \ifcase checking values 0-9 so the argument has to expand to a number.

fp package calculations do not work via expansion,

 \FPeval{\result}{trunc(#1-(#2*trunc(#1/#2,0)),0)}\result%

first assigns a value to \result (like \def or \newcommand`) and the uses that result, you can not use such an assignment as code that must expand to a number.

There are packages that do expandable arithmetic (xfp for example) but for the intended use case you can just extract the digits from the decimal form of the number, you do not need to do modulo 10 arithmetic, see the updated answer

https://tex.stackexchange.com/a/511167/1090

David Carlisle
  • 757,742