1 line of code to write Latex formulas, this 4.6M Python plug-in is a must-have for papers
Xiaoxiao sent from Aofei Temple
Quantum Bit Report | Public Account QbitAI
When writing a paper, are you exhausted from typing out piles of calculation formulas?
When making a PPT for a lecture, do you have dozens of pages of calculation and reasoning formulas? Do you want to just write them out by hand and take a photo of them?
Now, it's time to free your hands. You only need to master some Python syntax . The above formula can be generated in just 4 lines, 3 of which are Python calculation formulas.
△ Yes, these are the lines
This toolkit, called handcalcs , generates LaTeX formulas without having to learn the complex syntax of LaTeX.
The key is that the size is only 4.6MB , which is equivalent to a small plug-in in Jupyter.
Squares, square roots, fractions, trigonometric functions, footnotes... This plug-in has all the functions needed. It can not only generate formulas, but also calculate results.
In addition, there are also functions such as unit conversion and format adjustment.
Let’s see how it is used.
Basic version: formula + calculation
After installing the handcalcs plug-in, Python is upgraded from a ruthless calculator to a gorgeous formula generator.
Based on Python syntax, you only need to add one line of code to present the calculation formula in LaTeX format .
That’s right, this line of code is %%render.
That is to say, if you want to generate a LaTeX formula, just add %%render before the calculation formula.
Not only that, Python will automatically calculate the results for you.
As shown in the figure below, first set the values of the three parameters a, b, and c, then use Python to list the expressions and put %%render at the front.
Then, list the expression for x.
Suddenly, the result of x expressed by a, b, and c is displayed, and the result is also calculated.
You no longer need to enter long sections of complex LaTeX syntax to generate complex calculation formulas.
Additionally, if you want to use this tool plugin in a function, add another line @handcalc(), but pay attention to return locals(), like this:
The resulting effect is the same.
In addition, if you need to add judgment conditions to the formula, the system can also generate them.
As for points and such, there is no pressure to generate them.
Do you think this is the end?
It's still early, and generating LaTeX formulas is just the basic usage of this tool.
Advanced version: format + unit conversion
In addition, handcalcs also has functions such as format adjustment, special characters, and unit conversion .
Format Adjustment
First, the parameter format is adjusted.
If you have a formula that uses several parameters, but having them on a separate line would waste paper and make it difficult to read, try adding a line with ##Parameters.
In this way, three parameters can be placed in one line without taking up much space (reducing line spacing) .
Of course, if a row of formulas looks too crowded, you can adjust its length.
Just add #long or #short in front of the formula, and the formula can be expanded into several lines according to your needs, making the derivation process look clearer.
In addition, if you do not want to give the calculation results in the conclusion and only want to keep the parameter formula, that is also possible. Just add #symbolic in front of it.
As shown in the figure below, the original calculation result will be hidden and replaced by an expression with only parameters.
△ When your math teacher wants you to calculate a formula
And if you want to add some comments after the formula (or something like "Formula 3.1") , you can generate it here directly.
In addition, there are also methods for generating special characters.
Special characters
If you need to put some footnotes in the lower right corner of the letter, some footnotes may be "nested".
It doesn’t matter, one underscore will do the trick. If one is not enough, just add a few more.
In addition, Greek letters with various strange pronunciations and special characters can also be generated here based on their pronunciation.
Unit conversion
The most important thing is that handcalcs is not just a mathematical calculation generator, it also has the function of unit conversion.
If it is a physical calculation formula, after entering the expression and unit, handcalcs can automatically generate the unit conversion result.
In this way, there is no need to go through the trouble of listing the dimensions to see what the result of multiplying or dividing these two units is.
Convert to LaTeX syntax
Of course, if you want to restore the generated LaTeX formula to LaTeX syntax and paste it back into LaTeX for use, a very convenient operation is also provided here.
Just use %%tex and handcalc will automatically generate Latex syntax for you.
Minor restrictions
However, this toolkit has some minor limitations.
For example, not all data types are applicable, such as Python's "container data" (collections) .
In addition, not all formulas in Python are applicable, for example, for does not support rendering by this tool.
But apart from these minor limitations, this toolkit is still a powerful formula generator, and it is sufficient to generate most of the formulas needed in the paper.
There are some other detailed functions, you can click the portal below to view them.
about the author
The creator of this tool, Connor Ferster, is not a computer major, but he is very interested in Python.
According to Conner's self-introduction on social media, he is currently a student of civil engineering.
So, civil engineering papers might require a lot of computation?
Portal
Toolkit link:
https://github.com/connorferster/handcalcs
-over-
This article is the original content of [Quantum位], a signed account of NetEase News•NetEase's special content incentive plan. Any unauthorized reproduction is prohibited without the account's authorization.
5 minutes a day to seize industry development opportunities
How to pay attention to, learn and make good use of artificial intelligence?
Every weekday, Quantum位 AI Insider selects the latest global technology and research developments, summarizes new technologies, new products and new applications, sorts out the hottest industry trends and policies of the day, and searches for valuable papers, tutorials, research, etc.
At the same time, the AI Insider Group provides a platform for communication and sharing, which can better meet everyone's needs for obtaining AI information and learning AI technology. Scan the QR code to subscribe:
Join the AI community and communicate with outstanding people
Quantum Bit QbitAI · Toutiao signed author
Tracking new trends in AI technology and products
If you like it, click "Watching"!