Hexo doesn’t support latex out of box, but some theme do. Since I use next theme which support it, I don’t need additionally use other plugins to achieve the goal. But I still have to do some config to make it work better.
Steps
Enable the mathjax in next-theme config
1 2 3 4 5 6 7 8 9 10
//themes/next/_config.yml
math: # Default (false) will load mathjax / katex script on demand. # That is it only render those page which has `mathjax: true` in front-matter. # If you set it to true, it will load mathjax / katex script EVERY PAGE. every_page:false mathjax: enable:true tags:ams
add the meta in the post file
if you didn’t set the every_page to true, then you have to set the metadata info mathjax: true in the disered post
1 2 3 4
--- title: the disered post mathjax: true ---
Sample
Inline Formula
1
We all know that $1+1=2$
We all know that $1+1=2$
Display Formula
1 2 3 4
$$\begin{equation} \label{eq1} e=mc^2 \end{equation}$$ The famous matter-energy equation $\eqref{eq1}$ proposed by Einstein...
$$\begin{equation} \label{eq1} e=mc^2 \end{equation}$$ The famous matter-energy equation $\eqref{eq1}$ proposed by Einstein…
Some issues
The hexo default markdown render engine ‘marked’ will cause some issues when render the Multi-line Equations. In latex,\\ will inset a new line in Multi-line Equations. But in marked engine, the double backslash \\ will be escaped to \, which cause the render failure.
1 2 3 4 5 6 7
$$\begin{equation} \label{eq2} \begin{aligned} a &= b + c \\ &= d + e + f + g \\ &= h + i \end{aligned} \end{equation}$$
$$\begin{equation} \label{eq2} \begin{aligned} a &= b + c \ &= d + e + f + g \ &= h + i \end{aligned} \end{equation}$$
as you see, the Multi-line Equations $\eqref{eq2}$ didn’t display correctly Fortunately, you have at least two options to fix it.
Simpler way: use different linebreak symbol
maually escape the backslash
A simple way to fix it is that use \\\\ to generate the escaped double backslash, and pass \\ to next-theme‘s mathjax engine correctly.
1 2 3 4 5 6 7
$$\begin{equation} \label{eqcorrect} \begin{aligned} a &= b + c \\\\ &= d + e + f + g \\\\ &= h + i \end{aligned} \end{equation}$$
$$\begin{equation} \label{eqcorrect} \begin{aligned} a &= b + c \\ &= d + e + f + g \\ &= h + i \end{aligned} \end{equation}$$
tips: but due to difference between other render engines, \\\\ may render as two linebreaks on it, such as marked engine inside the Obsidian.
use \newline
\newline works the same way as \\ in latex syntax, and since marked will not escape \newline, it’s more compatible between different markdown render engine.
1 2 3 4 5 6 7
$$\begin{equation} \label{eqcorrect2} \begin{aligned} a &= b + c \newline &= d + e + f + g \\\\ &= h + i \end{aligned} \end{equation}$$
$$\begin{equation} \label{eqcorrect2} \begin{aligned} a &= b + c \newline &= d + e + f + g \\ &= h + i \end{aligned} \end{equation}$$
Maybe harder way: Use other render engine
Alternately, you could use another markdown render engine. like pandoc which is recommended by the next-theme officially.
1 2
$ npm un hexo-renderer-marked $ npm i hexo-renderer-pandoc
pros
It could render the math Formula correctly, no more ugly \\\\ thing, and the md content is basically standard, which makes it easier to edit or render with other editor or engine, like Emacs.
cons
cons_1. extra blank line
If you are familiar with the default marked flavor markdown, you could possibly need some modification with pandoc config. Pandoc won’t create newline when it comes with a single enter, you have to use the standard way: double space at the end of line you could fix it with config in the hexo config.
1 2 3
pandoc: extensions: -"+hard_line_breaks"
However, it will bring another issue, this will cause pandoc insert extra <br> tags around the <span> tag which the math formula are wrapped in, blank around the formula will make it looks not so good. at least two way to fix it as I know:
But you could solve it with by adding <br> tags or blanks line around the display formula.
modify the package source code to use a github flavor markdown
Another thing is that pandoc doesn’t support embed sources like pictures in local relative path out of box, maybe you could config it – I didn’t try that.
Appendix: More sample
Multiple Aligned Equations
1 2 3 4 5 6
$$\begin{align} a &= b + c \label{eq4} \newline x &= yz \label{eq5} \newline l &= m - n \label{eq6} \end{align}$$ There are three aligned equations: equation $\eqref{eq4}$, equation $\eqref{eq5}$ and equation $\eqref{eq6}$.
$$\begin{align} a &= b + c \label{eq4} \newline x &= yz \label{eq5} \newline l &= m - n \label{eq6} \end{align}$$ There are three aligned equations: equation $\eqref{eq4}$, equation $\eqref{eq5}$ and equation $\eqref{eq6}$.
Use \tag to Tag Equations
1 2
$$x+1\over\sqrt{1-x^2} \tag{i}\label{eq_tag}$$ Equation $\eqref{eq_tag}$ use `\tag{}` instead of automatic numbering.
$$x+1\over\sqrt{1-x^2} \tag{i}\label{eq_tag}$$ Equation $\eqref{eq_tag}$ use \tag{} instead of automatic numbering.
try <p>
When you use some Tex commands that can’t be recognized by markdown render engine, use wrap it with <p>, so that markdown render engine won’t process it, instead passing the raw content to the math equation render engine like MathJax, the math render engine usually can handle it.
Getting bored for using the same terminal all the time, time to move on to another one. This time will be Alacritty. The first trouble is that Alacritty won’t treat Option as Meta, it just don’t provide you this option. check the issues on its github repository, you’ll find something like the following:
It almost cover everything. Things semm perfect until I found Alt+i/u/e/n won’t work.
Issue
on MacOS in English input method option+n will prompt a “˜” symbol, and waiting for the next keystroke to see if it can input a char that can be modified by “˜”, which will break the keymap proceeding and this keymap will never get chance to be execute:
1
# - { key: N, mods: Alt, chars: "\x1bn" }
Looking into the issues, didn’t find useful information, and it seems the author will do the “treat option as meta” later in the future. So, what’s now?
Solution
Karabiner came to my mind. Karabiner, a cross-platform keymap tool. Since the issue can’t be solved in Alacritty itself, I can only count on some tool outside of it. if I can manage to avoid option-n keystroke and map it to a middle keybinding, then the “˜” won’t shown, then map this keyBinding to the desired chars code in the Alacritty. fortunately Karabiner and Alacritty can do this for me.
flowchart TB;
A(Alt+n) x-.-x |option+n will prompt a symbol to break the proceeding| C
subgraph Karabiner
A --> |map| B[Command+n]
end
B --- B'
subgraph Alacritty
B'[Command+n] --> |map| C("\ x1bn")
end
Karabiner will map left_option+n to left_command+n, so you don’t have to literally press Command+n to trigger Meta+n, just do as the natural way pressing the Alt+n, and karabiner and alacritty will ensure the Meta+n trigger for you.
将快捷方式加入app分享菜单中 进入快捷方式app,长按对应快捷方式快片 → Details → Show in Share Sheet
Usage
有两种使用方法,在app中使用,主动点击快捷方式进行触发。
在app中使用
richUrl2md
在bilibili的app中,点击分享 → 更多 → richUrl2md 此时你的剪切板中就得到了一个[This is url title infomation](https://www.someurl.com)格式的链接,粘贴到你的markdown文档中。 tip: this will result in a expanded shorten url
Annoying alt key and meta behave on different OS and applications.
GUI emacs on Windows:
alt works as meta key, didn’t do much test on msys2 or something.
ArchLinux tty:
alt can be recognised as meta key in some applications(like emacs), in some others it can’t.
application
work as meta
tmux
works as meta and also work with a number like ‘M-1’
emacs
works as meta, also work with number.
vim
alt won’t work as meta, alt-h won’t trigger M-h. you have to use execute "set <M-h>=\eh", then map nnoremap <M-h> <C-w>h
besides, number related binding like execute "set <M-h>=\e1 won’t give you the M-1 binding, it’s just not work in vim.
MacOS
GUI emacs application: you use Command key as meta key, there is nothing to worry about. iterm2: you can set the way terminal treat alt in preference, and the following is what it acts like.
set as
work as meta
behaviour
normal
no
alt-specificKey will input a specific char, which could be used to do keybinding( even work with number related keybinding:
map ¡ <M-1>noremap <C-1> 1gt ) in vim. If you want to use number binding in vim this is the choice.
meta
no respon in terminal
/
esc (current)
yes
aligned with archlinux tty, works fine except number key binding in vim.
tui run emacs from Msys2-msys2 gui run emacs from D:\*\msys64\mingw64\bin\emacs-28.2.exe run emacs from Msys2-MinGW
1.6 install plugins
switch between emacs(cli) & emacs(gui) several times to run and install packages as many as possible when stuck on some init-file config like (scroll-bar-mode -1),you can just comment it. it’s OK to do so, because we want to install asmany package, and the final aim is to use pdf-tools & org-noter
2. config pdf-tool& org-noter
2.1 install pdf-tool
run pdf-tool-install from emacs(gui)
2.2 eval pdf-tool & org-noter lisp code
open init-org from D:*\emacs.d\lisp\init-org.el
eval key-binding & use-package related lisp code
eval (require 'org-noter_modifer) to allow use custom org-noter function
config linum-mode before open an pdf, you have to turn linum-mode off. This could be done by adding a pdf-view-mode-hook hook, or you’ll stuck when try open pdf file.
Writing your CV in markdown with your favourite text editor and convert it into PDF with a single pandoc command. All these could be done in a TUI environment, you could even finish it in a tty.
Pre
Writing CV may be annoying. Pdf format is usually prefered, but many one prefer writing in markdown format, you have to convert format after writing. If you use some online website tool then every time you have to open it, it hard to writing something on a web you have to switch between mouse and keyboard which is a disaster, and what’s worse it usually charges, or need VIP for some feature. If you use some software, you have to depend on its export ability to convert your file into specific format, and usually its export has limitation, hard to extend and not flexible enough. Of course, writing in markdown and convert it into pdf can be achieved by many ways. the most simple way is to write in some sofeware and use its feature to display browser, and the save it as a pdf using browser. or using some editor to export to pdf after writing. What if you want it in some way that you can do all the thing in a tty, without opening any browser or open some desktop sofeware? Well, you can use pandoc.
pandoc - Swiss-army knife of markup format conversion
it’s a free and open-sourced cli tool. it can convert files between many formats: markdown, html, latex, docx. besides convertion you can custom the output format. cli tool can be use with many other tool-chain which makes it could work very flexibly.
Environment
The following work is on a win7 pc, so I guess it will work on higher version windows as well. For mac and linux environment, you could even achive better results, because though this is done on win7, but the tool chain is from linux(throuh msys2).
Solution
Writing your CV in markdown with your favourite editor
flowchart TB;
subgraph c[combination]
direction TB;
md(markdown)
css
end
c -.-> |pandoc| html
html -.-> |wkhtmltopdf| pdf
c --> |using pandoc directly convert| pdf
Steps
1. on windows you have to config a linux-like environment, you could do it by installing Msys2.
1.2 update msys2 enter msys2 execute multiple times until the last status
1
pacman -Syu
2. install pandoc
msys2 don’t have this package, so just download the executeable release package from github repository. then upzip it, put pandoc.exe into msys2 bin folder mingw64/usr/bin.
3. [NOT my choice] Using pdflatex/xelatex(from texlive package) to convert
at first I saw this https://kieranhealy.org/vita.pdf, and like its simpel academic curriculum vitae style and color scheme. its source code counld be download here https://github.com/kjhealy/kjh-vita but be careful since it’s based on a latex solution, it’s more complicated than the following markdown way. according to its memo in kjh-vita.tex, it got some Requirments from his other repository, where is https://github.com/kjhealy/latex-custom-kjh. and I found it need some font when compiling it, which counld be solved by download or just use other font instead.
latex syntax is much more complex than markdown, though it has an elegant syntax and render it in a precise way, it’s also true to be less readable than markdown. note that if you are not familiar with latex, then this is not a good way to do. if the markdown file contains CJK character(like Chinese), the default pdflatex won’t satisfy you, you could usexelatex instead. this way you may entercount lots of file missing ERROR, you could solve it by download the corresponding file. but if you konw what your are doing it’s totally ok.
at first I tried use pandoc convert markdown to pdf directly through xelatex, and the Chinese character issue and highlight style issue should be taken care of, which is basically like the following:
1 2
pandoc -f markdown -o result.pdf --pdf-engine=xelatex -s -VCJKoptions=BoldFont="SimHei" -VCJKmainfont="SimSun" --highlight-style=zenburn -V colorlinks -H head.tex -t pdf resume.md (head.tex is an head file to add head to the pdf file)
but then I found I can’t typeset the content precisely, since latex compelte its typesetting in a single latex file. so if you want using a latex way, you have to writing it in latex at the very beginnig.
the following is the steps to convert .tex file into a .pdf file.
3.1 texlive installation and install its depenency
cd ~/Desktop git clone https://github.com/kjhealy/kjh-vita
3.3 patch kjh-vita template: copy the required file into kjh-vita folder
1 2 3 4 5
cd ~/Desktop git clone https://github.com/kjhealy/latex-custom-kjh cd latex-custom-kjh cp needs-memoir/* ~/Desktop/kjh-vita/ cp needs-org-mode/* ~/Desktop/kjh-vita/
3.4 patch kjh-vita template: download vc bundle download vc bundle from https://ctan.org/pkg/vc unzip it, and read the vc-manual, copy the vc binary into kjh-vita folder.
1 2 3
cd vc/git-windows run the `vc.bat` file and generate the `vc` cp vc ~/Desktop/kjh-vita/
3.5 patch kjh-vita template: download the missing font here are some fonts I found need to be download:
FontAwesome/Unit-Medium/Minion Pro/
3.6 tweak the source code after tried my best I installed some fonts, but still missing some, so I tewaked the source code, so the compilation could be done. actually after the modification the output pdf looks almost the same as original one.
As pandoc‘s tip, the convert should be done directly using latex endinge.
[WARNING] Unusual conversion: to convert a .tex file to PDF, you get better results by using pdflatex (or lualatex or xelatex) directly, try pdflatex kjh-vita.tex instead of pandoc kjh-vita.tex -o result.pdf.
so just use xelatex to do do the job.
1 2
cd ~/Desktop/kjh-vita xelatex kjh-vita.tex
then you’ll get a right formatted pdf file.
4. [Work] Using markdown & css to convert
fortunately I found a similar academic style CV it use jekyll to render a html, and print it with browser's print funtion. but we don’t have to do it that way, using its css file is enough for me. now We can use css file to convert markdown into html as a intermedia to achieved goal. Using pandoc default convert html to pdf will lose the css style even with -c/--css filename.css. However with wkhtmltopdf, we can use -c/--css filename.css to use css.
4.1 install wkhtmltopdf
1
pacman -S mingw-w64-x86_64-wkhtmltopdf-git
4.2 download the css file.
1 2
git clone https://github.com/elipapa/markdown-cv cd markdown-cv
as mentioned previous you can use a css file to make markdown file rendered into a prettier pdf file. What if you don’t have a desired css file? fortunately, mkhtmltopdf is powerful, you could use it turn html to pdf directly(which is the statnard way to use it).This make it more flexible to turn you markdown file into pdf.
the reason you can see markdown rendered in a pretty way in some website(like github markdown preview) or markdown editor(like typora) is that the they have render-engine/code done it for you. the results could be different in differnt engine(which always happen). the pandoc has its own engine as well, but the rendering results cound be so plain and boring which is not we want. so what we need now is a html rendered in your flavor, and then let wkhtmltopdf to convert it to pdf.
it’s easy to download the html from the web, normally you just right-click and save the html file. then use wkhtmltopdf to do the convert.
1
wkhtmltopdf rendered.html result.pdf
ok, normally it won’t look exactly the same with the original web, both rendered.html and result.pdf. but for me it’s ok, rendering issue is too complex and I don’t wanna dive into it. Besides you could do some tweaks throuh edit the html file and css file.
pdf-tools https://github.com/vedang/pdf-tools (PDF Tools is dead, long live PDF Tools. Development continues with this fork) https://github.com/politza/pdf-tools (An older/archived one) 不会产生一个可以保存使用的具体文件 对文件的annotaion会嵌入到pdf文件中。 可以实现对annotation的list展示/插入。在list中移动光标到notes,可以让pdf滚动到对应位置,一可以关闭同步滚动 C-c C-a l : list annotation (在pdfmode 窗口中按下) C-c C-f : pdf annot list follow enable/diable (在Annots mode窗口中按下) summary:是对于pdf文件的直接操作。