2

I am writing a program that generates the steps performed during math operations ( + - * / ) and explain it has well.

I have read this and the best answer here is using the xlop package , which displays, e.g. multiplication as (in plain text):

    3 8 4
x     5 6
---------
  2 3 0 4
1 9 2 0
---------
2 1 5 0 4

And the latex :

\documentclass{article}
\usepackage{xlop}
\begin{document}
\opmul{384}{56}\qquad
\end{document}

But is there a way to create the latex like

    3 8 4
x     5 6
---------
  2 3 0 4

Here is one way using Plain-commands:


\vbox{
  \openup2pt
  \def\trule{\noalign{\smallskip\hrule\smallskip}}
  \halign{&\tabskip1em$\mathstrut#$\cr
          &   & 3 & 8 & 4 \cr
    \times&   &   & 5 & 6 \cr
    \trule
          & 2 & 3 & 0 & 4 \cr
    \trule
  }
}
\bye

Where it is not completely finished but shows a 'step' in the process. So what I mean is that , is it possible using the xlop package to specify to which degree and what it completed or what I want to omit from the output ? Or do I need to use a totally different technique

Bibi
  • 1,532
  • Welcome to TeX.se! The xlop package can't do this out of the box. You might want to contact the author to see if they would be interested in adding this as an option though. In case anyone here wants to mess with the code, you might want to add a sample document to your question. – Alan Munn Sep 06 '23 at 13:53
  • Ok , I will do it , the thing is I have absolutely zero clue about anything to do with latex and that was the best solution , I found – Aarav Shah Sep 06 '23 at 14:14
  • Strictly speaking, since LaTeX is just a format based on TeX, your solution isn't not-LaTeX. I of course know what you mean, but is there some particular reason you want a LaTeX solution? I'm wondering what it is about an xlop solution you want/need, in case somebody wonders about using a different approach. (I know nothing about xlop so I don't know what might be special about it.) – cfr Sep 07 '23 at 00:43
  • Well the reason I am using latex is as its a popular maths render supporting equations and advanced stuff and it has clients for mobile , web to render it. About xlop package is as it renders the school-grade operations accurately and with little 'code' , however if theres a better way I am all ears – Aarav Shah Sep 07 '23 at 15:34

1 Answers1

1

There are some options for this in xlop, some more easy than others. Some times is good idea take a look to the manual of the packages.


mwe

\documentclass[a5paper]{article}
\usepackage{xlop,geometry}

\newcommand\hole[1]{_}

\begin{document} \sffamily \noindent \begin{minipage}[c][3cm][t]{.16\linewidth} \opmul{384}{56} \vfill full result
\end{minipage} \hfil \begin{minipage}[c][3cm][t]{.16\linewidth} \opmul[displayintermediary=None]{384}{56} \vfill shortened \end{minipage} \hfil \begin{minipage}[c][3cm][t]{.16\linewidth} \oplput(2,-0.7){3}\oplput(3,-0.7){8}\oplput(4,-0.7){4} \oplput(1,-1.2){$\times$} \oplput(3,-1.7){5}\oplput(4,-1.7){6} \ophline(0,-1.95){5} \oplput(1,-2.7){2}\oplput(2,-2.7){3}\oplput(3,-2.7){0}\oplput(4,-2.7){4} \vfill\small\raggedright hard way, wrong or incomplete? \end{minipage} \hfil \begin{minipage}[c][3cm][t]{.16\linewidth} \oplput(2,-0.7){3}\oplput(3,-0.7){8}\oplput(4,-0.7){4} \oplput(1,-1.2){$\times$} \oplput(3,-1.7){5}\oplput(4,-1.7){6} \ophline(1,-1.95){4} \oplput(1,-2.7){2}\oplput(2,-2.7){3}\oplput(3,-2.7){0}\oplput(4,-2.7){4} \oplput(0,-3.7){.}\oplput(1,-3.7){.}\oplput(2,-3.7){.}\oplput(3,-3.7){.}\oplput(4,-3.7){←} \ophline(0,-3.95){5} \vfill\raggedright hard way,\ but clear \end{minipage} \hfil \begin{minipage}[c][3cm][t]{.16\linewidth} \opmul[intermediarystyle.2=\hole,resultstyle=\hole]{384}{56}
\vfill\raggedright easier and better? \end{minipage} \end{document}

Fran
  • 80,769
  • Could you explain to be why , what seems like totally random numbers are used in oplmut , for example \oplput(2,-0.7){3}\oplput(3,-0.7){8}\oplput(4,-0.7){4} – Aarav Shah Sep 13 '23 at 10:32
  • @AaravShah In \oplput(2,-0.7){3} you put "3" in horizontal position "2" and vertical position "-0.7". Period. This command has nothing to do with any calculus. You can use this command to insert comments to a real operation, or make impossible operations as 2+2=22 or A×3=6 with \oplput(0,0){A} \oplput(1,0){$\times$} and so on. With \opmul{2}{3} you can change "2" by "A" via operandstyle.1 option, but it does not work with style=text, unfortunately. – Fran Sep 13 '23 at 12:45
  • So these are just the 'index' in the thing not anything do to with the calculatino – Aarav Shah Sep 14 '23 at 10:44