Author Archives: DSB

Vim for Julia

By: DSB

Re-posted from: https://medium.com/coffee-in-a-klein-bottle/vim-for-julia-18eba071c654?source=rss-8bd6ec95ab58------2

An easy setup for Vim as Julia IDE (on Ubuntu)

As someone who has been a Vim user for years, I can confidently say that Vim is highly addictive. Once you get used to it’s shortcuts, editing code without it becomes unbearable. Although many tutorials exist on how to setup a Vim IDE for Python and other languages, no tutorial seems to be available for using Vim with Julia. So this might be a first.

By no means this article is comprehensive, I intend to present a very neat and fast way of using Vim with Julia. Note that there are many alternatives to using “pure Vim”, one can code using Juno and install the vim-mode package in Atom. The method I propose is using “pure Vim”, but with the very cool SpaceVim.

If you are new to Vim, and is trying to learn it, you probably realized that Vim has thousands of plugins available, and setting up your “IDEish” Vim may be quite complicated. One has to learn how to install plugins, choose color highlighting themes, and much more. Here is where SpaceVim comes in.

SpaceVim is a Vim distribution that works pretty much like an IDE, with some of the most popular plugins already installed. It also comes with some preset shortcuts, allowing for a more efficient file navigation. And most importantly, it looks beautiful.

Installing Vim and SpaceVim

The first thing to do is to install Vim… Well, actually, NeoVim. If you are not familiar with NeoVim, it is pretty much an updated Vim. So why use it? The only reason is that in my experience, it just works better with SpaceVim and Julia, and also, I like the cursor better. But feel free to go with Vim if you prefer it. The commands below install NeoVim and then SpaceVim.

sudo apt install neovim
curl -sLf https://spacevim.org/install.sh | bash

To access NeoVim from the terminal, you just need to write

nvim “example.txt”

If like me, you prefer to use the common “vim” command, then you can create an alias.

If you are using bash (the standard shel), open the file ~/.bashrc and write alias vim="nvim $argv".

If you are using fish, then on the terminal write

function vim
nvim $argv
end

This will create a function called “vim” in the fish shell. Then run the command funcsave vim , to save the function so it becomes permanant.

When you run Vim for the first time after installing SpaceVim, you will note that some plugins will be installed. By the end of the installation, you might get an error message about “vimproc”. To fix this, go into the command line of Vim by typing : , then write VimProcInstall .

Example on running VimProcInstall to fix possible error messages.

Setting up Julia

To set up Julia now is incredibly simple. If a plugin is already available in the SpaceVim “ecosystem”, you just need to add that plugin to your init.toml file, which is located in your home directory inside the folder .SpaceVim.d , and SpaceVim will install it for you.

Hence, to install the packages for dealing with Julia, just open ~/.SpaceVim.d/init.toml and write the following in the end of the file

[[layer]]
name= "lang#julia"

You might also want to add

[[layer]]
name= "colorscheme"

The code above will enable different colorschemes, which can be chosen by altering the attribute colorscheme.

This is it. You now have a Vim IDE for Julia!

Example of file ~/.SpaceVim.d/init.toml — Note that the ‘autocomplete’ layer is disabled. This is due to some incompatibility between the Julia packages and the autocomplete package. At the end of this article I present a fix for this problem.

Tips on using SpaceVim

There are tons of tutorials on how to use Vim, so I will not go into that. But there is not as much information on using SpaceVim. So I’ll give you some tips on how to get started.

  • Installing Plugins: I’ve already talked about how to install different plugins. You just have to pretty much add a layer to your init.toml file. Here is a list of the available plugins for SpaceVim;
  • Navigating file: the NerdTree plugin is already shipped with SpaceVim, so one just needs to press F3 to open the navigation menu. You can press l to go inside a folder, or h to go out of the folder;
  • <Leader> and SPC: If you read the documentation of SpaceVim, you will likely encounter shortcuts such as SPC <Tab> . The SPC stands for “space bar”. The <Leader> default key is \ ;
  • Commenting line: To comment a line, just do SPC c l (space bar + c +l), and SPC c l ;
  • Copy to system clipboad: A common difficulty to people starting with Vim is the fact that you cannot easily copy text from Vim to a another file not opened on the same Vim window (e.g your Browser). SpaceVim solves this to you, just use <Leader> y to copy to your system clipboard, and <Leader> p ;
  • Moving from Buffers (tabs): If you are working on a file, then press F3 and open another file, a new buffer will become active. You can then press SPC <Tab> to change buffers, therefore, easily going from one file to another. Amazingly, the buffers will be shown on the top of Vim, and you can actually just click on them if you want (but if you are using Vim, you probably don’t want to be using your mouse).
Image showing the different buffers of files opened.

If you like this article or has suggestions on how it could be improved, consider “Clapping” or leaving a comment, so I can get some feedback.

UPDATE: When using SpaceVim with Julia autocompletion, you might experience some freezing when pressing the Tab . This is due some incompatibility between the julia-vim package and the other autocompletion packages present on SpaceVim. To solve this issue, you may disable the Latex unicode tab command in the julia-vim package. To do this, open the file ~./SpaceVim/autoload/SpaceVim/layers/lang/julia.vim . And disable the following command.

let g:latex_to_unicode_tab = 0


Vim for Julia was originally published in Coffee in a Klein Bottle on Medium, where people are continuing the conversation by highlighting and responding to this story.

Creating a Mathematics Blog with Jekyll

By: DSB

Re-posted from: https://medium.com/coffee-in-a-klein-bottle/creating-a-mathematics-blog-with-jekyll-78cdee0339f3?source=rss-8bd6ec95ab58------2

A Tutorial on how to setup a blog using GitHub, Jekyll and MathJax

There are several ways to create your personal blog on the web, but not as many alternatives when you want to focus on technical subjects and want to write mathematical equations. In this brief article, I explain how you can use GitHub with Jekyll to create your personal blog with MathJax, so you can write beautiful equations using Latex notation. Note that this tutorial is written for Ubuntu, but can easily be adapted for a different OS.

What is Jekyll and MathJax

In this tutorial, I will assume that you now what GitHub is, and that you can use it to host your personal website using GitHub Page. If you don’t, then take a look at this Tutorial. With that being said, let’s explain what Jekyll and MathJax are…

Jekyll is a static site generator. It takes text written in your favorite markup language and uses layouts to create a static website. You can tweak the site’s look and feel, URLs, the data displayed on the page, and more.

— Jekyll Official Website

In other words, Jekyll can be thought as an application written in Ruby, that easily creates a web site that is easily manageable and allows one to write using markup language, which is quite handy. Also, Jekyll is supported by Github and has some pre-built styles, so your blog is beautiful looking right out of the box.

MathJax is a JavaScript display engine for mathematics that works in all browsers.

— MathJax Official Website

In other words, MathJax is a service that renders the mathematical equation, so it looks neat in your browser. You can then write in your blog

$$ x = y ^2 $$

And in your browser, MathJax will render it as

Mathematical equation rendered on the browser with MathJax. Note that Medium doesn’t use MathJax, so I actually just copy and pasted an image of how the rendered text would look like.

The idea is to create a GitHub page, then to use Jekyll to style your blog and allow the use of markdown, together with MathJax to properly render the equations.

Setting up your Blog with Jekyll

There are several ways to set up Jekyll with your GitHub page. One can install themes using Ruby Gems, or use one of the themes provided by GitHub. But to enable MathJax, one has to manually tweak the html code for the theme. So instead, we will fork an specific theme, and modify it.

First, we need to install Jekyll and Bundle (which helps manage Ruby Gems). If you are using Ubuntu 20.04, you might already have Ruby installed. Otherwise, you might need to install it. The command below will install Ruby, and then install Jekyll and Bundle.

sudo apt install ruby-dev
gem install jekyll
gem install bundler

With these few lines of code, you can already set up your blog with Jekyll, just run the following

jekyll new my-website

This will create a folder “my-website” with all website code inside it. If you go inside the directory and run one command, you can start a local server with your blog running.

cd ./my-website
bundle exec jekyll serve

Now go into your browser and go to “localhost:4000” and you can see your blog.

Example of Website running using Jekyll

Your blog is already functional! You can just copy all the files inside the “./my-website” folder, and move them to your git repository, and then push them to GitHub. After a few seconds, your blog will be up on the web. Below I show an example:

mv ./my-website/* ./coffee-in-a-klein-bottle.github.io
cd ./coffee-in-a-klein-bottle.github.io
git add -A
git commit -m “Initiated my Jekyll blog”
git push -u origin master

Quick guide to using Jekyll

Now, I’ve explained how to set up Jekyll, but not exactly how to use it. There is a ton of tutorials out there, but, actually, you don’t need to know much to start using Jekyll effectively. Once your blog is created, to personalize it and start writing posts is straightforward. If you go inside the folder containing your new blog, this is what it might look like:

Screenshot of Terminal showing inside the “my-website” folder created by using Jekyll

The “.markdown” files are just, as the name says, markdown files containing information regarding each specific webpage. You can, for example, open the “about.markdown” file, and start modifying it with your personal information. After that, just run

bundle exec jekyll serve

from inside the “my-website” folder, and Jekyll will update your website files, which are inside the “_site/” folder. Note that you don’t do anything with the “_site/” folder, the files in there are taken care of by Jekyll under the hood.

Screenshot of “_config.yml” file

The “_config.yml” file will contain configuration properties used by Jekyll, such as the theme being used, the plugins that are necessary to be installed, the title of your website, and so on. We will be using a preset theme, so you won’t need to worry much about this file for now.

The “Gemfile” and “Gemfile.lock” contain information for Ruby, such as the version of Jekyll and so on. You don’t need to worry about them.

Finally, the “_posts/” folder is where you will store your posts files. This posts are markdown, so there is not much here to be said. Just follow the same structure as the example post provided, and you will be fine.

Updating the them to enable MathJax

Unfortunately, most Jekyll themes don’t come with MathJax enabled right out of the box, so we have to do this manually, and this require that we modify the files of the theme. When hosting your blog on GitHub, some themes are natively supported (such as the minima theme), but the theme files cannot be modified this way. So we will need to bring all the theme files to the repository and modify them there.

First, let’s go to the “minima” theme GitHub repository, and then download the repository to your computer. Delete all the files in your GitHub repository containing the website, and then copy all the files from the “minima” folder to your repository. Then, run the Jekyll command to see if your site is still working. Below are the commands showing an example of how to do this:

cd ~/
git clone https://github.com/jekyll/minima.git
cd ./coffee-in-a-klein-bottle.github.io
rm ./*
mv ~/minima/* ./
bundle exec jekyll serve

Go to the “localhost:4000” and see if your site is working properly. If it is, then stop the server, and let’s modify the theme to enable MathJax.

Open the “_layout/default.html” file and add the CDN for MathJax. In other words, open “_layout/default.html” and paste this two lines in the end of the file:

<script src=”https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id=”MathJax-script” async src=”https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

The image below shows what your file should look like

Screenshot of the “default.html” file

Writing Mathematical Equations

You are done! The only thing left to do is to actually start writing your blog posts. So let’s do an example. Open one of the posts files and write

$$ x = y^2 $$

Then, run the Jekyll to visualize your website on the localhost.

This is an example of how your post should look:

Example of using MathJax with Jekyll

Finally, just push all the file to your repository, and your personal mathematics blog will be on the web open and running.


Creating a Mathematics Blog with Jekyll was originally published in Coffee in a Klein Bottle on Medium, where people are continuing the conversation by highlighting and responding to this story.

Installing Julia on Ubuntu

By: DSB

Re-posted from: https://medium.com/coffee-in-a-klein-bottle/install-julia-1-5-on-ubuntu-bb8be4b2571d?source=rss-8bd6ec95ab58------2

A quick tutorial on how to install Julia on Ubuntu and add the kernel to Jupyter

Installing Julia on Ubuntu is very straightforward. As anything on Linux, there are several ways to do the installation.

1. Using Apt-Get

This is the first way, and it is the easiest. Just open the terminal and run

sudo apt-get install julia

The problem with this method is that you don’t get the latest stable version for Julia. In the time I’m writing this article, the Ubuntu repository contains the version 1.0.4 for Julia, while the current stable version is 1.5.2.

So this is not the method I recommend!

2. From the Website (recommended)

First, go to the Julia website download page. There, several ways to run Julia are shown. Go to the “Current stable release” table, and click on the link shown in the image below.

Donwload Julia by clicking on the “64-bit” inside the red square

Then, the Julia Language will be donwloaded (most likely to your Download directory). Next, go on your terminal and unzip the downloaded file.

tar -xvzf julia-1.5.2-linux-x86_64.tar.gz

You now have a folder with all the Julia files. No installation is required. Now, we move this folder to “/opt” (this is not strictly necessary, you can use any other location in your machine).

sudo mv julia-1.5.2/ /opt/

Finally, create a symbolic link to the Julia binary file. This will allow you to run the command “julia” in your terminal and start the Julia REPL.

sudo ln -s /opt/julia-1.5.2/bin/julia /usr/local/bin/julia

Done! Now Julia is already installed and working in your machine. Let’s now add it to Jupyter.

3. Adding Julia kernel to Jupyter

We assume that Jupyter is already installed in your machine. To add the Julia Kernel to it is quite easy. Just open your terminal and run “julia”. This will open the REPL, as shown in the image below.

Inside the REPL, we then run the following commands:

using Pkg
Pkg.add(“IJulia”)

The “Pkg” package is used in Julia to install different packages on Julia. By installing “IJulia”, it automatically adds the Julia kernel to Jupyter.

And that’s it. Julia should be working with your Jupyter Notebook and/or JupyterLab.


Installing Julia on Ubuntu was originally published in Coffee in a Klein Bottle on Medium, where people are continuing the conversation by highlighting and responding to this story.