Blogger or Wordpress if you are looking for a simpler setup.
In this tutorial, I will assume that you have some familiarity with with git and with installing software.
conda ...
with pip ...
or whatever is appropriate for the purpose.begin..end
blocks) For rendering mathematical formulas in \( \LaTeX \), we can use either of the following two JavaScript libraries. git
, the Python distribution, mkdocs
and mkdocs-material
.If you are using conda
conda-forge
repository (conda config --add channels conda-forge
).conda install mkdocs
.conda install mkdocs-material
.<mathblog>
from now on. To the .gitignore
add the line site/
.git clone <repository-url>
) on your local machine.mkdocs new <mathblog>
. This generates all the required files for MkDocs.<mathblog>
directory (cd <mathblog>
), and run mkdocs serve &
. If you do not have any errors, go to http://127.0.0.1:8000/
in your web browser. You should see the home page of your (to be created) website. If you get the error pkg_resources.DistributionNotFound: The 'mkdocs-material-extensions>=1.0' distribution was not found and is required by the application
, then install MkDocs Material Extensions
using pip
(pip install mkdocs-material-extensions
) since there is not conda package for it yet (check!).docs/
and create an markdown document within the folder. This file should automatically show in the website.mkdocs.yml
, so I will not mention this explicitly.We need either MathJax or KaTeX to process \( \LaTeX \). As I mentioned earlier, we shall use MathJax since I have yet to figure out how to process begin..end
blocks in KaTeX. The Arithmatex pages do talk about using KaTeX, but these did not work for me.
First, we need to enable the Arithmatex extension.
markdown_extensions:
- pymdownx.arithmatex:
generic: true
Now we need to add relevant scripts.
mkdocs.yml
extra_javascript:
- https://polyfill.io/v3/polyfill.min.js?features=es6
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
mkdocs.yml
extra_javascript:
- js/arithmatex2katex.js
- https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js
- https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js
extra_css:
- css/katex.my.css
- https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css
docs/js/arithmatex2katex.js
(function () {
'use strict';
var katexMath = (function () {
var maths = document.querySelectorAll('.arithmatex'),
tex;
for (var i = 0; i < maths.length; i++) {
tex = maths[i].textContent || maths[i].innerText;
if (tex.startsWith('\\(') && tex.endsWith('\\)')) {
katex.render(tex.slice(2, -2), maths[i], {'displayMode': false});
} else if (tex.startsWith('\\[') && tex.endsWith('\\]')) {
katex.render(tex.slice(2, -2), maths[i], {'displayMode': true});
}
}
});
(function () {
var onReady = function onReady(fn) {
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", fn);
} else {
document.attachEvent("onreadystatechange", function () {
if (document.readyState === "interactive") {
fn();
}
});
}
};
onReady(function () {
if (typeof katex !== "undefined") {
katexMath();
}
});
})();
}());
docs/css/katex.my.css
.katex {
font-size: 1.1em !important; /* Smaller fonts for inline math */
}
.katex-display > .katex {
font-size: 1.21em !important; /* Larger fonts for display math */
}
.katex-html {
overflow-y: hidden;
}
Now write some math in your markdown files and test them out. They should render normally.
This package can only handle syntaxes in a particular format, namely $``…``$
(not two backticks but one) and ```math … ```
. There are specific advantages to this, but it means I cannot copy-paste code between my website and \( \LaTeX \) documents, which is not what I want.
Local installation
We do not need to install MathJax or KaTeX locally. Both are obtained directly from a CDN.
Todo
mermaid
. I have not been able to get this running. For an example of what it should look like, see here.plugins
in mkdocs.yml
. Further description of each plugin can be found in the respective pages.*.html
files generated by mkdocs build
in a post-processing step, stripping all unnecessary characters to reduce the payload served to the client.mkdocs.yml
. For options, see github.com/lukasgeiter/mkdocs-awesome-pages-plugin/ and lukasgeiter/mkdocs-awesome-pages-plugin.Now that we are happy with our creation, it is time for us to show our work to the world. Before we go ahead, we commit to our changes using git commit -a
and push the commit to the origin
using git push
.
Now run mkdocs gh-deploy
to create a separate branch called gh-pages
for our website. Finally, go to the GitHub Pages settings of your repository and choose the source as gh-pages branch
. Now our website is live! Check this by visiting the link to your website as shown in your GitHub Pages settings.
The Python Markdown extensions are a set of extrememly useful extensions. For more extensions, see the Extensions pages of SquidFunk's website for Material for MkDocs.
Note
In features
under theme
, do not use * instant
, because it stops math from rendering without reloading, and * tabs
, because it just looks bad.
Tip
For social
, the icons can be found here.
property
for your website.Set up for free
. Give an account name and go to the next page.Web
in the next pagegoogle_analytics:
- UA-XXXXXXXX-X
- auto
Disqus website
. Go to Disqus signup, and click on I want to install Disqus on my site
, and fill up the form. Now include your Disqus Website Name
in the project. extra:
disqus: the-website-shortname
The links throughout the recipe were immensely helpful for me to set up the website (and create this document). I highly recommend you visit these sources for a better understanding of the processes and to customize the blog according to your tastes.