I have to make an assignment about converting base-n notation to decimal and vice versa.
We are allowed to make it on paper, and send it in digitally by scanning. However, I'd like to send it in using LaTeX. Because I think it's an interesting technology which can come very handy in the future to handle.
Unfortunately I don't know yet how to use it properly, I don't feel the same 'freedom' as I'd have with e.g LibreOffice Writer.
But an helping hand can solve that!
This is what I have on paper:
How would I make that nice in LaTeX?
This is what I need to know:
How to…
- Put a small number (base number) in small right-bottom of the notation
- Make those arrows (down and than right)
- Bullet for multiply-sign
- Exponent
- Make that add-notation, with that line and plus-sign
- All nicely formatted?
To be clear, I'm not asking any of you to do this all for me. But to put my in the right direction or give examples on how to accomplish this. Thanks!
Best Answer
First version uses LaTeX's picture as enhanced by
pict2e
and it only handles bases less then (or equal to) 10, some extra macros would be needed for higher bases (from digits in the base to actual number in base 10 understood by TeX; the case of bases <= 16 could be handled directly as in v2).Second version works with bases up to 16 and it uses TikZ's tikzpicture for fancier graphics. I went a bit overboard when I started playing with xcolor color series... Also the method uses tabular's allowing easier to right align things than in v1 with direct
\put
.Regarding the basic TikZ method for setting up nodes and then drawing arrows from one tabular to the other, I copied it from https://tex.stackexchange.com/a/400571/4686. It needs at least two compilations.
In an edit, I have simplified a bit the coding of v2 (removal of usage of
\xintAssignArray
, as the\xintFor*
loops are used directly on the number to be converted without having first made it into an "array"). For v2, the number passed as second argument to\ConvertFromBase
may be a macro (if it is completely expandable in an\edef
).finally I add also for conversion from decimal to another base: at most 36 because Latin alphabet has 26 letters (I don't know the consensus on notation beyond that). This was also mentioned in OP but with no concrete layout proposed. If a separate question gets asked I will move that part to an answer there.
Last remark: the conversion routines are tailored by the display constraints. For numbers with hundreds of digits, one would proceed differently (as it is not realistic to display like here and only the result of the conversion matters). The macros here do not necessarily define a macro expanding to the converted number, as they are only preoccupied with typesetting the process.
v1
v2
Conversion from decimal to another base. The target base is at most 36.
The OP mentioned this was also asked for but gave to model layout. I chose the one which made the curves easier to manage.
For base 2, the layout taking much vertical space limits us to some small example...