# Hands-On Tutorial On HandCalcs Python Library For Converting Calculations In Latex

Through this article, we will discuss a new python library Hand Calcs that is used to render different calculation code in Latex that is dependent on the writing of calculations.

We have seen several python libraries and packages that support various multiple tasks in the field of Data Science. Different libraries are used from Data preprocessing to data visualisation, etc. Through this article, we will discuss a new python library HandCalcs that is used to render different calculation code in Latex that is dependent on the writing of calculations. This library is helpful in terms of verifying the calculations. As there are no prerequisites of using this library which becomes easy for a person who does not know python as well. The library renders the symbolic formula, the numerical substitution, and then the result for any calculation. In this article, we will also see different usages of this library.

• What is the HandCalcs library? How to install it?
• What are different uses of Hand Calcs library?

We need to first install this library. We can install this using the pip command. Use the below code for the same.

`pip install handcalcs`

Now we will see how it is used. For this, we need to first import the required libraries. Use the below code for the same. This library is responsible for using latex as well as rendering the code.

`import handcalcs.render`

Now suppose we want to render any calculations. For this, we just need to use %%render at the starting of the code. Refer to the below example for the same.

`%%render`

`a = 2`

`b = 3`

`c= a*8 + 3/b`

Output:

We can also convert the python code into latex. For this, we need to import a library and math function. Use the below code for the same. Similar to render we need to write %%tex before the code. Refer to the below example.

`import handcalcs.render`

`from math import sqrt, pi`

`%%tex`

`a = 4 / 8 * cube(pi)`

Output:

Three different comment tags are supported by the library for formatting your code. Let’s see these customisation tags.

1. Parameters: This code is rendered vertically which is one after the other by the library. However, when we are printing the result we need to avoid the wastage of vertical space so we make use of this tag. This tag will render the result in the form of columns. Refer to the below example.

`%%render`

`# Parameters`

`a=1`

`b=2`

`c=3`

Output:

1. Long and Short: For saving the vertical space if the code is small enough then this tag renders it in a single line whereas if the calculations are big enough then it renders it into multiple lines. We can do this using short and long tags. Refer to the below example for short and long respectively.

`%%render`

`# short`

`f = d / a+b # Comment`

`g = d*f / a # Comment`

Output:

`%%render`

`# long`

`f = d / a+b # Comment`

`g = d*f / a # Comment`

Output:

1. Symbolic: This library makes it easy for the user to verify all the calculations by rendering it but there can be the cases where we want to just display these calculations. We can make use of symbolic tags for the same. Refer to the below example for the same.

`%%render`

`# Symbolic`

`r = sqrt(a**2 + b**2)`

`x = b**2 + 4*a*c`

Output:

If we want to put all the symbolic code in one cell and all other numerical results in another cell we can do that using this. In the above example, we have just used the symbolic code in one line now we will print the numerical result. Refer to the below example.

`%%render`

`# Parameters`

`r `

`x`

Output:

This library was designed in a manner that it can be used with the forallpeople package. Let us see some examples of it. Refer to the below example. For this, we need to first import the library and use the below code for the same.

`import handcalcs.render`

`import forallpeople`

`%env 'structural'`

`%%render`

`# Parameters`

`phi = 0.9`

`f_X = 67`

Output:

We can also display the variable values in a separate cell. Refer to the below example.

`a = 2`

`b = 4`

Output:

We can also get just the latex code without using render by just writing %%tex before the calculations. Use the below code to do so.

`%%tex`

`# Symbolic`

`r = sqrt(a**2 + b**2)`

`x = b**2 + 4*a*c`

Output:

We can also write in subscripts using _ after the variable name. Refer to the below example for the same.

`%%render`

`a_x = 4`

`b_x_y = 2`

Output:

We can also use greek symbols using this library. Refer to the below example for converting into greek symbols.

`%%render`

`alpha = 28`

`beta = 2`

`gamma = 5 `

Output:

This library also supports rendered-in line comments that can be helpful to write comments after each line of code or as notes. Refer to the below example for the same.

%%render

`lamb = 2.0303 # This comment will be displayed `

`a = 45`

`b = 34`

`c = lamb *a*b `

Anything that is written within the parentheses will be totally rendered. Refer to the example below for the same.

`%%render`

`a = 2.8`

`b = (2*a+10)`

Output:

Conclusion

In this article, we discussed the HandCalcs python library. How it can be used to convert calculations into latex and what are different usages of the library for representing different calculations. We can also export this jupyter notebook in HTML format and PDF format via latex. You can also check the GitHub repo for more information about the library whereas all the instructions are given.

References

1. HandCalcs, “Connorferster”

I am currently enrolled in a Post Graduate Program In Artificial Intelligence and Machine learning. Data Science Enthusiast who likes to draw insights from the data. Always amazed with the intelligence of AI. It's really fascinating teaching a machine to see and understand images. Also, the interest gets doubled when the machine can tell you what it just saw. This is where I say I am highly interested in Computer Vision and Natural Language Processing. I love exploring different use cases that can be build with the power of AI. I am the person who first develops something and then explains it to the whole community with my writings.

## Oct 11-13, 2023 | Bangalore

### Telegram group

Discover special offers, top stories, upcoming events, and more.

### Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

### How Whatfix is Revolutionising SaaS with GenAI Integration

With the help of a 12-member team split into two groups, Whatfix is working towards generative AI implementation across its products and functions with a focus on responsible AI.

### Council Post: AI’s Evolutionary Journey – Model-Centric to Data-Centric to Decision-Centric

The emerging trend of decision-centric AI holds great promise in transforming the way we make decisions by integrating data analysis, machine learning, and optimization techniques.

### Beware of the AI Bubble Burst

AI is this year’s investment craze but experts pinpoint the warning signs of an AI bubble forming

### Try Out These 5 New Crazy Features on Adobe Firefly

Currently, in beta testing, Adobe Firefly allows users to access its generative AI-based editing models through a waitlist.

### AWS Fires Up Indian Govt’s Digital Ambitions

AWS has helped the Telangana government migrate their mission-critical core application for e-governance across 93 districts

### 5 Things That Killed The Metaverse

In less than two years since genesis, the metaverse has already met its demise. Here are five reasons why we’ll never see the metaverse again.

### ChatGPT Craves Human Expertise

Looks like RLHF was not enough human interaction for OpenAI’s ChatGPT, which now craves more

### India’s Semiconductor Dreams Plunge into Chaos and Uncertainty

The delays and inefficiencies in communication and processing have resulted in the loss of one-and-a-half years

### Spark vs Presto: Unleashing the Power of Data

Although both Spark and Presto are preferred by companies because of similar similar offerings, they come with their own share of differences.

### Internal Drama Unveiled: A Behind-the-Scenes Look at Rust

Amidst bureaucratic issues at the Rust Foundation, the open-source community has created its own fork of the programming language, endearingly called Crab.