Antkillerfarm Hacking V7.0

Github显示数学公式, Latex

2020-08-23

Github显示数学公式

这里主要用到了LaTeX和MathJax。

LaTeX是TeX的扩展包,用于书写数学公式。它的官网是:

http://www.latex-project.org/

MathJax

MathJax是一个JavaScript包,可以将LaTeX书写的数学公式转换成HTML。它的官网是:

https://www.mathjax.org/

源代码地址:

https://github.com/mathjax/MathJax

如果官网的网速不好的话,还可采用以下CDN地址:

http://cdn.bootcss.com/mathjax/2.4.0/MathJax.js

一般而言,从一个巨大的符号表中查询所需要的特定符号是一件令人沮丧的事情。在此向大家介绍一个LATEX手写符号识别系统:

http://detexify.kirelabs.org/classify.html

LaTeX和MathJax联合使用的方法参见:

http://www.cnblogs.com/linxd/p/4955530.html

Mathjax与LaTex公式简介

http://3iter.com/2015/10/14/Mathjax%E4%B8%8ELaTex%E5%85%AC%E5%BC%8F%E7%AE%80%E4%BB%8B/

Mathjax与LaTex公式简介

http://www.uinio.com/Math/LaTex/

通用LaTeX数学公式语法手册

如果在Vscode下编辑Markdown和Latex的话,可以使用Markdown All in One插件。

如果是其他编辑器的话,推荐使用:

https://casual-effects.com/markdeep/

MathJax v3

MathJax v3和v2的接口发生了较大的变化,升级方法参见以下文件的git log。

https://github.com/antkillerfarm/antkillerfarm.github.com/blob/master/_layouts/default.html

参考:

https://chrisyeh96.github.io/2020/03/29/mathjax3.html

Painful Upgrade to MathJax 3

KaTeX

KaTeX是另一个LaTeX渲染引擎,速度比MathJax快,但是功能有限。

https://katex.org/docs/supported.html

这是KaTeX支持的操作的列表,也是一个很好的LaTeX手册。

示例

\[\vec{p}(t)=\vec{o} + t\vec{d}\]

\[ (x-o_x)^2+(x-o_y)^2+(x-o_z)^2-R^2=0 \]

\[A\xrightarrow[\alpha]{\beta}B\] \[\text{vxRPNLayer}\left\{ \begin{array}{l} \begin{aligned} \text{softmax} & \left\{ \begin{aligned}\text{background scores} \\ \text{foreground scores}\end{aligned} \right. \end{aligned} \hfill \\ \left.\begin{aligned}\text{proposal} & \Rightarrow \color{red}{\text{axis_aligned_bbox_transform}}\\ \text{sort} \\ \text{nms} & \left\{ \begin{aligned} \Rightarrow & \color{red}{\text{detection_postprocess(hard nms)}} \\ \Rightarrow & \color{red}{\text{box_with_nms_limit(soft nms)}}\end{aligned} \right. \\ \text{retrieve}\end{aligned}\right\} \Rightarrow \color{red}{\text{generate_proposals}} \end{array} \right.\] \[\sum\limits_{k=1}^KG_t = \sum\nolimits_{k=1}^KG_t\] \[\angle APB=\angle BPC=\angle CPA=120^{\circ}\] \[A\xrightarrow{\enclose{circle}{j}+\enclose{circle}{i}k}B\]

注意

绝对值符号虽然键盘上有这个键,但由于和Markdown的表格功能有冲突,需要采用\mid、\vert、\lvert、\rvert替代之。

微分符号\(\rm{d}\)要用正体:\mathrm{d}或\rm{d}。

偏微分符号\(\partial\):\partial

空格:<space>,表示键盘上的空格键。

维基百科中出现的公式,可以在编辑界面中获得TeX代码。

\mathop

\[\mathop{\arg\min}_{\theta,\theta_\Delta}\] \[{\arg\min}_{\theta,\theta_\Delta}\] \[\arg\min_{\theta,\theta_\Delta}\]

Mermaid

和MathJax类似,mermaid也是一个JS渲染引擎,可用于绘制各种图表。

官网:

https://mermaid-js.github.io/mermaid/

参考:

https://www.cnblogs.com/wuyida/p/6301240.html

markdown绘图插件–mermaid简介

https://zhuanlan.zhihu.com/p/355997933

Mermaid从入门到入土——Markdown进阶语法

示例:

graph TD A([Graph Construction]) --> B([Graph Verification]) B --> C([Graph Execution]) C --> |reference changes| B C --> D([Graph Deconstruction]) E[[Input Data]] -.-> C C -.-> F[[Output Data]]

Latex

CTAN

CTAN是tex包的一个集中资源站,类似于perl的CPAN。

官网:

https://ctan.org/

Tex/Latex的历史非常悠久,多数基本包都诞生于90年代中期之前,此后的十几年进入了一个沉闷期,发展很缓慢,有些包也年久失修了。最近这些年,随着科研人群的增加,一些明星包尤其是Tikz/Beamer的更新逐渐变得活跃。当然也少不了github的功劳,其他代码托管的网站太难用了,包括十年前的标杆——sourceforge。

tlmgr

tlmgr是texlive提供的包管理器。

tlmgr install <package>

arara

arara是一个tex方面的自动化工具。

传统的latex,流水线比较长。一般有.tex->.dvi->.pdf的过程。pdflatex虽然将这几步统一了,但是如果要输出.gif或者.svg的话,仍然需要添加后续步骤。

使用arara就可以一步到位了。

使用arara之前需要安装JRE。

官网:

https://islandoftex.gitlab.io/arara/

TikZ

TikZ是PGF(portable graphics format)提供的用户层API,主要用于绘图。TikZ ist kein Zeichenprogram(TikZ is not a drawing program)。

官网:

https://pgf-tikz.github.io/

代码:

https://github.com/pgf-tikz/pgf

官方文档:

https://pgf-tikz.github.io/pgf/pgfmanual.pdf

安装:

sudo apt install qtikz texlive-fonts-recommended texlive-xetex texlive-lang-chinese

此外,ubuntu上还有一个叫做texdoctk的程序,可以查看各种tex包的用户手册。

在线编辑:

https://www.sharelatex.com/

代码示例:

https://github.com/antkillerfarm/antkillerfarm_crazy/tree/master/helloworld/tikz

由于qtikz对于某些包支持的不好,我也不知道该怎样配置,因此采用了原始的命令行方式:

pdflatex xxx.tex

evince xxx.pdf

有的时候,会报没有.aux的错误,但实际上该文件是存在的,这时只需要再运行一遍pdflatex即可。

tikz的衍生包也不少,比如:

tikz-network:绘制网络图。

tikz-cd:绘制通用图表,接口更友好。

参考:

http://www.hahack.com/tools/pgftikz-resources/

PGF/TikZ资源汇总

http://www.texample.net/tikz/examples/

各种tikz示例的网站

https://github.com/xiaohanyu/awesome-tikz

一个Tikz资源集合贴

https://en.wikibooks.org/wiki/LaTeX/PGF/TikZ

TikZ入门教程

http://www.fuzihao.org/blog/2015/08/11/TikZ%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/

另一个TikZ入门教程

http://www.cnblogs.com/wangl393/

一个TikZ的blog

https://sandrocirulli.net/how-to-plot-functions-with-latex/

安装pgfplots

http://www.latexstudio.net/archives/category/tex-graphics/tikz-example

一个tikz的论坛

https://mp.weixin.qq.com/s/cetQ_Ddzc9Tov3x_w-Z72g

快速入门使用tikz绘制深度学习网络图

https://www.cnblogs.com/qizhou/p/13040159.html

TIKZ——LaTeX基本绘图

https://blog.csdn.net/qq_41437512/article/details/109189067

TikZ绘图实例——LSTM元胞结构图

https://www.cnblogs.com/ourweiguan/p/9953460.html

LaTeX:图形的填充(生成阴影图形)

Tikz+Gnuplot

sudo apt install gnuplot

示例:

https://github.com/antkillerfarm/antkillerfarm_crazy/tree/master/helloworld/tikz/gnuplot

animation

目前的动画主要有.gif.svg两种格式。

gif:

首先使用tikz生成所有的静态帧,然后用convert将之整合到一个gif文件中。arara中的animate规则采用了该方式。

convert -density 300 -delay 24 -loop 0 -alpha remove multipage.pdf animated.gif

示例:

https://github.com/antkillerfarm/antkillerfarm_crazy/tree/master/helloworld/tikz/animations/tikz_gif.tex

svg:

首先生成dvi文件,然后使用dvisvgm将dvi文件变为svg文件。arara提供有dvisvgm规则。这个方案使用tikz的animations库。

svg文件的动态效果只有在浏览器中才可观看。

pdflatex -output-format=dvi tikz-animation

dvisvgm --zoom=-1 --exact --font-format=woff tikz-animation.dvi

示例:

https://github.com/antkillerfarm/antkillerfarm_crazy/tree/master/helloworld/tikz/animations/tikz-animation.tex

此外,还有工具dvipng:

https://www.tug.org/texinfohtml/dvipng.html

中文支持

Latex的中文支持方案很多,早期有CCT、天元、CJK等,后来又有了Ctex套装。目前主流的是texlive+xelatex+xeCJK。

示例:

https://github.com/antkillerfarm/antkillerfarm_crazy/blob/master/helloworld/tikz/mindmap/mindmap_2.tex

xelatex xxx.tex

原始的Tex/Latex虽然比较稳定,但一者功能有限,二者使用步骤比较繁琐,因此才有paflatex/xelatex之类的一站式方案。

pdf2svg

安装:

sudo apt install pdf2svg

\documentclass[convert=pdf2svg, multi=false]{standalone}

使用细节

tikz包含一个叫做tikzmath的库,可以定义变量,用于后续使用。

latex有一个ifthen的库,可以执行分支语句。

gridslides

gridslides是一个用于制作slide的tex包。

官网:

https://github.com/minad/gridslides

安装依赖:

sudo apt install biber texlive-latex-extra texlive-fonts-extra texlive-extra-utils

Mathpix Snip

Mathpix Snip可以用来将图片变成Latex公式。目前已经收费。。。

官网:

https://mathpix.com/

安装:

sudo snap install mathpix-snipping-tool

快捷键:

Ctrl+Alt+M

参考:

https://mp.weixin.qq.com/s/fY936R9trn0RcTICE8EAAA

免费数学神器Mathpix发布移动版,一起来写更快的公式

Mathpix原理

论文:

《What You Get Is What You See:A Visual Markup Decompiler》

代码:

https://github.com/harvardnlp/im2markup/

官方实现(torch版本)

https://github.com/ritheshkumar95/im2latex-tensorflow

tensorflow版本

https://github.com/yixuanzhou/image2latex

上个版本的GUI封装

https://github.com/ssampang/im2latex

另一个TF实现

https://github.com/guillaumegenthial/im2latex

另一个TF实现

https://github.com/kingyiusuen/image-to-latex

还是一个开源替代品

Beamer

示例:

https://github.com/antkillerfarm/antkillerfarm_crazy/tree/master/helloworld/beamer

参考:

https://hartwork.org/beamer-theme-matrix/

Beamer Theme Matrix

https://deic-web.uab.cat/~iblanes/beamer_gallery/

Beamer theme gallery

https://zhuanlan.zhihu.com/p/142023097

Beamer入门

https://zhuanlan.zhihu.com/p/132750772

Beamer——基于LaTex的Slides制作

https://zhuanlan.zhihu.com/p/99801808

用beamer制作精美的演示文稿

mathcha

mathcha是一个可视化的Latex编辑器,和其他同类产品相比,它主要聚焦公式和图表功能,其中后者基于tikz。

官网:

https://www.mathcha.io/

安装:

sudo snap install math-notebook

Fork me on GitHub