Recently I discovered some more of the incredibly useful features of my favorite text-editor Neovim:
Entering :read !somefunction
in Neovim causes the editor to execute the command somefunction
and then insert the echoed response into the file you are currently editing at your cursor position.
This got me thinking… Maybe I could use this to make my programming more concise. And after installing figlet
I was proven right:
# Use `:read figlet "Example"`
# and then select the output and comment it out: `:'<,'>norm ^i# `
#
# _____ _
# | ____|_ ____ _ _ __ ___ _ __ | | ___
# | _| \ \/ / _` | '_ ` _ \| '_ \| |/ _ \
# | |___ > < (_| | | | | | | |_) | | __/
# |_____/_/\_\__,_|_| |_| |_| .__/|_|\___|
# |_|
echo "It works!"
And after all this thinking I was stuck with an idea, which I had for quite some time already, but never really knew how to implement in vim:
I can use this, to show complex math formulas in programs, as actual math formulas {: text-align: center}
The problem however was, that no package I searched for seemed to provide the ability to render math formulas as ASCII / ANSI / Unicode. And therefor I just set out to create my own program:
prettymath
The programming was the easy part. Just write a python script that internally parses expressions using SymPy and then pretty prints them. But publishing this program with none more than ~50 lines of code was a real pain.
- Publish to GitHub
- Create an account on https://aur.archlinux.org
- Use my .ssh/config
- Generate an ssh key:
$ ssh-keygen -f ~/.ssh/aur
- Clone your future repository:
git clone ssh://[email protected]/your_package_name.git
- Put your
PKGBUILD
in there - Add, Commit, Push
SSH Configuration
$ cat .ssh/config
Host aur.archlinux.org
User aur
PreferredAuthentications publickey
IdentityFile ~/.ssh/aur
And after all this struggle, which even drove me to reddit because I had no clue anymore on what to do, I was able to install my package using the AUR:
yay -S prettymath-git
What does it do?
After having installed prettymath-git
, you can do stuff like this:
before prettymath
import math
def normalDistribution(x):
return 1/sqrt(math.pi)*math.e**(-x**2)
after prettymath
(:read !prettymath -u "1/sqrt(pi) * e**(-x**2)"; :norm ^i#
)
import math
def normalDistribution(x):
# 2
# -x
# e
# ────
# √π
return 1/sqrt(math.pi)*math.e**(-x**2)