See the code that follows.
The user gives some pairs of numbers. Each time they happen also to be displayed.
Finally they are added up in a specific way.
\documentclass{article}
%\def\Result...
\newcount{\A}\A=0
\newcount{\B}\B=0
\newcount{\C}\C=0
\def\XYZ{#1,#2}{\textbf{#1}---\textbf{#2}\A=#1\B=#2\multiply\A by 100\advance\C by \A\advance\C by \B}
\begin{document}
\XYZ{4,30}
\XYZ{7,30}
\XYZ{9,40}
%\Result
\end{document}
This kind of code prevents the document from ever compiling.
- What is wrong with it? How can it be fixed?
- Can it be rewritten using
\newcounter
,\setcounter
,\countainedwithin*
, and other LaTeX methods? I am interested in knowing both the correct TeX and LaTeX methods to achieve the result. - How does one write a macro
\Result
that takes \C and divides by 100 and if the result is three digits EFG, writes \textbf{E},\textbf{FG}, and if the result is four digits EFGH, writes \textbf{EF},\textbf{GH} instead? - In case it has fewer than three digits, to add 0 for G or 00 for FG and use the three digit case.
I am looking for something that does not involve the calc package by the way. A result rounded to the nearest FG or GH in \Result is also fine.
For the \Result
\def\Result{\divide\C by 100\textbf{\the\C}}
is working now - but now sure how to handle rounding up to nearest H in the EF.GH.
If it did work, not sure how to handle the fractional part and cut off to at most two digits on each side of a dividing marker.
\def\XYZ{#1,#2}
is a syntax x error.\C
/ 100 in this example is 21 so neither three nor 4 digits, what output do you want in this case?\newcount
is to give the argument without braces (it's a plain TeX macro). Not that it doesn't work with the braces, but I find it a bit strange (if you were to play this game with primitives such as\let
or\ifx
, you'd get bitten).