Debdeep Bhattacharya

View My GitHub Profile

Writing with markdown and TeX

5 Apr 2025

\[\newcommand{\xx}{\mathbf{x}} \newcommand{\R}{\mathbb{R}} \newcommand{\ww}{\boldsymbol{\omega}}\] \[\begin{CD} A @<<< B @>>> C\\ @. @| @AAA\\ @. D @= E \end{CD}\]

New command \(\xx\) and \(\R\) and $\R$ and $\xx$ and so on and so forth and $\ww$ and $\lesssim$ $\textcolor{blue}{Hello}$ and $\boldsymbol{\omega}$

Inline math: \(x^2\) vs $x^2$

vs

\[\begin{align*} x^2 \end{align*}\]

vs

\begin{align} x^2 \end{align}

Tex and markdown conversion to html with pandoc

:setfiletype pandoc.tex
---
title: Readme
author: Author
header-includes: |
    \usepackage{amsmath, amssymb, amsthm, amsfonts, color, bm}

    \newcommand{\R}{\mathcal{R}}
    \newcommand{\ww}{\boldsymbol{\omega}}
    \newcommand{\xx}{\mathbf{x}}
---

Converting a tex file into html pandoc file.tex -o file.html uses unicode by default to render math symbols. We need to use mathjax for a nicer rendering. Other options are

--mathml, --webtex, --mathjax, --katex

and demos can be found in pandoc demos.

According to pandoc documentation One need to specify the url of the .js file that would be used to convert math into mathjax. By default pandoc uses some link form some content delivery network (CDN), which does not work on firefox at the first attempt. So we can specify the url like this:

pandoc math.text -s --mathjax=https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js -o   mathMathJax.html

There are other CDN locations on mathjax documentation from sites like

pandoc README.md -s --mathjax=https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js -o   README.html

LaTeX writing guide

We want our .md file to convert to pdf or tex without much hassle. While using mathjax, a few things to remember for a quick conversion.

Diagrams

My observation is that using a freehand drawing tool like inkscape takes less time and provides more flexibility for creating diagrams. Markdown-friendly tools like mermaid required additional set up and does not seem to support latex within diagram. Maybe once can use latex tikz diagrams within markdown, but the whole point was to move away from programmable diagrams. Still:

Install pandoc filter for mermaid from git using

npm install --global mermaid-filter

Use it with -F in pandoc

pandoc  -F mermaid-filter something.md -o something.html 

A sample block of code

```{.mermaid format=png scale=5 caption='Computational graph'}
%%{init: {'theme':'neutral'}}%%
  graph TD
    a --> b

```

produces a flowchart-like diagram.

Marp and usual markdown

Converting marp-focused .md file into html using pandoc is very glitchy. Few things that do not work so far

Github readme compatibility

The markdown files with header does not render in github webpages, even though both are mathjax.