How to represent long division using KaTeX? - katex

I checked the official KaTeX docs and there seems to be no support for long division. Is there another way I can represent long division using KaTeX?

In case you are looking for something in the sense of a fraction/ratio, you could use the \dfrac{...}{...} command.
For example:
$\dfrac{This\ is\ a\ very\ looooooooong\ statement}{This\ is\ an\ even\ loooooooooooooooonger\ statement}$
Resulting in:
Note that I am using \ (backslash + space) to create a standard spacing.
For other more complex types of fractions, please refer to the official documentation.

Related

Doubts about the example on page 167 of The TeXbook (Computers & Typesetting A by Donald E. Knuth)

Page 167 of "The TeXBook", line 5
... $F_n=F_{n-1}+F_{n-2}$, \ $n\ge2$.}$$
I tried to write the omitted part completely, as I understand it should be written:
$${\rm The\ Fibonacci\ numbers\ satisfy\ $F_n=F_{n-1}+F_{n-2}$, \ $n\ge2$.}$$
But the above code can't be compiled under plain TeX (error hint: "Missing } inserted.")
Is it not possible to insert $...$ in a $$...$$?
Environment: macOS, TexShop 5.03 (with plain TeX selected), MacTeX 2022
What is the correct way to complete it?
Thanks for your comment.
I found that the following code compiles successfully, but I'm not sure whether this is the author's intention, and I don't quite understand the meaning of using $$...$$ here, is it just for more vertical whitespace?
$$\centerline{The Fibonacci numbers satisfy $F_n=F_{n-1}+F(n-2)$, \ $n\ge2$.}$$
If you look into the source code of the TeXbook, you will find that this line was typset like this:
\begindisplay
The ^{Fibonacci} numbers satisfy $F_n=F_{n-1}+F_{n-2}$, \ $n\ge2$.
\enddisplay
Indeed, the use of $$ is not a good idea in this case, since this will introduce display math mode, which not only adds some whitespace, but also switches to math mode (just like $ does) and additionally typesets the part between $$ and the next $$ centered on a separate line. Since $$ already introduces math mode, TeX will complain if it encounters a single $.
Now, the above example consists only of a short math part while the rest is non-math. Therefore, not the whole sentence should not be typeset in math mode, but only the math part of it. Hence, the use of $$ would not make much sense here.
I don't know why it is stated on page 167 that the sentence was printed using $$ which is obviously wrong. Maybe it is just a mistake.
As for your last example: If you use \centerline, you essentially step out of math mode. Since the stuff inside the argument of \centerline is not typeset in math mode, another single $ is not a problem here. This is why your example compiles just fine. But it is probably not the best idea to place \centerline inside $$...$$.

how to add subscript(or superscript) in notion block?

i am new in using notion as a notebook.Before this,i use oneNote instead,because i found that notion is more convinient in same ways.But one thing making me annoyed is that i can't add subscript(or superscript) in notion text block。Are there any fellows can handle this?
as shown:
text with subscript i need
when i edit in notion block i get like this
For subscript:
/math
Then C_1 renders C1
For superscript:
/math
Then C^2 renders C2
In the latest version as of writing, you could use:
$$c^2$$ - for superscript
$$c_2$$ - for subscript
If you write any mathematical equation between $$ $$, it will render beautifully on notion.
For more than 1 character superscript
/math
P^{xyz}
Result: Pxyz
For more than 1 character subscript
/math
P_{xyz}
Result: Pxyz
In fact, this works for 1 or many characters as subscript or superscript.
Even I just started using notion and faced the same problem. The solution I found was to keep a tab of laTex containing the syntax for all the required math formulae open. It is only temporary as you will get used to them pretty quickly.
You can use tex to write things is superscript or subscript or basically any type of formulae , but its still in tex.
I did and worked on my Notion
Step 1: Choose what to add subscript(or superscript) in notion block (Example a^n)
Step 2: Choose symbol sqrt(x)
Step 3: Press "Done"
In Notion, there are two ways to add math formulas: inline equations and block equations. Both use KaTeX formatting to show the formulas. KaTeX is a TeX display formulas method based on JavaScrpt language. When you place a block or inline equation, for your example, you have to do something like that in the code:
w_{1}=0 ~,~ w_{2}=1
Note that spaces are not rendered, you gotta use ~ separate things, and the { } on these subscripts are optional because when not placed, the "" will take just the first next character. To do superscript, change the "" to "^". You can combine both in the same main variable, like w_2^2=1.
In the following links, you can see a Notion's guide about how to use it, the supported features KaTeX allows you to do, and a link to easy creating formulas.
Notion:
https://www.notion.so/help/math-equations
KaTeX Supported Functions:
https://katex.org/docs/supported.html or
https://katex.org/docs/support_table.html
Easy web TeX editor:
https://atomurl.net/math/
Take time to try and explore writing by typping. Then, when you get used to it, it flows easily like writing regular text.
For anyone stumbling upon this question who does not want to write math equations but simply wants to add a couple of superscript or exponent elements to a Notion page, for instance to write footnotes: there seems to be no way to add "simple" superscript (inline and with the same font), but you can use superscript unicode characters, for instance with a tool such as this one.
It is not perfect as many characters are not available, but will cover many¹ common² uses³ of superscriptᶜᶦᵗᵃᵗᶦᵒⁿ ⁿᵉᵉᵈᵉᵈ.

#-names in plain TeX

Texinfo adds macros starting with '#'. I'm curious how to do that in plain TeX because I'm trying to create a simple TeX framework for my friends' needs and it would be more readable for them.
texinfo essentially replaces plain TeX's backslash with the at sign. This is done by setting the so-called \catcode of the at sign to 0.
Note that with this setting, #command means exactly the same as \command, you don't get a second family of command names.
Note also that designing and implementing a new TeX format is a lot of work; it is much easier to resort to one of the existing TeX formats.

How to manually equalize columns in an IEEE paper if using BibTex?

IEEE conference publications in two-column format require authors to manually equalize the lengths of the columns on the last page of the final submission. I have typically done this by inserting a \newpage where necessary -- which usually ends up being somewhere amidst my (manually entered) references.
However, I have recently begun using BibTeX to manage references, and have now run into a problem: my last page contains only a few (generated) references, and I can't figure out how to manually equalize the columns.
The last page is the tail end of what is generated by:
\bibliographystyle{IEEEtran}
\bibliography{IEEEabrv,library}
Any ideas on how I can equalize the columns while continuing to use BibTeX?
I have submitted to both ACM and IEEE conferences and the easiest thing for me has been using:
\usepackage{flushend}
I've heard it doesn't always work well, but it's been great for me
http://www.ctan.org/pkg/flushend
I went back to RTFM again, and it turns out this is addressed right in "How to Use the IEEEtran LaTeX Class" by Michael Shell (maintainer). Section XIV notes that IEEEtran helpfully provides the \IEEEtriggeratref{} command for just this purpose. By default, it fires a \newline at the given BibTeX reference number. You can even change the command to fire with \IEEEtriggercmd{}.
It can also be done by using the balance package. You simply include the balance package in the preamble (\usepackage{balance}) and insert \balance some place on the last page of your document (for instance right in front of the references). However, I'm not sure if it's working if the last page (both columns) is completely full of references...
IEEE requires authors to equalize the lengths of the columns on the last page.
ACM makes us do this too. I just wind up inserting \vfill\break by hand either in the main text or somewhere in the .bbl file, wherever it makes the columns balance. By the time camera-ready copy goes to ACM, they want the .bbl file inlined by hand anyway, so tinkering by hand does not present an additional hardship.
The reference-number trick might be nice except I never use numbered references :-)
The multicols environment works only if you're luck and your last page comes out exactly as bibliography.
It would be extremely good (and not so difficult) if some enterprising hacker would build the "balance the two columns in the last page" functionality straight into LateX's \output routine. The flexibility is there in the underlying engine, and it would make a lot of people happy.
Not sure if multicol conflicts with bibtex at all, and I don't have time to check, sorry. But try this:
use the multicol package:
\usepackage{multicol} in your preamble, then:
\begin{multicols}{2}
\bibliographystyle{IEEEtran}
\bibliography{IEEEabrv,library}
\end{multicols}
Multicol automatically balances columns. I would recomend using it through out your document, instead of using the .cls or .sty's twocolumn option.

Is there a calculator with LaTeX-syntax?

When I write math in LaTeX I often need to perform simple arithmetic on numbers in my LaTeX source, like 515.1544 + 454 = ???.
I usually copy-paste the LaTeX code into Google to get the result, but I still have to manually change the syntax, e.g.
\frac{154,7}{25} - (289 - \frac{1337}{42})
must be changed to
154,7/25 - (289 - 1337/42)
It seems trivial to write a program to do this for the most commonly used operations.
Is there a calculator which understand this syntax?
EDIT:
I know that doing this perfectly is impossible (because of the halting problem). Doing it for the simple cases I need is trivial. \frac, \cdot, \sqrt and a few other tags would do the trick. The program could just return an error for cases it does not understand.
WolframAlpha can take input in TeX form.
http://blog.wolframalpha.com/2010/09/30/talk-to-wolframalpha-in-tex/
The LaTeXCalc project is designed to do just that. It will read a TeX file and do the computations. For more information check out the home page at http://latexcalc.sourceforge.net/
The calc package allows you to do some calculations in source, but only within commands like \setcounter and \addtolength. As far as I can tell, this is not what you want.
If you already use sage, then the sagetex package is pretty awesome (if not, it's overkill). It allows you get nicely formatted output from input like this:
The square of
$\begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}$
is \sage{matrix([[1, 2], [3,4]])^2}.
The prime factorization of the current page number is \sage{factor(\thepage)}
As Andy says, the answer is yes there is a calculator that can understand most latex formulas: Emacs.
Try the following steps (assuming vanilla emacs):
Open emacs
Open your .tex file (or activate latex-mode)
position the point somewhere between the two $$ or e.g. inside the begin/end environment of the formula (or even matrix).
use calc embedded mode for maximum awesomeness
So with point in the formula you gave above:
$\frac{154,7}{25} - (289 - \frac{1337}{42})$
press C-x * d to duplicate the formula in the line below and enter calc-embedded mode which should already have activated a latex variant of calc for you. Your buffer now looks like this:
$\frac{154,7}{25} - (289 - \frac{1337}{42})$
$\frac{-37651}{150}$`
Note that the fraction as already been transformed as far as possible. Doing the same again (C-x * d) and pressing c f to convert the fractional into a floating point number yields the following buffer:
$\frac{154,7}{25} - (289 - \frac{1337}{42})$
$\frac{-37651}{150}$
$-251.006666667$
I used C-x * d to duplicate the formula and then enter embedded mode in order to have the intermediate values, however there is also C-x * e which avoids the duplication and simply enters embedded mode for the current formula.
If you are interested you should really have a look at the info page for Emacs Calc - Embedded Mode. And in general the help for the Gnu Emaca Calculator together with the awesome interactive tutorial.
You can run an R function called Sweave on a (mostly TeX with some R) file that can replace R expressions with their results in Tex.
A tutorial can be found here: http://www.scribd.com/doc/6451985/Learning-to-Sweave-in-APA-Style
My calculator can do that. To get the formatted output, double-click the result formula and press ctrl+c to copy it.
It can do fairly advanced stuff too (differentiation, easy integrals (and not that easy ones)...).
https://calculator-algebra.org/
A sample computation:
https://calculator-algebra.org:8166/#%7B%22currentPage%22%3A%22calculator%22%2C%22calculatorInput%22%3A%22%5C%5Cfrac%7B1%2B2%7D%7B3%7D%3B%20d%2Fdx(arctan%20(2x%2B3))%22%2C%22monitoring%22%3A%22true%22%7D
There is a way to do what you want just not quite how you describe.
You can use the fp package (\usepackage[options]{fp}) the floating point package will do anything you want; solving equations, adding dividing and many more. Unfortunately it will not read the LaTeX math you instead have to do something a little different, the documentation is very poor so I'll give an example here.
for instance if you want to do (2x3)/5 you would type:
\FPmul\p{2}{3} % \p is the assignment of the operation 2x3
\FPupn\p{\p{} 7 round} % upn evaluates the assignment \p and rounds to 7dp
\FPdiv\q{\p}{5} % divides the assigned value p by 5 names result q
\FPupn\q{\q{} 4 round} % rounds the result to 4 decimal places and evaluates
$\frac{2\times3}{5}=\FPprint\q$ % This will print the result of the calculations in the math.
the FP commands are always ibvisible, only FPprint prints the result associated with it so your documents will not be messy, FP commands can be placed wherever you wish (not verb) as long as they are before the associated FPprint.
You could just paste it into symbolab which as a bonus has free step by step solutions. Also since symbolab uses mathquill it instantly formats your latex.
Considering that LaTeX itself is a Turing-complete markup language I strongly doubt you can build something like this that isn't built directly into LaTeX. Furthermore, LaTeX math matkup itself has next to no semantic meaning, it merely describes the visual appearance.
That being said, you can probably hack together something which recognizes a non-programmable subset of LaTeX math markup and spits out the result in the same way. If all you're interested in is simple arithmetics with fractions and integers (careful with decimal fractions, though, as they may appear as 3{,}141... in German texts :)) this shouldn't be too hard. But once you start with integrals, matrices, etc. I fear that LaTeX lacks expressiveness to accurately describe your intentions. It is a document preparation system, after all and thus not very suitable as input for computer algebra systems.
Side note: You can switch to Word which has—in its current version—a math markup language which is sufficiently LaTeX-like (by now it even supports LaTeX markup) and yet still Google-friendly for simpler terms:
With the free Microsoft Math add-in you can even let Word calculate expressions in-place:
There is none, because it is generally not possible.
LaTeX math mode markup is presentational markup and there are cases in which it does not provide enough information to calculate the expression.
That was one of the reasons MathML content markup was created and also why MathML is used in Mathematica. MathML actually is sort of two languages in one:
presentation markup
content markup
To accomplish what you are after you'll have to have MathML with comibned presentation and content markup (see MathML spec).
In my opinion your best bet is to use MathML (even if it is verbose) and convert to LaTeX when necessary. That said, I also like LaTeX syntax best and maybe what we need is a compact syntax for MathML (something similar in spirit to RelaxNG compact syntax).
For calculations with LaTeX you can use a CalcTeX package.
This package understand elements of LaTeX language and makes an calculations, for example your problem is avialble on
http://sg.bzip.pl/CalcTeX/examples/frac.tgz
or just please write
\noindent
For calculation please use following enviromentals
$515.1544 + 454$
or
\[ \frac{154.7}{25}-(289-\frac{1337}{42.})
\]
or
\begin{equation}
154.7/25-(289-1337/42.)
\end{equation}
For more info please visite project web site or contact author of this project.
For performing the math within your LaTeX itself, you might also look into the pgfmath package, which is more powerful and convenient than the calc package. You can find out how to use it from Part VI of The TikZ and PGF Packages Manual, which you can find here (version 2.10 currently): http://mirror.unl.edu/ctan/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf
Emacs calc-mode accepts latex-input. I use it daily. Press "d", followed by "L" to enter latex input mode. Press "'" to open a prompt where you can paste your tex.
Anyone saing it is not possible is wrong.
IIRC Mathematica can do it.
There is none, because it is generally not possible. LaTeX math mode
markup is presentational markup and there are cases in which it does
not provide enough information to calculate the expression.
You are right. LaTeX as it is does not provide enough info to make any calculations.Moreover, it does not represent any information to do it. But nobody prevents to wright in LaTeX format a text that contains such an information.
It is a difficult path, because you need to build a system of rules superimposed on what content ofthe text in Latex format needs to contain that it would be recognizable by your interpreter. And then convince the user that it is necessary to learn, etc. etc...
The easiest way to create a logical and intuitive calculator of mathematical expressions. And the expression is already possible to convert latex. It's almost like what you said. This is implemented in the program which I have pointed to. AnEasyCalc allows to type an expression as you type the plane text in any text editor. It checks, calculates and generate LateX string by its own then. Its very easy and rapid work. Just try and you will see that.
This is not exactly what you are asking for but it is a nice package
that you can include in a LaTeX document to do all kind of operations including arithmetic, calculus and even vectors and matrices:
The package name is "calculator"
http://mirror.unl.edu/ctan/macros/latex/contrib/calculator/calculator.pdf
The latex2sympy2 Python library can parse LaTeX math expressions.
from latex2sympy2 import latex2sympy
tex_str = r"""YOUR TEX MATH HERE"""
tex_str = r"\frac{9\pi}{\ln(12)}+22" # example TeX math
sympy_object = latex2sympy(tex_str)
evaluated_tex = float(sympy_object.evalf())
print(evaluated_tex)
This Python 3 code evaluates 9𝜋/ln(12)+22 (in its LaTeX from above) to 33.37842899841745.
The snippet above only handles basic algebraic simplification (math expressions without variables). Since the library converts LaTeX math to SymPy objects, the above code can easily be tweaked and extended to handle much more complicated LaTeX math (including solving derivatives, integrals, etc...).
The latex2sympy2 library can be installed via the pip command: pip install --user latex2sympy2
<>
try the AnEasyCalc program. It allows to get the latex formula very easy:
http://steamandwater.od.ua/AnEasyCalc/
:)

Resources