Skip to content

Commit 7b647a5

Browse files
committed
fixed missing about
1 parent 0476aa1 commit 7b647a5

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
I"l{"source"=>"/media/user/Storage-Fast/Research/code/github-website/src", "destination"=>"/media/user/Storage-Fast/Research/code/github-website/src/_site", "collections_dir"=>"collections", "cache_dir"=>".jekyll-cache", "plugins_dir"=>"_plugins", "layouts_dir"=>"_layouts", "data_dir"=>"_data", "includes_dir"=>"_includes", "collections"=>{"posts"=>{"output"=>true, "permalink"=>"/:categories/:year/:month/:day/:title:output_ext"}, "projects"=>{"output"=>true}, "blog"=>{"output"=>true}, "travel"=>{"output"=>true}}, "safe"=>false, "include"=>[".htaccess"], "exclude"=>[".sass-cache", ".jekyll-cache", "gemfiles", "Gemfile", "Gemfile.lock", "node_modules", "vendor/bundle/", "vendor/cache/", "vendor/gems/", "vendor/ruby/"], "keep_files"=>[".git", ".svn"], "encoding"=>"utf-8", "markdown_ext"=>"markdown,mkdown,mkdn,mkd,md", "strict_front_matter"=>false, "show_drafts"=>nil, "limit_posts"=>0, "future"=>false, "unpublished"=>false, "whitelist"=>[], "plugins"=>["jekyll-feed", "jekyll-seo-tag", "jekyll-paginate"], "markdown"=>"kramdown", "highlighter"=>"rouge", "lsi"=>false, "excerpt_separator"=>"\n\n", "incremental"=>false, "detach"=>false, "port"=>"4000", "host"=>"127.0.0.1", "baseurl"=>nil, "show_dir_listing"=>false, "permalink"=>"date", "paginate_path"=>"/page:num/", "timezone"=>nil, "quiet"=>false, "verbose"=>false, "defaults"=>[], "liquid"=>{"error_mode"=>"warn", "strict_filters"=>false, "strict_variables"=>false}, "kramdown"=>{"auto_ids"=>true, "toc_levels"=>[1, 2, 3, 4, 5, 6], "entity_output"=>"as_char", "smart_quotes"=>"lsquo,rsquo,ldquo,rdquo", "input"=>"GFM", "hard_wrap"=>false, "guess_lang"=>true, "footnote_nr"=>1, "show_warnings"=>false}, "title"=>"RCmags", "author"=>"Mags", "email"=>"memoryofatrufestival@gmail.com", "description"=>"Projects and other things", "paginate"=>6, "github_username"=>"RCmags", "youtube_username"=>"XXXmags", "rcgroups_username_id"=>"189488", "google_analytics"=>true, "minima"=>{"date_format"=>"%-d %b, %Y"}, "header_pages"=>["home.html", "about.html", "travel.html", "blog.html", "projects.html", "search.html"], "livereload_port"=>35729, "serving"=>true, "watch"=>true, "url"=>"http://localhost:4000"}:ET
1+
I"j{"source"=>"/media/user/Storage-Fast/Research/code/github-website/src", "destination"=>"/media/user/Storage-Fast/Research/code/github-website/src/_site", "collections_dir"=>"collections", "cache_dir"=>".jekyll-cache", "plugins_dir"=>"_plugins", "layouts_dir"=>"_layouts", "data_dir"=>"_data", "includes_dir"=>"_includes", "collections"=>{"posts"=>{"output"=>true, "permalink"=>"/:categories/:year/:month/:day/:title:output_ext"}, "projects"=>{"output"=>true}, "blog"=>{"output"=>true}, "travel"=>{"output"=>true}}, "safe"=>false, "include"=>[".htaccess"], "exclude"=>[".sass-cache", ".jekyll-cache", "gemfiles", "Gemfile", "Gemfile.lock", "node_modules", "vendor/bundle/", "vendor/cache/", "vendor/gems/", "vendor/ruby/"], "keep_files"=>[".git", ".svn"], "encoding"=>"utf-8", "markdown_ext"=>"markdown,mkdown,mkdn,mkd,md", "strict_front_matter"=>false, "show_drafts"=>nil, "limit_posts"=>0, "future"=>false, "unpublished"=>false, "whitelist"=>[], "plugins"=>["jekyll-feed", "jekyll-seo-tag", "jekyll-paginate"], "markdown"=>"kramdown", "highlighter"=>"rouge", "lsi"=>false, "excerpt_separator"=>"\n\n", "incremental"=>false, "detach"=>false, "port"=>"4000", "host"=>"127.0.0.1", "baseurl"=>nil, "show_dir_listing"=>false, "permalink"=>"date", "paginate_path"=>"/page:num/", "timezone"=>nil, "quiet"=>false, "verbose"=>false, "defaults"=>[], "liquid"=>{"error_mode"=>"warn", "strict_filters"=>false, "strict_variables"=>false}, "kramdown"=>{"auto_ids"=>true, "toc_levels"=>[1, 2, 3, 4, 5, 6], "entity_output"=>"as_char", "smart_quotes"=>"lsquo,rsquo,ldquo,rdquo", "input"=>"GFM", "hard_wrap"=>false, "guess_lang"=>true, "footnote_nr"=>1, "show_warnings"=>false}, "title"=>"RCmags", "author"=>"Mags", "email"=>"memoryofatrufestival@gmail.com", "description"=>"Projects and other things", "paginate"=>6, "github_username"=>"RCmags", "youtube_username"=>"XXXmags", "rcgroups_username_id"=>"189488", "google_analytics"=>true, "minima"=>{"date_format"=>"%-d %b, %Y"}, "header_pages"=>["home.html", "about.md", "travel.html", "blog.html", "projects.html", "search.html"], "livereload_port"=>35729, "serving"=>true, "watch"=>true, "url"=>"http://localhost:4000"}:ET

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ plugins:
4343
# Order menu
4444
header_pages:
4545
- home.html
46-
- about.html
46+
- about.md
4747
- travel.html
4848
- blog.html
4949
- projects.html
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
layout: post
3+
title: "Adding Latex to Jekyll for pretty equations"
4+
katex: true
5+
---
6+
7+
In the process of setting up my blog, I recently encountered the challenge of rendering equations, specifically expressions from the [LaTeX](https://www.latex-project.org/) markup language, which is designed for writing mathematical notation. By default, [Jekyll](https://jekyllrb.com/) does not convert these expressions into visually appealing equations. However, we can work around this limitation by using additional tools to render them. One solution is to use a website that converts LaTeX code into an image, which can then be embedded into our site. This is precisely what I did for the review post of my [sensor fusion algorithm for an IMU](/projects/arduino-libraries/2020/03/14/imu_sensor_fusion.html). While this approach works well for infrequent use of LaTeX, it makes sense to implement a rendering add-on for more regular use.
8+
9+
**See: [latex2png](https://www.latex2png.com/)**
10+
11+
{% include image.html src="/img/imu-filter/equations1/equation1.png" %}
12+
<p align="center"><i>An image created from LaTeX code</i></p>
13+
14+
After a few internet searches, I found a blog post detailing how to embed a JavaScript library called [KaTeX](https://github.com/KaTeX/KaTeX). This library allows you to take LaTeX code written in a Markdown file and render it as beautiful equations. According to the blog post, all that was needed was to add a few lines to include some JavaScript files and a CSS file in the **<head>** element of the **default.html** page used by Jekyll. Here's the required code:
15+
16+
**See: [Adding LaTeX to your Jekyll Site](https://ionathan.ch/2021/05/19/latex-in-jekyll.html)** by Jonathan Chan.
17+
18+
{% highlight javascript %}
19+
<!-- CSS -->
20+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css"/>
21+
22+
<!-- JavaScript -->
23+
<script defer src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js"></script>
24+
<script defer src="https://cdn.jsdelivr.net/npm/katex@latest/dist/contrib/auto-render.min.js"
25+
onload="renderMathInElement(document.body,{
26+
delimiters: [
27+
{ left: '$$', right: '$$', display: true },
28+
{ left: '$', right: '$', display: false },
29+
{ left: '\\[', right: '\\]', display: true },
30+
{ left: '\\(', right: '\\)', display: false }
31+
]});">
32+
</script>
33+
{% endhighlight %}
34+
35+
<br>
36+
**Note:** Jekyll can highlight code syntax through the `pygments` plugin by wrapping code snippets between the `{ % highlight <language> % } { % endhighlight % }` tags. See: [Add syntax highlighting to gh-pages](https://stackoverflow.com/questions/6615415/add-syntax-highlighting-to-gh-pages).
37+
38+
This process was straightforward, and much to my surprise, it worked flawlessly. My only concern with this approach is the reliance on external JavaScript files. If I wanted to work on the website offline or found myself without an internet connection, I wouldn't be able to render the LaTeX. To mitigate this issue, I decided to save the KaTeX files locally on the Jekyll server. Initially, I attempted to copy the files from the internet into any directory within the Jekyll project, but this didn’t work correctly—the LaTeX did not render as expected. After another search, I discovered a Stack Overflow post stating that KaTeX requires a specific directory structure to function properly. According to the termianal output of the Jekyll server, I was also missing the _fonts_ folder, so I had to download the KaTex repository and copy the folder into my page's directory.
39+
40+
**See: [Loading KaTeX locally](https://stackoverflow.com/questions/60905163/why-katex-is-not-loaded-locally)**. The required directory structure is as follows:
41+
42+
```
43+
/katex/katex.min.css
44+
/katex/katex.min.js
45+
/katex/contrib/auto-render.min.js
46+
/katex/fonts
47+
```
48+
49+
<br>
50+
Once I placed _all_ the KaTeX files in this specific structure, the LaTeX began to render correctly. According to the code, you can use different tags to adjust the CSS style of the equations. When the display is set to **false**, the equation will be centered on the page. Here’s an example using the `\\[ \\]` tags:
51+
52+
`\\[ I_e = \int_{0}^t{(K_{p}e(t) - K_{c}{I_e})dt} \\]`
53+
54+
And here’s the same example using the `\\( \\)` tags: `\\( I_e = \int_{0}^t{(K_{p}e(t) - K_{c}{I_e})dt} \\)`
55+
56+
You can also create more complex equations by simply modifying the underlying LaTeX code. Check out the **[LaTeX Cheatsheet](https://quickref.me/latex)** for an overview of different LaTeX expressions:
57+
58+
```
59+
\\[ f\relax(x) = \int_{-\infty}^\infty
60+
f\hat\xi\,e^{2 \pi i \xi x}
61+
\,d\xi
62+
\\]
63+
```
64+
With just a few changes to the `<head>` tag of my Jekyll site, I was able to render elegant equations quickly. This solution is both simple and effective, and I want to commend the developers who made this system possible. Well done!

0 commit comments

Comments
 (0)