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

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 $$...$$.

Related

Correct way to define macros \etc \ie in latex

In
this article the author discusses the use of \# to put correct spacings after full stops that are not at the end of a sentence e.g. Mr. i.e. etc.
The macro suggested
\newcommand\etc{etc\#ifnextchar.{}{.\#}}
is not quite perfect since in the case (\etc more text) it produces (etc.more text).
I have seen a lot of authors who have made their own versions of the \etc macro, mostly variations on etc.\.
What macros for \etc, \ie, \etal, \eg produce the nicest results in the most situations?
Is this something too personal in taste to be solved in general?
Earlier I used macros for "et al.", etc., but nowadays I would discourage people from defining that kind of macros.
One problem is what you already observed: it's surprisingly tricky to get the definitions right so that they handle all special cases correctly (including the interactions with other packages – e.g., those that re-define the "\cite" command and tweak spacing before references).
But more importantly, even if you have a bunch of macros that suit your needs and you know how to use them, your co-authors are likely to be confused with exactly how to use your macros correctly in various special cases.
Hence I'd recommend that you avoid macros for trivial things such as "et al." and simply spell out everything by using standard Latex markup. After all, most cases don't need any special handling ("e.g." is often followed by a comma; "et al." is often followed by "~\cite", etc.), and whenever special handling is needed, all Latex users should know how to use commands such as "\ " and "\#".
In CVPR's style package, it is defined as:
\usepackage{xspace}
% Add a period to the end of an abbreviation unless there's one
% already, then \xspace.
\makeatletter
\DeclareRobustCommand\onedot{\futurelet\#let#token\#onedot}
\def\#onedot{\ifx\#let#token.\else.\null\fi\xspace}
\def\eg{\emph{e.g}\onedot} \def\Eg{\emph{E.g}\onedot}
\def\ie{\emph{i.e}\onedot} \def\Ie{\emph{I.e}\onedot}
\def\cf{\emph{c.f}\onedot} \def\Cf{\emph{C.f}\onedot}
\def\etc{\emph{etc}\onedot} \def\vs{\emph{vs}\onedot}
\def\wrt{w.r.t\onedot} \def\dof{d.o.f\onedot}
\def\etal{\emph{et al}\onedot}
\makeatother
Have you tried using the xspace package?
Example macro:
\def\etc{etc.\#\xspace}
Some tests:
Cat, dog, \etc. And so on. \\
Cat, dog, \etc! And so on. \\
Cat, dog, \etc, and so on. \\
Cat (dog, \etc). And so on. \\
Produces:
From the documentation:
The xspace package provides a single
command that looks at what comes after
it in the command stream, and decides
whether to insert a space to replace
one "eaten" by the TeX command
decoder.
A technical challenge! We can avoid the problem of letters after spaces by looking at the catcode of the next character and seeing whether or not it is a letter; this can be done with the Latex3's expl3 macro \peek_charcode:NTF (my first expl3 code!):
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\newcommand\latinabbrev[1]{
\peek_meaning:NTF . {% Same as \#ifnextchar
#1\#}%
{ \peek_catcode:NTF a {% Check whether next char has same catcode as \'a, i.e., is a letter
#1.\# }%
{#1.\#}}}
\ExplSyntaxOff
%Omit final dot from each def.
\def\eg{\latinabbrev{e.g}}
\def\etal{\latinabbrev{et al}}
\def\etc{\latinabbrev{etc}}
\def\ie{\latinabbrev{i.e}}
\begin{document}
Maybe a list, \eg, a, b, c, and d. Which is to say (\ie) a, b, \etc. Consider Knuth, \cf The TeXbook.
\end{document}
Jukka's advice I think is sound, though: I'd say the problem Will works around with his \etc macro we should see as a bug in Tex's implementation of double spacing (Will Robertson should ask for his cheque): if you know the bug is there, you can workaround it directly by putting in \# in cases such as ".)", or you can have tricky code that means you don't have to think in this case, but you have added complexity to the way you typeset which is not going to work for you with the next unexpected glitch, one you probably have introduced yourself.
Postscript Previous version fixed, thanks to Joseph Wright noticing a stupid error at tex.stackexchange.com.
All LaTeX commands eliminate space after them. If you want a space, you need to escape it:
\etc\ and more
This is necessary, because you need to be clear where the command name ends. \etcno space cannot be correctly interpreted.

Automatically capitalize first letter of first word in a new sentence in LaTeX

I know one of LaTeX's bragging points is that it doesn't have this Microsoftish behavior. Nevertheless, it's sometimes useful.
LaTeX already adds an extra space after you type a (non-backslashed) period, so it should be possible to make it automatically capitalize the following letter as well.
Is there an obvious way to write a macro that does this, or is there a LaTeX package that does it already?
The following code solves the problem.
\let\period.
\catcode`\.\active
\def\uppercasesingleletter#1{\uppercase{#1}}
\def.{\period\afterassignment\periodx\let\next= }
\def \periodx{\ifcat\space\next \next\expandafter\uppercasesingleletter \else\expandafter\next\fi}
First. second.third. relax.relax. up
\let\period. save period
\catcode\.\active make all periods to be active symbol (like macro).
\def\uppercasesingleletter#1{\uppercase{#1}} defines macro \uppercasesingleletter to make automatically capitalize the following letter.
\def.{\period\afterassignment\periodx\let\next= } writes saved period and checkes the next symbol.
\def \periodx{\ifcat\space\next \next\expandafter\uppercasesingleletter \else\expandafter\next\fi} If the next letter is a space then \uppercasesingleletter is inserted.
ages ago there was discussion of this idea on comp.text.tex, and the general conclusion was you can't do it satisfactorily. satisfactory, in my book, involves not making characters active, but i can't see how that could work at all.
personally, i would want to make space active, and have it then look at \spacefactor and \MakeUppercase the following character if the factor is 3000.
something like
\catcode\ \active % latex already has a saved space character -- \space
\def {\ifhmode% \spacefactor is invalid
% (or something) in vertical mode
\ifnum\spacefactor<3000\else% note: with space active,
% even cs-ended lines need %-termination
\expandafter\gobbleandupper\fi}%
\def\gobbleandupper#1{\def\tempa{#1}\def\tempb{ }%
\ifx\tempa\tempb% can''t indent the code, either :-(
% here, we have another space
\expandafter\gobbleandupper% try again
\else\space% insert a "real" space to soak up the
% space factor
\expandafter\MakeUppercase\fi}%
this doesn't really do the job -- there are enough loose ends to knit a fairisle jumper. for example, given that we can't rely on \everypar in latex, how do you uppercase the first letter of a paragraph?
no ... however much it hurts (which is why i avoid unnecessary key operations) we need to type latex "properly" :-(
I decided to solve it in the following way:
Since I always compile the LaTeX code three times before i okular the result (to get pagination and references right), I decided to build the capitalization of sentences into that process.
Thus, I now have a shell script that calls my capitalization script (written in CRM114) first, then pdflatex three times, and then okular. This way, all the stuff happens as the result of a single command.

Latex - Apply an operation to every character in a string

I am using LaTeX and I have a problem concerning string manipulation.
I want to have an operation applied to every character of a string, specifically
I want to replace every character "x" with "\discretionary{}{}{}x". I want to do
this because I have a long string (DNA) which I want to be able to separate at
any point without hyphenation.
Thus I would like to have a command called "myDNA" that will do this for me instead of
inserting manually \discretionary{}{}{} after every character.
Is this possible? I have looked around the web and there wasnt much helpful
information on this topic (at least not any I could understand) and I hoped
that you could help.
--edit
To clarify:
What I want to see in the finished document is something like this:
the dna sequence is CTAAAGAAAACAGGACGATTAGATGAGCTTGAGAAAGCCATCACCACTCA
AATACTAAATGTGTTACCATACCAAGCACTTGCTCTGAAATTTGGGGACTGAGTACACCAAATACGATAG
ATCAGTGGGATACAACAGGCCTTTACAGCTTCTCTGAACAAACCAGGTCTCTTGATGGTCGTCTCCAGGT
ATCCCATCGAAAAGGATTGCCACATGTTATATATTGCCGATTATGGCGCTGGCCTGATCTTCACAGTCAT
CATGAACTCAAGGCAATTGAAAACTGCGAATATGCTTTTAATCTTAAAAAGGATGAAGTATGTGTAAACC
CTTACCACTATCAGAGAGTTGAGACACCAGTTTTGCCTCCAGTATTAGTGCCCCGACACACCGAGATCCT
AACAGAACTTCCGCCTCTGGATGACTATACTCACTCCATTCCAGAAAACACTAACTTCCCAGCAGGAATT
just plain linebreaks, without any hyphens. The DNA sequence will be one
long string without any spaces or anything but it can break at any point.
This is why my idea was to inesert a "\discretionary{}{}{}" after every
character, so that it can break at any point without inserting any hyphens.
This takes a string as an argument and calls \discretionary{}{}{} after each character. The input string stops at the first dollar sign, so you should not use that.
\def\hyphenateWholeString #1{\xHyphenate#1$\wholeString}
\def\xHyphenate#1#2\wholeString {\if#1$%
\else\say{#1}\discretionary{}{}{}%
\takeTheRest#2\ofTheString
\fi}
\def\takeTheRest#1\ofTheString\fi
{\fi \xHyphenate#1\wholeString}
\def\say#1{#1}
You’d call it like \hyphenateWholeString{CTAAAGAAAACAGGACG}.
Instead of \discretionary{}{}{} you can also try \hspace{0pt}, if you like that more (and are in a latex environment). In order to align the right margin, I think you’d need to do some more fine tuning (but see below). The effect is of course minimised by using a font of fixed width.
Revision:
\def\hyphenateWholeString #1{\xHyphenate#1$\wholeString\unskip}
\def\xHyphenate#1#2\wholeString {\if#1$%
\else\transform{#1}%
\takeTheRest#2\ofTheString\fi}
\def\takeTheRest#1\ofTheString\fi
{\fi \xHyphenate#1\wholeString}
\def\transform#1{#1\hskip 0pt plus 1pt}
Steve’s suggestion of using \hskip sounds like a very good idea to me, so I made a few corrections. Note that I’ve renamed the \say macro and made it more useful in that it now actually does the transformation. (However, if you remove the \hskip from \transform, you’ll also need to remove the \unskip in the main macro definition.
Edit:
There is also the seqsplit package which seems to be made for printing DNA data or long numbers. They also bring a few options for nicer output, so maybe that is what you’re looking for…
Debilski's post is definitely a solid way to do it, although the \say is not necessary. Here's a shorter way that makes use of some LaTeX internal shortcuts (\#gobble and \#ifnextchar):
\makeatletter
\def\hyphenatestring#1{\xHyphen#te#1$\unskip}
\def\xHyphen#te{\#ifnextchar${\#gobble}{\sw#p{\hskip 0pt plus 1pt\xHyphen#te}}}
\def\sw#p#1#2{#2#1}
\makeatother
Note the use of \hskip 0pt plus 1pt instead of \discretionary - when I tried your example I ended up with a ragged margin because there's no stretchability. The \hskip adds some stretchable glue in between each character (and the \unskip afterwards cancels the extra one we added). Also note the LaTeX style convention that "end user" macros are all lowercase, while internal macros have an # in them somewhere so that users don't accidentally call them.
If you want to figure out how this works, \#gobble just eats whatever's in front of it (in this case the $, since that branch is only run when a $ is the next char). The main point is that \sw#p is only given one argument in the "else" branch, so it swaps that argument with the next char (that isn't a $). We could just as well have written \def\hyphenate#next#1{#1\hskip...\xHyphen#te} and put that with no args in the "else" branch, but (in my opinion) \sw#p is more general (and I'm surprised it's not in standard LaTeX already).
There is a contrib package on CTAN that deals with typesetting DNA sequences. It does a little more than just line-breaking, for example, it also supports colouring. I'm not sure if it is possible to get the output you are after though, and I have no experience in the DNA-sequence-typesetting area, but is one long string the most readable representation?
Assuming your string is the same, in your preamble, use the \newcommand{}{}. Like this:
\newcommand{\myDNA}{blah blah blah}
if that doesn't satisfy your requirements, I suggest:
2. Break the strings down to the smallest portion, then use the \newcommand and then call the new commands in sequence: \myDNA1 \myDNA2.
If that still doesn't work, you might want to look at writing a perl script to satisfy your string replacement needs.

Special characters in LaTeX table caption

When I include \overline{x} or other special characters in the caption text of a table, the whole caption text won't appear at all. When I put simple text without special characters, the caption works fine. How can I include special characters in the caption?
Are you putting $ around the maths? I.e.:
\caption{This is a caption with maths $\overline{x}$ in it.}
Apparently your real problem was that TeX's fancy error correction mechanism prevented you from knowing that there was a syntax error in the document. Back in 1982 or so, running TeX on a long document would take so much time that Knuth didn't want TeX to just quit when it ran into an error. Instead, TeX tries to guess what you meant and go on typesetting the document, so that you can fix a bunch of errors before you run it again; for example, when it spots a math-mode command outside math mode, it assumes that you forgot a dollar sign and inserts it. No automatic error-correction mechanism is perfect, so syntax errors often cause some part of text to be lost, or typeset in a wrong way.
TeX does try to tell you that it has found errors, but I suppose current IDEs make it easy to ignore the output. Try running latex on the document from the command line and pay attention to what it says. For example, the short document
\documentclass{article}
\begin{document}
It seems \sqrt{2} I forgot some dollar signs.
\end{document}
causes TeX to prompt you with
! Missing $ inserted.
<inserted text>
$
l.3 It seems \sqrt{
2} I forgot some dollar signs.
?
The 2009 way of dealing with this is to type X to quit, fix the source document, and run latex again - but you can actually enter other commands at the prompt to edit the input that TeX sees. If you just type Q (to run quietly - same as specifying \batchmode, which Emacs or whatever IDE you are using probably does for you) you get a typeset document as a result, and it might not be obvious that there are in fact syntax errors in it.
If you looking for how to insert any special character in Latex in a table then this may help you. Check this out...
\documentclass{article}
\begin{document}
\begin{tabular}{|l|r|r|}
Item & Quality & Price(\$)\\
Nails & 500 & 34\\
Wooden boards & 100 & 4\\
Bricks & 240 & 11\\
\end{tabular}
\end{document}

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